From ac4e2ad160cedafa1883efddf05815ac1c18fc19 Mon Sep 17 00:00:00 2001 From: Bingus_Violet Date: Wed, 17 Jan 2024 20:39:08 -0600 Subject: [PATCH] Fixed bug, more audio format --- index.js | 32 +++++++++++++++++++++++--------- static/index.html | 22 ++++++++++++---------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index d41f827..5f019ba 100644 --- a/index.js +++ b/index.js @@ -31,10 +31,10 @@ 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) @@ -58,14 +58,15 @@ app.get("/download", async (req, res) => { res.write(downloadHTML.substring(0, downloadHTML.indexOf("{CONTENT}"))) - - if (!format in ["mp3"]) { + console.log(format) + 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 ytdlpProcess = cp.spawn('yt-dlp', [ url, '-o', filePath, - '--max-filesize', MAX_FILESIZE + 'm' + '--max-filesize', MAX_FILESIZE + 'm', + '-S', 'res:' + quality ]) } else { var fileName = Math.round(Math.random() * 100_000_000_000_000).toString() @@ -75,7 +76,6 @@ app.get("/download", async (req, res) => { '-x', '-o', filePath, '--max-filesize', MAX_FILESIZE + 'm', - ]) fileName += '.opus' filePath = path.join(__dirname, 'downloads', fileName) @@ -108,8 +108,15 @@ app.get("/download", async (req, res) => { }) + var exited = false + ytdlpProcess.on('close', () => { - if (fs.existsSync(filePath)) { + if (exited) { + if (fs.existsSync(filePath)) { + fs.rmSync(filePath) + } + } + else if (fs.existsSync(filePath)) { res.write(`"`) res.write(downloadHTML.substring(downloadHTML.indexOf("{CONTENT}") + 9), () => {res.end()}) } else { @@ -118,6 +125,13 @@ app.get("/download", async (req, res) => { } }) + res.on("error", () => { + if (fs.existsSync(filePath)) { + fs.rmSync(filePath) + } + exited = true + }) + }) app.use(express.static(path.join(__dirname, 'static'))) diff --git a/static/index.html b/static/index.html index e793edb..fd18b09 100644 --- a/static/index.html +++ b/static/index.html @@ -22,17 +22,17 @@

Quality:

- - - + + + + + + + + -

Format:

-
+