forked from Supositware/Haha-Yes
make it work with more link
This commit is contained in:
parent
c1df7a3506
commit
7aad74b9cd
1 changed files with 31 additions and 25 deletions
|
@ -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,7 +42,6 @@ class vidshittifyerCommand extends Command {
|
|||
let input = `${os.tmpdir()}/${message.id}.mp4`;
|
||||
let output = `${os.tmpdir()}/Shittifyed${message.id}.mp4`;
|
||||
let compression;
|
||||
if (args.link) {
|
||||
if (args.compression == 1) {
|
||||
compression = '10M';
|
||||
} else if (args.compression == 2) {
|
||||
|
@ -47,14 +50,20 @@ class vidshittifyerCommand extends Command {
|
|||
compression = '10k';
|
||||
}
|
||||
let option = `-b:v ${compression} -b:a ${compression}`;
|
||||
if (args.link) {
|
||||
|
||||
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.');
|
||||
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();
|
||||
});
|
||||
video.pipe(fs.createWriteStream(input));
|
||||
video.on('end', function () {
|
||||
} 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();
|
||||
|
@ -64,9 +73,6 @@ class vidshittifyerCommand extends Command {
|
|||
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…
Reference in a new issue