2019-10-28 18:22:26 +01:00
|
|
|
const { Command } = require('discord-akairo');
|
|
|
|
const os = require('os');
|
2020-07-16 09:20:24 +02:00
|
|
|
const ffmpeg = require('fluent-ffmpeg');
|
|
|
|
const attachment = require('../../utils/attachment');
|
|
|
|
const downloader = require('../../utils/download');
|
2019-10-28 18:22:26 +01:00
|
|
|
|
|
|
|
class gif2vidCommand extends Command {
|
|
|
|
constructor() {
|
|
|
|
super('gif2vid', {
|
|
|
|
aliases: ['gif2vid', 'g2v', 'gv'],
|
|
|
|
category: 'utility',
|
2019-11-09 12:04:01 +01:00
|
|
|
clientPermissions: ['SEND_MESSAGES', 'ATTACH_FILES'],
|
2019-10-28 18:22:26 +01:00
|
|
|
args: [
|
|
|
|
{
|
|
|
|
id: 'vid',
|
|
|
|
type: 'string'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
description: {
|
|
|
|
content: 'Transform gif into video.',
|
2019-10-30 18:13:08 +01:00
|
|
|
usage: '[link to gif]',
|
2019-10-28 18:22:26 +01:00
|
|
|
examples: ['']
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async exec(message, args) {
|
2020-07-16 09:20:24 +02:00
|
|
|
let vid;
|
2020-07-11 01:33:27 +02:00
|
|
|
|
2020-07-16 09:20:24 +02:00
|
|
|
if (args.vid)
|
|
|
|
vid = args.vid.href;
|
|
|
|
else
|
|
|
|
vid = await attachment(message);
|
2020-07-11 01:33:27 +02:00
|
|
|
|
2020-07-16 09:20:24 +02:00
|
|
|
if (!vid.endsWith('gif')) return message.channel.send('Please use a gif.');
|
2019-10-28 18:22:26 +01:00
|
|
|
|
|
|
|
let loadingmsg = await message.channel.send('Processing <a:loadingmin:527579785212329984>');
|
|
|
|
|
2020-07-16 09:20:24 +02:00
|
|
|
downloader(vid, null, `${os.tmpdir()}/${message.id}g2v`)
|
|
|
|
.on('error', async err => {
|
2019-10-28 18:22:26 +01:00
|
|
|
loadingmsg.delete();
|
2020-07-16 09:20:24 +02:00
|
|
|
return message.channel.send(err, { code: true });
|
|
|
|
})
|
|
|
|
.on('end', async output => {
|
|
|
|
let ffmpegCommand = ffmpeg(output);
|
2019-10-28 18:22:26 +01:00
|
|
|
|
2020-07-16 09:20:24 +02:00
|
|
|
ffmpegCommand.videoFilters('scale=trunc(iw/2)*2:trunc(ih/2)*2');
|
|
|
|
ffmpegCommand.fps(args.fps ? args.fps : 15);
|
|
|
|
ffmpegCommand.output(`${os.tmpdir()}/${message.id}g2v.mp4`);
|
|
|
|
ffmpegCommand.outputOptions('-pix_fmt yuv420p');
|
|
|
|
ffmpegCommand.run();
|
|
|
|
ffmpegCommand.on('error', (err, stdout, stderr) => {
|
|
|
|
loadingmsg.delete();
|
|
|
|
console.error(`${err}\n${stdout}\n${stderr}`);
|
|
|
|
return message.channel.send('Uh oh, an error has occurred!' + err);
|
|
|
|
});
|
|
|
|
ffmpegCommand.on('end', () => {
|
|
|
|
loadingmsg.delete();
|
|
|
|
message.delete();
|
|
|
|
return message.channel.send({files: [`${os.tmpdir()}/${message.id}g2v.mp4`]})
|
|
|
|
.catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
return message.channel.send(`${err.name}: ${err.message} ${err.message === 'Request entity too large' ? 'The file size is too big' : ''}`);
|
|
|
|
});
|
|
|
|
});
|
2019-10-28 18:22:26 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = gif2vidCommand;
|