make it work with more link

merge-requests/4/head
loicbersier 5 years ago
parent c1df7a3506
commit 7aad74b9cd

@ -1,5 +1,4 @@
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const fs = require('fs');
const util = require('util'); const util = require('util');
const exec = util.promisify(require('child_process').exec); const exec = util.promisify(require('child_process').exec);
const youtubedl = require('youtube-dl'); const youtubedl = require('youtube-dl');
@ -19,6 +18,11 @@ class vidshittifyerCommand extends Command {
id: 'compresion', id: 'compresion',
type: 'string' type: 'string'
}, },
{
id: 'alt',
match: 'flag',
flag: '--alt'
},
{ {
id: 'watermark', id: 'watermark',
match: 'flag', match: 'flag',
@ -38,7 +42,6 @@ class vidshittifyerCommand extends Command {
let input = `${os.tmpdir()}/${message.id}.mp4`; let input = `${os.tmpdir()}/${message.id}.mp4`;
let output = `${os.tmpdir()}/Shittifyed${message.id}.mp4`; let output = `${os.tmpdir()}/Shittifyed${message.id}.mp4`;
let compression; let compression;
if (args.link) {
if (args.compression == 1) { if (args.compression == 1) {
compression = '10M'; compression = '10M';
} else if (args.compression == 2) { } else if (args.compression == 2) {
@ -47,14 +50,20 @@ class vidshittifyerCommand extends Command {
compression = '10k'; compression = '10k';
} }
let option = `-b:v ${compression} -b:a ${compression}`; let option = `-b:v ${compression} -b:a ${compression}`;
if (args.link) {
let video = youtubedl(args.link); return youtubedl.exec(args.link, ['-o', input], {}, function(err) {
video.on('error', function error(err) { if (err) {
console.log('error 2:', err); console.error(err);
message.channel.send('An error has occured, I can\'t download from the link you provided.'); return message.channel.send('An error has occured, I can\'t download from the link you provided.');
}
shittify();
}); });
video.pipe(fs.createWriteStream(input)); } else {
video.on('end', function () { return message.channel.send('You need a valid video link!');
}
function shittify() {
exec(`ffmpeg -i ${input} ${option} -vcodec libx264 -r 5 -r 15 ${output}`) exec(`ffmpeg -i ${input} ${option} -vcodec libx264 -r 5 -r 15 ${output}`)
.then(() => { .then(() => {
message.delete(); message.delete();
@ -64,9 +73,6 @@ class vidshittifyerCommand extends Command {
return message.channel.send('On no! an error just occured! perhaps the file is too big?'); return message.channel.send('On no! an error just occured! perhaps the file is too big?');
}); });
}); });
});
} else {
return message.channel.send('You need a valid video link!');
} }
} }
} }

Loading…
Cancel
Save