Haha-Yes/commands/fun/vidshittifyer.js

74 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-10-12 12:16:19 +02:00
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');
const os = require('os');
class vidshittifyerCommand extends Command {
constructor() {
super('vidshittifyer', {
aliases: ['vidshittifyer', 'vs', 'shittifyer', 'vid2shit', 'v2s'],
category: 'fun',
args: [
{
id: 'link',
type: 'string',
2019-10-12 12:48:36 +02:00
},
{
id: 'compresion',
type: 'string'
2019-10-12 13:09:19 +02:00
},
{
id: 'watermark',
match: 'flag',
flag: '--watermark'
2019-10-12 12:16:19 +02:00
}
],
description: {
2019-10-12 12:48:36 +02:00
content: 'Make your vid shit quality.',
usage: '[link to video] [compression ( 1, 2 or 3)]',
2019-10-12 12:16:19 +02:00
examples: ['']
}
});
}
async exec(message, args) {
let input = `${os.tmpdir()}/${message.id}.mp4`;
let output = `${os.tmpdir()}/Shittifyed${message.id}.mp4`;
2019-10-12 12:48:36 +02:00
let compression;
2019-10-12 12:16:19 +02:00
if (args.link) {
2019-10-12 12:48:36 +02:00
if (args.compression == 1) {
2019-10-12 13:12:55 +02:00
compression = '10M';
2019-10-12 12:48:36 +02:00
} else if (args.compression == 2) {
2019-10-12 13:12:55 +02:00
compression = '5M';
2019-10-12 12:48:36 +02:00
} else {
compression = '10k';
}
2019-10-12 13:11:21 +02:00
let option = `-b:v ${compression} -b:a ${compression}`;
2019-10-12 12:16:19 +02:00
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 () {
2019-10-12 13:09:19 +02:00
exec(`ffmpeg -i ${input} ${option} -vcodec libx264 -r 5 -r 15 ${output}`)
2019-10-12 12:16:19 +02:00
.then(() => {
2019-10-12 12:48:36 +02:00
message.delete();
2019-10-12 12:16:19 +02:00
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 {
return message.channel.send('You need a valid video link!');
}
}
}
module.exports = vidshittifyerCommand;