diff --git a/index.js b/index.js index 92e2da1..1f7f0fe 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ app.get("/convert", async (req, res) => { var filePath = path.join(__dirname, 'downloads', file) if (fs.existsSync(filePath)) { - var ytdlpProcess = cp.spawnSync('yt-dlp', ['--get-filename', url]) + var ytdlpProcess = cp.spawnSync('./yt-dlp', ['--get-filename', url]) var name = ytdlpProcess.stdout.toString() name = name.substring(0, name.lastIndexOf("[") - 1) res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(name)}.${format}"`); @@ -43,9 +43,9 @@ app.get("/convert", async (req, res) => { }) ffmpegProcess.stderr.setEncoding('utf-8') - ffmpegProcess.stderr.on('data', (data) => { - console.log(data) - }) + // ffmpegProcess.stderr.on('data', (data) => { + // console.log(data) + // }) // These are debugging lines to watch FFMPEG output :3 ffmpegProcess.stdio[1].pipe(res) @@ -63,10 +63,10 @@ app.get("/download", async (req, res) => { res.setHeader("X-Accel-Buffering", "no") var fileName = Math.ceil(Math.random() * 100_000_000_000).toString() - var videoName = cp.spawnSync('yt-dlp', ['-S', 'res:' + quality, '--get-filename', url]).stdout.toString() + var videoName = cp.spawnSync('./yt-dlp', ['-S', 'res:' + quality, '--get-filename', url]).stdout.toString() videoName = videoName.substring(0, videoName.lastIndexOf('.')) - videoName = videoName.substring(0, videoName.lastIndexOf('[')) + videoName = videoName.substring(0, videoName.lastIndexOf('[') - 1) if (!["mp3", "wav", "ogx"].includes(format) && Number(quality) > 720) { res.setHeader("Content-Type", "text/html") @@ -76,7 +76,7 @@ app.get("/download", async (req, res) => { res.write(downloadHTML.substring(0, downloadHTML.indexOf("{CONTENT}"))) var filePath = path.join(__dirname, 'downloads', fileName) - var ytdlpProcess = cp.spawn('yt-dlp', [ + var ytdlpProcess = cp.spawn('./yt-dlp', [ url, '-o', filePath, '--max-filesize', MAX_FILESIZE + 'm', @@ -88,7 +88,7 @@ app.get("/download", async (req, res) => { ytdlpProcess.stderr.setEncoding('utf-8') ytdlpProcess.stderr.on('data', (data) => { - console.log(data) + // console.log(data) res.write(`

` + data + `

`) }) @@ -118,7 +118,7 @@ app.get("/download", async (req, res) => { var files = fs.readdirSync(path.join(__dirname, 'downloads')) for (let index = 0; index < files.length; index++) { const file = files[index]; - console.log(file) + console.log(fileName) if (file.includes(fileName)) { fileName = file filePath = path.join(__dirname, 'downloads', fileName) @@ -147,7 +147,7 @@ app.get("/download", async (req, res) => { } else if (["mp3", "wav", "opus"].includes(format)) { res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(videoName)}.${format}"`); - var ytdlpProcess = cp.spawn('yt-dlp', [ + var ytdlpProcess = cp.spawn('./yt-dlp', [ url, '-x', '-o', '-', @@ -173,15 +173,15 @@ app.get("/download", async (req, res) => { ytdlpProcess.stdout.pipe(ffmpegProcess.stdio[3]) ytdlpProcess.stderr.setEncoding('utf-8') - ytdlpProcess.stderr.on('data', (data) => { - console.log(data) - }) + // ytdlpProcess.stderr.on('data', (data) => { + // console.log(data) + // }) ffmpegProcess.stdio[1].pipe(res) } else { res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(videoName)}.${format}"`); - var ytdlpProcess = cp.spawn('yt-dlp', [ + var ytdlpProcess = cp.spawn('./yt-dlp', [ url, '-o', '-', '--max-filesize', MAX_FILESIZE + 'm', @@ -207,9 +207,9 @@ app.get("/download", async (req, res) => { ytdlpProcess.stdout.pipe(ffmpegProcess.stdio[3]) ytdlpProcess.stderr.setEncoding('utf-8') - ytdlpProcess.stderr.on('data', (data) => { - console.log(data) - }) + // ytdlpProcess.stderr.on('data', (data) => { + // console.log(data) + // }) ffmpegProcess.stdio[1].pipe(res) } diff --git a/yt-dlp b/yt-dlp new file mode 100755 index 0000000..046751c Binary files /dev/null and b/yt-dlp differ