Haha-Yes/commands/fun/vidshittifier.js

93 lines
2.4 KiB
JavaScript
Raw Normal View History

2019-10-12 12:16:19 +02:00
const { Command } = require('discord-akairo');
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const youtubedl = require('youtube-dl');
const os = require('os');
2019-10-12 16:49:07 +02:00
class vidshittifierCommand extends Command {
2019-10-12 12:16:19 +02:00
constructor() {
2019-10-12 16:49:07 +02:00
super('vidshittifier', {
aliases: ['vidshittifier', 'vs', 'shittifier', 'vid2shit', 'v2s'],
2019-10-12 12:16:19 +02:00
category: 'fun',
args: [
{
id: 'link',
type: 'string',
2019-10-12 12:48:36 +02:00
},
{
2019-10-12 19:39:36 +02:00
id: 'compression',
2019-10-12 18:04:31 +02:00
type: 'integer'
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) {
2019-10-12 19:26:35 +02:00
let Attachment = (message.attachments).array();
let url = args.link;
// Get attachment link
if (Attachment[0] && !args.link) {
url = Attachment[0].url;
}
2019-10-12 18:01:10 +02:00
let input = `${os.tmpdir()}/${message.id}.mp4`;
2019-10-13 00:19:08 +02:00
let output = `${os.tmpdir()}/Shittified${message.id}.mp4`;
2019-10-12 19:39:36 +02:00
2019-10-12 12:48:36 +02:00
let compression;
2019-10-12 19:39:36 +02:00
let audioCompression;
if (args.compression == 1) {
2019-10-12 18:09:31 +02:00
compression = '50k';
2019-10-12 19:39:36 +02:00
audioCompression = '100k';
} else if (args.compression == 2) {
2019-10-12 18:09:31 +02:00
compression = '30k';
2019-10-12 19:39:36 +02:00
audioCompression = '60k';
2019-10-12 14:50:52 +02:00
} else {
compression = '10k';
2019-10-12 19:39:36 +02:00
audioCompression = '20k';
2019-10-12 14:50:52 +02:00
}
2019-10-12 19:39:36 +02:00
let option = `-b:v ${compression} -b:a ${audioCompression}`;
2019-10-12 13:11:21 +02:00
2019-10-12 15:10:11 +02:00
let loadingmsg = await message.channel.send('Processing <a:loadingmin:527579785212329984>');
2019-10-12 19:26:35 +02:00
if (url) {
return youtubedl.exec(url, ['-o', input], {}, function(err) {
2019-10-12 14:50:52 +02:00
if (err) {
console.error(err);
2019-10-12 15:10:11 +02:00
loadingmsg.delete();
2019-10-12 14:50:52 +02:00
return message.channel.send('An error has occured, I can\'t download from the link you provided.');
} else {
shittifie();
2019-10-12 14:50:52 +02:00
}
2019-10-12 12:16:19 +02:00
});
} else {
return message.channel.send('You need a valid video link!');
}
2019-10-12 14:50:52 +02:00
2019-10-12 16:49:07 +02:00
function shittifie() {
2019-10-12 18:01:10 +02:00
exec(`ffmpeg -i ${input} ${option} -vcodec libx264 -r 15 ${output}`)
2019-10-12 14:50:52 +02:00
.then(() => {
loadingmsg.delete();
2019-10-12 14:50:52 +02:00
message.delete();
return message.channel.send({files: [output]})
.catch(err => {
console.error(err);
2019-10-12 15:10:11 +02:00
loadingmsg.delete();
2019-10-12 14:50:52 +02:00
return message.channel.send('On no! an error just occured! perhaps the file is too big?');
});
2019-10-12 17:08:18 +02:00
})
.catch(err => {
console.error(err);
loadingmsg.delete();
2019-10-12 18:02:46 +02:00
return message.channel.send('On no! an error just occured! Im gonna be honest with you, i don\'t know what caused it yet! but worry not! my owner will look into it soon!');
2019-10-12 14:50:52 +02:00
});
}
2019-10-12 12:16:19 +02:00
}
}
2019-10-12 16:49:07 +02:00
module.exports = vidshittifierCommand;