From c211cfcc0b08bcde36cef97dfbf6a7ea959cb6dc Mon Sep 17 00:00:00 2001 From: bingus_violet Date: Sun, 27 Jul 2025 21:12:27 -0500 Subject: [PATCH] Should work with all sites now. tiktok mp3s dont work for some reason. --- downloader.js | 142 ++++++++++++++++++++++++++++---------------------- 1 file changed, 80 insertions(+), 62 deletions(-) diff --git a/downloader.js b/downloader.js index 6b28874..2582a80 100644 --- a/downloader.js +++ b/downloader.js @@ -62,7 +62,7 @@ expressManager.app.get("/download", async (req, res) => { var downloadMode = "audio" if (needsVideo) downloadMode = "auto" - + var info = await axios.post("https://cobalt.univerter.dev/", { url, downloadMode, @@ -75,74 +75,92 @@ expressManager.app.get("/download", async (req, res) => { } }) - console.log(info) - - var downloadType = "attachment" - if (req.query.playInBrowser) downloadType = "inline"; - var filename = info.data.filename || info.data.output.filename res.setHeader("Content-Disposition", `${downloadType}; filename="${filename.replace(/[^a-z0-9 ]/gi, '')}.${format}"`) - var baseArgs = [ - // Remove ffmpeg's console spamming - '-loglevel', 'error', - // // Set inputs - // '-i', 'pipe:4', - // '-i', 'pipe:5', - // Map audio & video from streams - // '-map', '0:a', - // '-map', '1:v', - // Keep encoding - '-c:v', 'copy', - '-movflags','frag_keyframe+empty_moov', - '-f', format, - // Define output file - '-', - ] - - var inputArgs = [ - '-i', 'pipe:4' - ] - var mapArgs = [ - '-map', '0:a' - ] + if (info.data.service == "youtube") { - var bonusArgs = [] + var downloadType = "attachment" + if (req.query.playInBrowser) downloadType = "inline"; + + var baseArgs = [ + // Remove ffmpeg's console spamming + '-loglevel', 'error', + // // Set inputs + // '-i', 'pipe:4', + // '-i', 'pipe:5', + // Map audio & video from streams + // '-map', '0:a', + // '-map', '1:v', + // Keep encoding + '-c:v', 'copy', + '-movflags','frag_keyframe+empty_moov', + '-f', format, + // Define output file + '-', + ] + + var inputArgs = [ + '-i', 'pipe:4' + ] - if (needsVideo) { - inputArgs = inputArgs.concat(['-i', 'pipe:5']) - mapArgs = mapArgs.concat(['-map', '1:v']) + var mapArgs = [ + '-map', '0:a' + ] + + var bonusArgs = [] + + if (needsVideo) { + inputArgs = inputArgs.concat(['-i', 'pipe:5']) + mapArgs = mapArgs.concat(['-map', '1:v']) + } + + if (trimAudio) { + bonusArgs = bonusArgs.concat(['-af', 'silenceremove=1:0:-50dB']) + } + + var args = inputArgs.concat(mapArgs).concat(bonusArgs).concat(baseArgs) + + const ffmpegProcess = cp.spawn(ffmpeg, args, { + windowsHide: true, + stdio: [ + /* Standard: stdin, stdout, stderr */ + 'pipe', 'pipe', 'pipe', + /* Custom: pipe:3, pipe:4, pipe:5 */ + 'pipe', 'pipe', 'pipe', + ], + }); + + ffmpegProcess.stdio[1].pipe(res) + + var audio = await fetch(info.data.tunnel[1] || info.data.tunnel[0]) + + Readable.fromWeb(audio.body).pipe(ffmpegProcess.stdio[4]) + + if (needsVideo) { + var video = await fetch(info.data.tunnel[0]) + + Readable.fromWeb(video.body).pipe(ffmpegProcess.stdio[5]) + } + } else { + var info = await axios.post("https://cobalt.univerter.dev/", { + url, + downloadMode, + videoQuality: quality, + localProcessing: false, + }, { + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + } + }) + + console.log(info) + var video = await fetch(info.data.url) + + Readable.fromWeb(video.body).pipe(res) } - - if (trimAudio) { - bonusArgs = bonusArgs.concat(['-af', 'silenceremove=1:0:-50dB']) - } - - var args = inputArgs.concat(mapArgs).concat(bonusArgs).concat(baseArgs) - - const ffmpegProcess = cp.spawn(ffmpeg, args, { - windowsHide: true, - stdio: [ - /* Standard: stdin, stdout, stderr */ - 'pipe', 'pipe', 'pipe', - /* Custom: pipe:3, pipe:4, pipe:5 */ - 'pipe', 'pipe', 'pipe', - ], - }); - - ffmpegProcess.stdio[1].pipe(res) - - var audio = await fetch(info.data.url || info.data.tunnel[1] || info.data.tunnel[0]) - - Readable.fromWeb(audio.body).pipe(ffmpegProcess.stdio[4]) - - if (needsVideo) { - var video = await fetch(info.data.url || info.data.tunnel[0]) - - Readable.fromWeb(video.body).pipe(ffmpegProcess.stdio[5]) - } - } else { res.send("Invalid URL!") }