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 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?');
});
});
}
}
}

Loading…
Cancel
Save