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);
|
2020-06-17 18:42:52 +02:00
|
|
|
const downloader = require('../../utils/download');
|
2019-10-12 12:16:19 +02:00
|
|
|
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',
|
2019-11-09 12:04:01 +01:00
|
|
|
clientPermissions: ['SEND_MESSAGES', 'ATTACH_FILES'],
|
2019-10-12 12:16:19 +02:00
|
|
|
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: {
|
2020-06-15 17:56:51 +02:00
|
|
|
content: 'Compress your videos and lower their quality!',
|
2019-10-12 12:48:36 +02:00
|
|
|
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-11-09 12:04:01 +01:00
|
|
|
let input2 = `${os.tmpdir()}/tmp${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;
|
|
|
|
|
2020-06-15 18:00:05 +02:00
|
|
|
if (args.compression === 1) {
|
2019-10-12 18:09:31 +02:00
|
|
|
compression = '50k';
|
2019-10-12 19:39:36 +02:00
|
|
|
audioCompression = '100k';
|
2019-11-09 12:04:01 +01:00
|
|
|
} else {
|
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
|
|
|
}
|
2019-11-09 12:04:01 +01: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) {
|
2020-06-17 18:42:52 +02:00
|
|
|
downloader(args.link, null, input)
|
2020-07-11 01:33:12 +02:00
|
|
|
.on('error', (err) => {
|
2019-10-12 15:10:11 +02:00
|
|
|
loadingmsg.delete();
|
2020-06-17 18:42:52 +02:00
|
|
|
return message.channel.send(err, { code: true });
|
|
|
|
})
|
2020-07-11 01:33:12 +02:00
|
|
|
.on('end', () => {
|
2019-10-12 18:30:17 +02:00
|
|
|
shittifie();
|
2020-06-17 18:42:52 +02:00
|
|
|
});
|
2019-10-12 12:16:19 +02:00
|
|
|
} else {
|
2020-06-15 17:56:51 +02:00
|
|
|
return message.channel.send('You need a valid video link! Try again!');
|
2019-10-12 12:16:19 +02:00
|
|
|
}
|
2019-10-12 14:50:52 +02:00
|
|
|
|
2019-10-12 16:49:07 +02:00
|
|
|
function shittifie() {
|
2019-11-09 12:04:01 +01:00
|
|
|
// reduce video resolution
|
|
|
|
exec(`ffmpeg -i ${input} -vf "scale=iw/4:ih/4" ${input2}`)
|
2019-10-12 14:50:52 +02:00
|
|
|
.then(() => {
|
2019-11-09 12:04:01 +01:00
|
|
|
// upscale video and change bitrate
|
|
|
|
exec(`ffmpeg -i ${input2} ${option} -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2" -vcodec libx264 -r 15 -f mp4 ${output}`)
|
|
|
|
.then(() => {
|
|
|
|
loadingmsg.delete();
|
|
|
|
message.delete();
|
|
|
|
return message.channel.send({files: [output]})
|
|
|
|
.catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
loadingmsg.delete();
|
2020-06-15 17:56:51 +02:00
|
|
|
return message.channel.send('On no! an error just occured! Maybe the file is too big?');
|
2019-11-09 12:04:01 +01:00
|
|
|
});
|
|
|
|
})
|
2019-10-12 14:50:52 +02:00
|
|
|
.catch(err => {
|
|
|
|
console.error(err);
|
2019-10-12 15:10:11 +02:00
|
|
|
loadingmsg.delete();
|
2020-06-15 18:00:05 +02:00
|
|
|
return message.channel.send('Oh no! an error just occured! We don\'t know what causes this error yet, so let us know!');
|
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;
|