diff --git a/index.js b/index.js index c8e09bc..e7d2403 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,7 @@ app.get("/convert", async (req, res) => { '-i', filePath, '-f', formats[format] || format, '-movflags', 'frag_keyframe+empty_moov', - '-vcodec', 'copy' , + '-vcodec', 'copy', '-' ], { stdio: [ @@ -37,16 +37,16 @@ app.get("/convert", async (req, res) => { ], }) - ffmpegProcess.stderr.setEncoding('utf-8') - ffmpegProcess.stderr.on('data', (data) => { - console.log(data) - }) + // ffmpegProcess.stderr.setEncoding('utf-8') + // ffmpegProcess.stderr.on('data', (data) => { + // console.log(data) + // }) // These are debugging lines to watch FFMPEG output :3 - ffmpegProcess.stdio[1].pipe(res) - .on('close', () => { - fs.rmSync(filePath) - }) + ffmpegProcess.stdio[1].pipe(res) + .on('close', () => { + fs.rmSync(filePath) + }) } }) @@ -62,26 +62,30 @@ app.get("/download", async (req, res) => { 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)) { - var fileName = Math.round(Math.random() * 100_000_000_000_000).toString() + '.webm' - var filePath = path.join(__dirname, 'downloads', fileName) + var fileName = Math.round(Math.random() * 100_000_000_000_000).toString() + fileExtension + var filePath = path.join(__dirname, 'downloads', fileName).trim() var ytdlpProcess = cp.spawn('yt-dlp', [ url, - '-o', filePath, + '-o', filePath.substring(0, filePath.lastIndexOf('.')), '--max-filesize', MAX_FILESIZE + 'm', - '-S', 'res:' + quality + '-S', 'res:' + quality, + '--no-playlist', ]) } 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 ytdlpProcess = cp.spawn('yt-dlp', [ url, '-x', - '-o', filePath, + '-o', filePath.substring(0, filePath.lastIndexOf('.')), '--max-filesize', MAX_FILESIZE + 'm', + '--no-playlist', ]) - fileName += '.opus' - filePath = path.join(__dirname, 'downloads', fileName) } var lastDownload = 0 @@ -100,15 +104,15 @@ app.get("/download", async (req, res) => { if (data.includes("max-filesize")) { debounce = true res.write(`

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!)

`) - } + } else if (data.includes("[download]")) { res.write(``) lastDownload += 1 res.write(`

` + data.substring(12) + `

`) - } + } } - + }) var exited = false @@ -121,10 +125,9 @@ app.get("/download", async (req, res) => { } else if (fs.existsSync(filePath)) { res.write(`"`) - res.write(downloadHTML.substring(downloadHTML.indexOf("{CONTENT}") + 9), () => {res.end()}) + res.write(downloadHTML.substring(downloadHTML.indexOf("{CONTENT}") + 9), () => { res.end() }) } else { res.write("

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.

") - console.log(filePath) } })