make it work with more link

This commit is contained in:
loicbersier 2019-10-12 14:50:52 +02:00
parent c1df7a3506
commit 7aad74b9cd

View file

@ -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,36 +42,38 @@ 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.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.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); 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.');
}); }
video.pipe(fs.createWriteStream(input)); shittify();
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?');
});
});
}); });
} else { } else {
return message.channel.send('You need a valid video link!'); 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?');
});
});
}
} }
} }