From cef981c5223ed83b85c2c866980b5e049717a954 Mon Sep 17 00:00:00 2001 From: supositware Date: Sat, 12 Jun 2021 16:27:46 +0200 Subject: [PATCH] Check for video format --- routes/index.js | 91 ++++++++++++++++++++++++++---------------- views/index.ejs | 103 ++++++++++++++++++++++++------------------------ 2 files changed, 108 insertions(+), 86 deletions(-) diff --git a/routes/index.js b/routes/index.js index 6ccb6ec..df0096d 100644 --- a/routes/index.js +++ b/routes/index.js @@ -80,12 +80,39 @@ router.get('/', function(req, res, next) { router.get('/status/:uuid', function (req, res ,next) { let uuid = req.params.uuid; if (progress[uuid]) { - res.send(progress[uuid]); + return res.send(progress[uuid]); } else { - res.send(undefined); + return res.send(undefined); } }); +router.get('/format', function (req, res ,next) { + let url; + let i = 0; + try { + url = new URL(req.query.url); + } catch (e) { + return res.send(undefined); + } + + let formats = []; + + youtubedl.exec(url.href, ['--dump-json'], {}, function(err, output) { + if (err) throw err + let json = JSON.parse(output); + json.formats.forEach(format => { + if (format.vcodec === 'none' || format.acodec === 'none') + return; + + i++; + formats.push({ext: format.ext, id: format.format_id, note: format.format_note}); + }); + + return res.send(formats); + }); + return; +}); + router.post('/', async function(req, res, next) { let data; const form = formidable({ multiples: true}); @@ -99,22 +126,17 @@ router.post('/', async function(req, res, next) { }) }); - - console.log(data.url); if (data.url === undefined) { //res.render('index', { error: true, errormsg: 'You didn\'t input a link'}) return res.send('You didn\'t input a link') } - let quality; - if (data.quality === 'worst') { - quality = 'worst'; - } else { - quality = 'best'; - } + console.log(data.format); + + let format = data.format; - if (data.format === undefined) { - data.format = 'mp4'; + if (data.format === undefined || data.format === 'mp3' || data.format === 'flac') { + format = 'best'; } if (data.url.toLowerCase().includes('porn')) { @@ -132,7 +154,7 @@ router.post('/', async function(req, res, next) { } } - let options = ['--format=mp4', '-f', quality]; + let options = ['-f', format]; if (data.proxy !== 'none') { options.push('--proxy'); options.push(data.proxy); @@ -182,7 +204,28 @@ router.post('/', async function(req, res, next) { video.on('end', function() { progress[data.uuid] = 0; - if (data.format === 'mp4' || data.format === 'webm') { + + if (data.format === 'mp3' || data.format === 'flac') { + // If user requested an audio format, convert it + ffmpeg(`./public/uploads/${DLFile}`) + .noVideo() + .audioChannels('2') + .audioFrequency('44100') + .audioBitrate('320k') + .format(data.format) + .save(`./public/uploads/${DLFile.replace(`.${ext}`, `.${data.format}`)}`) + .on('error', function(err, stdout, stderr) { + console.log('Cannot process video: ' + err.message); + return res.json({error: err.message}); + //return res.render('index', { error: true, errormsg: err.message}) + }) + .on('end', () => { + fs.unlinkSync(`./public/uploads/${DLFile}`); + if (data.feed !== 'on') generateWaveform(DLFile.replace(`.${ext}`, `.${data.format}`)); + return res.json({url: `uploads/${DLFile.replace(`.${ext}`, `.${data.format}`)}`}); + //return res.attachment(`./public/uploads/${DLFile.replace(`.${ext}`, `.${data.format}`)}`); + }); + } else { if (data.sponsorBlock) { // WARNING: THIS PART SUCK let filter = ''; let abc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']; @@ -246,26 +289,6 @@ router.post('/', async function(req, res, next) { res.json({url: `uploads/${DLFile}`}) if (data.feed !== 'on') generateThumbnail(DLFile); } - } else { - // If user requested an audio format, convert it - ffmpeg(`./public/uploads/${DLFile}`) - .noVideo() - .audioChannels('2') - .audioFrequency('44100') - .audioBitrate('320k') - .format(data.format) - .save(`./public/uploads/${DLFile.replace(`.${ext}`, `.${data.format}`)}`) - .on('error', function(err, stdout, stderr) { - console.log('Cannot process video: ' + err.message); - return res.json({error: err.message}); - //return res.render('index', { error: true, errormsg: err.message}) - }) - .on('end', () => { - fs.unlinkSync(`./public/uploads/${DLFile}`); - if (data.feed !== 'on') generateWaveform(DLFile.replace(`.${ext}`, `.${data.format}`)); - return res.json({url: `uploads/${DLFile.replace(`.${ext}`, `.${data.format}`)}`}); - //return res.attachment(`./public/uploads/${DLFile.replace(`.${ext}`, `.${data.format}`)}`); - }); } }); diff --git a/views/index.ejs b/views/index.ejs index 104a530..55991ef 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -4,7 +4,7 @@ I guess have fun looking at the html, no easter egg to find here. Come take a look here https://git.namejeff.xyz/Supositware/jeff-downloader for all my bad coding --> - + @@ -24,20 +24,8 @@ Come take a look here https://git.namejeff.xyz/Supositware/jeff-downloader for a Le epic video downloader v<%= version %> -
-
+

Le epic downloader v<%= version %>

@@ -45,21 +33,6 @@ Come take a look here https://git.namejeff.xyz/Supositware/jeff-downloader for a
- - - - - -