2018-11-18 17:58:08 +01:00
|
|
|
const { Command } = require('discord.js-commando');
|
|
|
|
const fs = require('fs');
|
|
|
|
const youtubedl = require('youtube-dl');
|
2018-11-28 01:35:26 +01:00
|
|
|
const SelfReloadJSON = require('self-reload-json');
|
|
|
|
const blacklist = require('../../blacklist');
|
2018-11-18 17:58:08 +01:00
|
|
|
const { fbuser, fbpasswd } = require('../../config.json');
|
|
|
|
|
2018-11-18 18:04:13 +01:00
|
|
|
module.exports = class downloadCommand extends Command {
|
2018-11-18 17:58:08 +01:00
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
2018-11-18 18:04:13 +01:00
|
|
|
name: 'download',
|
2018-11-18 17:58:08 +01:00
|
|
|
group: 'utility',
|
2018-11-18 18:04:13 +01:00
|
|
|
memberName: 'download',
|
2018-11-18 17:58:08 +01:00
|
|
|
description: `Download any video from the link you provided.`,
|
|
|
|
args: [
|
|
|
|
{
|
|
|
|
key: 'link',
|
|
|
|
prompt: 'Wich video would you like to download?',
|
|
|
|
type: 'string',
|
|
|
|
default: 'https://www.youtube.com/watch?v=6n3pFFPSlW4'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async run(message, { link }) {
|
2018-12-04 16:22:45 +01:00
|
|
|
let blacklistJson = new SelfReloadJSON('./json/blacklist.json');
|
2018-11-28 01:35:26 +01:00
|
|
|
if(blacklistJson[message.author.id])
|
|
|
|
return blacklist(blacklistJson[message.author.id] , message)
|
|
|
|
|
2018-11-18 17:58:08 +01:00
|
|
|
if(link.includes("http") || link.includes("www")) {
|
2018-11-18 18:28:27 +01:00
|
|
|
message.say('Downloading...').then(msg => {
|
|
|
|
video.on('end', function() {
|
|
|
|
msg.delete()
|
|
|
|
})
|
|
|
|
})
|
2018-11-18 17:58:08 +01:00
|
|
|
let video = youtubedl(link, [`--username=${fbuser}`,`--password=${fbpasswd}`])
|
|
|
|
video.pipe(fs.createWriteStream('video.mp4'))
|
2018-11-20 19:47:54 +01:00
|
|
|
video.on('error', function error(err) {
|
|
|
|
console.log('error 2:', err);
|
|
|
|
message.say("An error has occured, i can't download from the link you provided.")
|
|
|
|
});
|
2018-11-18 17:58:08 +01:00
|
|
|
video.on('end', function() {
|
2018-11-18 18:28:27 +01:00
|
|
|
message.delete();
|
|
|
|
message.channel.send(`Downloaded by ${message.author.username}`, {files: ["./video.mp4"]})
|
2018-11-20 19:47:54 +01:00
|
|
|
.catch(error => message.say('File too big'))
|
2018-11-18 17:58:08 +01:00
|
|
|
})
|
|
|
|
} else
|
|
|
|
message.say("You need to input a valid link")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|