2018-12-30 01:20:24 +01:00
|
|
|
const { Command } = require('discord-akairo');
|
2018-11-18 17:58:08 +01:00
|
|
|
const fs = require('fs');
|
|
|
|
const youtubedl = require('youtube-dl');
|
|
|
|
const { fbuser, fbpasswd } = require('../../config.json');
|
2018-12-25 19:17:07 +01:00
|
|
|
|
2018-12-30 01:20:24 +01:00
|
|
|
class DownloadCommand extends Command {
|
|
|
|
constructor() {
|
|
|
|
super('download', {
|
|
|
|
aliases: ['download', 'dl'],
|
|
|
|
category: 'utility',
|
2018-11-18 17:58:08 +01:00
|
|
|
args: [
|
|
|
|
{
|
2018-12-30 01:20:24 +01:00
|
|
|
id: "link",
|
|
|
|
type: "string",
|
|
|
|
default: "https://www.youtube.com/watch?v=6n3pFFPSlW4"
|
2018-11-18 17:58:08 +01:00
|
|
|
}
|
2018-12-30 01:20:24 +01:00
|
|
|
],
|
|
|
|
clientPermissions: ['ATTACH_FILES'],
|
|
|
|
description: {
|
|
|
|
content: 'Download videos from different website from the link you provided',
|
|
|
|
usage: '[link]',
|
|
|
|
examples: ['https://www.youtube.com/watch?v=6n3pFFPSlW4']
|
|
|
|
}
|
2018-11-18 17:58:08 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-30 01:20:24 +01:00
|
|
|
async exec(message,args) {
|
|
|
|
let link = args.link;
|
|
|
|
|
2018-11-18 17:58:08 +01:00
|
|
|
if(link.includes("http") || link.includes("www")) {
|
2018-12-30 01:20:24 +01:00
|
|
|
message.channel.send('Downloading <a:loadingmin:527579785212329984>').then(msg => {
|
2018-11-18 18:28:27 +01:00
|
|
|
video.on('end', function() {
|
|
|
|
msg.delete()
|
|
|
|
})
|
|
|
|
})
|
2018-11-18 17:58:08 +01:00
|
|
|
let video = youtubedl(link, [`--username=${fbuser}`,`--password=${fbpasswd}`])
|
2018-12-05 00:54:28 +01:00
|
|
|
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);
|
2018-12-30 01:20:24 +01:00
|
|
|
message.channel.send("An error has occured, i can't download from the link you provided.")
|
2018-11-20 19:47:54 +01:00
|
|
|
});
|
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-12-30 01:20:24 +01:00
|
|
|
.catch(() => message.channel.send('File too big'))
|
2018-11-18 17:58:08 +01:00
|
|
|
})
|
|
|
|
} else
|
2018-12-30 01:20:24 +01:00
|
|
|
message.channel.send("You need to input a valid link")
|
2018-11-18 17:58:08 +01:00
|
|
|
}
|
2018-12-30 01:20:24 +01:00
|
|
|
}
|
2018-11-18 17:58:08 +01:00
|
|
|
|
2018-12-30 01:20:24 +01:00
|
|
|
module.exports = DownloadCommand;
|