Haha-Yes/commands/utility/download.js

52 lines
2 KiB
JavaScript
Raw Normal View History

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');
const { fbuser, fbpasswd } = require('../../config.json');
2018-11-18 18:04:13 +01:00
module.exports = class downloadCommand extends Command {
constructor(client) {
super(client, {
2018-11-18 18:04:13 +01:00
name: 'download',
group: 'utility',
2018-11-18 18:04:13 +01:00
memberName: 'download',
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)
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()
})
})
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.")
});
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'))
})
} else
message.say("You need to input a valid link")
}
}