From 7aad74b9cdf418bb6e24e0656e847a79aa83aabe Mon Sep 17 00:00:00 2001 From: loicbersier Date: Sat, 12 Oct 2019 14:50:52 +0200 Subject: [PATCH] make it work with more link --- commands/fun/vidshittifyer.js | 56 +++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/commands/fun/vidshittifyer.js b/commands/fun/vidshittifyer.js index 245d19f..651e916 100644 --- a/commands/fun/vidshittifyer.js +++ b/commands/fun/vidshittifyer.js @@ -1,5 +1,4 @@ const { Command } = require('discord-akairo'); -const fs = require('fs'); const util = require('util'); const exec = util.promisify(require('child_process').exec); const youtubedl = require('youtube-dl'); @@ -19,6 +18,11 @@ class vidshittifyerCommand extends Command { id: 'compresion', type: 'string' }, + { + id: 'alt', + match: 'flag', + flag: '--alt' + }, { id: 'watermark', match: 'flag', @@ -38,36 +42,38 @@ class vidshittifyerCommand extends Command { let input = `${os.tmpdir()}/${message.id}.mp4`; let output = `${os.tmpdir()}/Shittifyed${message.id}.mp4`; let compression; + if (args.compression == 1) { + compression = '10M'; + } else if (args.compression == 2) { + compression = '5M'; + } else { + compression = '10k'; + } + let option = `-b:v ${compression} -b:a ${compression}`; if (args.link) { - if (args.compression == 1) { - compression = '10M'; - } else if (args.compression == 2) { - compression = '5M'; - } else { - compression = '10k'; - } - let option = `-b:v ${compression} -b:a ${compression}`; - let video = youtubedl(args.link); - video.on('error', function error(err) { - console.log('error 2:', err); - message.channel.send('An error has occured, I can\'t download from the link you provided.'); - }); - video.pipe(fs.createWriteStream(input)); - video.on('end', function () { - exec(`ffmpeg -i ${input} ${option} -vcodec libx264 -r 5 -r 15 ${output}`) - .then(() => { - message.delete(); - return message.channel.send({files: [output]}) - .catch(err => { - console.error(err); - return message.channel.send('On no! an error just occured! perhaps the file is too big?'); - }); - }); + return youtubedl.exec(args.link, ['-o', input], {}, function(err) { + if (err) { + console.error(err); + return message.channel.send('An error has occured, I can\'t download from the link you provided.'); + } + shittify(); }); } else { return message.channel.send('You need a valid video link!'); } + + function shittify() { + exec(`ffmpeg -i ${input} ${option} -vcodec libx264 -r 5 -r 15 ${output}`) + .then(() => { + message.delete(); + return message.channel.send({files: [output]}) + .catch(err => { + console.error(err); + return message.channel.send('On no! an error just occured! perhaps the file is too big?'); + }); + }); + } } }