More compatiblity

This commit is contained in:
Bingus_Violet 2024-01-18 18:05:00 -06:00
parent 83e901520c
commit d8f867745d

View file

@ -29,7 +29,7 @@ app.get("/convert", async (req, res) => {
'-i', filePath, '-i', filePath,
'-f', formats[format] || format, '-f', formats[format] || format,
'-movflags', 'frag_keyframe+empty_moov', '-movflags', 'frag_keyframe+empty_moov',
'-vcodec', 'copy' , '-vcodec', 'copy',
'-' '-'
], { ], {
stdio: [ stdio: [
@ -37,16 +37,16 @@ app.get("/convert", async (req, res) => {
], ],
}) })
ffmpegProcess.stderr.setEncoding('utf-8') // ffmpegProcess.stderr.setEncoding('utf-8')
ffmpegProcess.stderr.on('data', (data) => { // ffmpegProcess.stderr.on('data', (data) => {
console.log(data) // console.log(data)
}) // })
// These are debugging lines to watch FFMPEG output :3 // These are debugging lines to watch FFMPEG output :3
ffmpegProcess.stdio[1].pipe(res) ffmpegProcess.stdio[1].pipe(res)
.on('close', () => { .on('close', () => {
fs.rmSync(filePath) fs.rmSync(filePath)
}) })
} }
}) })
@ -62,26 +62,30 @@ app.get("/download", async (req, res) => {
res.write(downloadHTML.substring(0, downloadHTML.indexOf("{CONTENT}"))) res.write(downloadHTML.substring(0, downloadHTML.indexOf("{CONTENT}")))
var fileExtension = cp.spawnSync('yt-dlp', ['--get-filename', url]).stdout.toString()
fileExtension = fileExtension.substring(fileExtension.lastIndexOf('.'))
if (!["mp3"].includes(format)) { if (!["mp3"].includes(format)) {
var fileName = Math.round(Math.random() * 100_000_000_000_000).toString() + '.webm' var fileName = Math.round(Math.random() * 100_000_000_000_000).toString() + fileExtension
var filePath = path.join(__dirname, 'downloads', fileName) var filePath = path.join(__dirname, 'downloads', fileName).trim()
var ytdlpProcess = cp.spawn('yt-dlp', [ var ytdlpProcess = cp.spawn('yt-dlp', [
url, url,
'-o', filePath, '-o', filePath.substring(0, filePath.lastIndexOf('.')),
'--max-filesize', MAX_FILESIZE + 'm', '--max-filesize', MAX_FILESIZE + 'm',
'-S', 'res:' + quality '-S', 'res:' + quality,
'--no-playlist',
]) ])
} else { } else {
var fileName = Math.round(Math.random() * 100_000_000_000_000).toString()
var fileName = Math.round(Math.random() * 100_000_000_000_000).toString() + fileExtension
var filePath = path.join(__dirname, 'downloads', fileName) var filePath = path.join(__dirname, 'downloads', fileName)
var ytdlpProcess = cp.spawn('yt-dlp', [ var ytdlpProcess = cp.spawn('yt-dlp', [
url, url,
'-x', '-x',
'-o', filePath, '-o', filePath.substring(0, filePath.lastIndexOf('.')),
'--max-filesize', MAX_FILESIZE + 'm', '--max-filesize', MAX_FILESIZE + 'm',
'--no-playlist',
]) ])
fileName += '.opus'
filePath = path.join(__dirname, 'downloads', fileName)
} }
var lastDownload = 0 var lastDownload = 0
@ -100,15 +104,15 @@ app.get("/download", async (req, res) => {
if (data.includes("max-filesize")) { if (data.includes("max-filesize")) {
debounce = true debounce = true
res.write(`<p>Uh oh! The video you're trying to download is too large for this server's current settings ${MAX_FILESIZE}. Please try another server? (Visit main page and go to the codeberg for a list of instances!)</p>`) res.write(`<p>Uh oh! The video you're trying to download is too large for this server's current settings ${MAX_FILESIZE}. Please try another server? (Visit main page and go to the codeberg for a list of instances!)</p>`)
} }
else if (data.includes("[download]")) { else if (data.includes("[download]")) {
res.write(`<style>#downloading${lastDownload}{ display: none; }</style>`) res.write(`<style>#downloading${lastDownload}{ display: none; }</style>`)
lastDownload += 1 lastDownload += 1
res.write(`<p id="downloading${lastDownload}">` + data.substring(12) + `</p>`) res.write(`<p id="downloading${lastDownload}">` + data.substring(12) + `</p>`)
} }
} }
}) })
var exited = false var exited = false
@ -121,10 +125,9 @@ app.get("/download", async (req, res) => {
} }
else if (fs.existsSync(filePath)) { else if (fs.existsSync(filePath)) {
res.write(`<iframe src="/convert?file=${fileName}&format=${format}&url=${url}"></iframe>"`) res.write(`<iframe src="/convert?file=${fileName}&format=${format}&url=${url}"></iframe>"`)
res.write(downloadHTML.substring(downloadHTML.indexOf("{CONTENT}") + 9), () => {res.end()}) res.write(downloadHTML.substring(downloadHTML.indexOf("{CONTENT}") + 9), () => { res.end() })
} else { } else {
res.write("<p>An error has occured!!! We're not exactly sure what the error is, but we cant seem to find the download file. Double check the URL, and if the URL is fine, then file an issue on codeberg. </p>") res.write("<p>An error has occured!!! We're not exactly sure what the error is, but we cant seem to find the download file. Double check the URL, and if the URL is fine, then file an issue on codeberg. </p>")
console.log(filePath)
} }
}) })