forked from Supositware/Haha-Yes
No longer need alt download link
This commit is contained in:
parent
9a3ac5bc6e
commit
c6b97689e3
1 changed files with 52 additions and 92 deletions
|
@ -17,11 +17,6 @@ class DownloadCommand extends Command {
|
||||||
start: 'Send the link of wich video you want to download',
|
start: 'Send the link of wich video you want to download',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
id: 'alt',
|
|
||||||
match: 'flag',
|
|
||||||
flag: '--alt'
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: 'spoiler',
|
id: 'spoiler',
|
||||||
match: 'flag',
|
match: 'flag',
|
||||||
|
@ -39,7 +34,6 @@ class DownloadCommand extends Command {
|
||||||
|
|
||||||
async exec(message, args) {
|
async exec(message, args) {
|
||||||
let link = args.link;
|
let link = args.link;
|
||||||
let needCompress = false;
|
|
||||||
let fileName;
|
let fileName;
|
||||||
|
|
||||||
if (args.spoiler) {
|
if (args.spoiler) {
|
||||||
|
@ -51,60 +45,61 @@ class DownloadCommand extends Command {
|
||||||
if (link.includes('http') || link.includes('www')) {
|
if (link.includes('http') || link.includes('www')) {
|
||||||
let loadingmsg = await message.channel.send('Downloading <a:loadingmin:527579785212329984>');
|
let loadingmsg = await message.channel.send('Downloading <a:loadingmin:527579785212329984>');
|
||||||
|
|
||||||
if (args.alt) {
|
if (fs.existsSync(`${os.tmpdir()}/${fileName}.mp4`)) {
|
||||||
console.log('alt download!');
|
fs.unlink(`${os.tmpdir()}/${fileName}.mp4`, (err) => {
|
||||||
if (fs.existsSync(`${os.tmpdir()}/${fileName}.mp4`)) {
|
if (err);
|
||||||
fs.unlink(`${os.tmpdir()}/${fileName}.mp4`, (err) => {
|
|
||||||
if (err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return youtubedl.exec(args.link, ['-o', `${os.tmpdir()}/${fileName}.mp4`], {}, async function(err, output) {
|
|
||||||
if (err) throw err;
|
|
||||||
console.log(output.join('\n'));
|
|
||||||
message.delete();
|
|
||||||
loadingmsg.delete();
|
|
||||||
message.channel.send(`Downloaded by ${message.author.username}`, { files: [`${os.tmpdir()}/${fileName}.mp4`] })
|
|
||||||
.catch(err => {
|
|
||||||
console.error(err);
|
|
||||||
loadingmsg.delete();
|
|
||||||
return message.channel.send('File too big');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return youtubedl.exec(args.link, ['-o', `${os.tmpdir()}/${fileName}.mp4`], {}, async function(err, output) {
|
||||||
|
if (err) {
|
||||||
let video = youtubedl(link);
|
console.error(err);
|
||||||
video.pipe(fs.createWriteStream(`${os.tmpdir()}/${fileName}.mp4`));
|
loadingmsg.delete();
|
||||||
video.on('error', async function error(err) {
|
return message.channel.send('An error has occured, I can\'t download from the link you provided.');
|
||||||
console.log('error 2:', err);
|
|
||||||
loadingmsg.delete();
|
|
||||||
message.channel.send('An error has occured, I can\'t download from the link you provided.');
|
|
||||||
});
|
|
||||||
|
|
||||||
video.on('info', async function(info) {
|
|
||||||
let duration = info.duration;
|
|
||||||
if (duration) {
|
|
||||||
duration = duration.replace(/:/g, '');
|
|
||||||
|
|
||||||
if (duration > 500) {
|
|
||||||
video.pause();
|
|
||||||
video.unpipe();
|
|
||||||
loadingmsg.delete();
|
|
||||||
return message.channel.send('Can\'t download video longer than 5 minutes');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
console.log(output.join('\n'));
|
||||||
|
|
||||||
console.log('Download started');
|
let file = fs.statSync(`${os.tmpdir()}/${fileName}.mp4`);
|
||||||
console.log('filename: ' + info._filename);
|
let fileSize = file.size / 1000000.0;
|
||||||
console.log('size: ' + info.size);
|
|
||||||
|
|
||||||
|
console.log(fileSize);
|
||||||
|
|
||||||
if (info.size >= 8000000) {
|
//Compress vid if bigger than 8MB
|
||||||
needCompress = true;
|
if (fileSize > 8) {
|
||||||
}
|
console.log('file bigger than 8MB');
|
||||||
});
|
let compressmsg = await message.channel.send('Video bigger than 8MB compressing now <a:loadingmin:527579785212329984> (This can take a long time!)\nWant it to go faster? Donate to the dev with the donate command, so i can get a better server and do it faster!');
|
||||||
video.on('end', async function () {
|
loadingmsg.delete();
|
||||||
if (!needCompress) {
|
|
||||||
|
const options = {
|
||||||
|
input: `${os.tmpdir()}/${fileName}.mp4`,
|
||||||
|
output: `${os.tmpdir()}/${fileName}compressed.mp4`,
|
||||||
|
preset: 'General/Gmail Small 10 Minutes 288p30'
|
||||||
|
};
|
||||||
|
|
||||||
|
let handbrake = hbjs.spawn(options);
|
||||||
|
handbrake.on('error', err => {
|
||||||
|
console.error(err);
|
||||||
|
compressmsg.delete();
|
||||||
|
return message.channel.send('An error has occured while compressing the video');
|
||||||
|
});
|
||||||
|
handbrake.on('progress', progress => {
|
||||||
|
console.log(
|
||||||
|
'Percent complete: %s, ETA: %s',
|
||||||
|
progress.percentComplete,
|
||||||
|
progress.eta
|
||||||
|
);
|
||||||
|
});
|
||||||
|
handbrake.on('end', async function () {
|
||||||
|
message.delete();
|
||||||
|
compressmsg.delete();
|
||||||
|
return message.channel.send(`Downloaded by ${message.author.username}`, { files: [`${os.tmpdir()}/${fileName}compressed.mp4`] })
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
compressmsg.delete();
|
||||||
|
return message.channel.send('File too big');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log('file smaller than 8MB');
|
||||||
message.delete();
|
message.delete();
|
||||||
loadingmsg.delete();
|
loadingmsg.delete();
|
||||||
return message.channel.send(`Downloaded by ${message.author.username}`, { files: [`${os.tmpdir()}/${fileName}.mp4`] })
|
return message.channel.send(`Downloaded by ${message.author.username}`, { files: [`${os.tmpdir()}/${fileName}.mp4`] })
|
||||||
|
@ -114,44 +109,9 @@ class DownloadCommand extends Command {
|
||||||
return message.channel.send('File too big');
|
return message.channel.send('File too big');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let compressmsg = await message.channel.send('Video bigger than 8MB compressing now <a:loadingmin:527579785212329984> (This can take a long time!)\nWant it to go faster? Donate to the dev with the donate command, so i can get a better server and do it faster!');
|
|
||||||
loadingmsg.delete();
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
input: `${os.tmpdir()}/${fileName}.mp4`,
|
|
||||||
output: `${os.tmpdir()}/${fileName}compressed.mp4`,
|
|
||||||
preset: 'General/Gmail Small 10 Minutes 288p30'
|
|
||||||
};
|
|
||||||
|
|
||||||
//Compress vid if bigger than 8MB
|
|
||||||
let handbrake = hbjs.spawn(options);
|
|
||||||
handbrake.on('error', err => {
|
|
||||||
console.error(err);
|
|
||||||
compressmsg.delete();
|
|
||||||
return message.channel.send('An error has occured while compressing the video');
|
|
||||||
});
|
|
||||||
handbrake.on('progress', progress => {
|
|
||||||
console.log(
|
|
||||||
'Percent complete: %s, ETA: %s',
|
|
||||||
progress.percentComplete,
|
|
||||||
progress.eta
|
|
||||||
);
|
|
||||||
});
|
|
||||||
handbrake.on('end', async function () {
|
|
||||||
message.delete();
|
|
||||||
compressmsg.delete();
|
|
||||||
return message.channel.send(`Downloaded by ${message.author.username}`, { files: [`${os.tmpdir()}/${fileName}compressed.mp4`] })
|
|
||||||
.catch(err => {
|
|
||||||
console.error(err);
|
|
||||||
compressmsg.delete();
|
|
||||||
return message.channel.send('File too big');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
return message.channel.send('You need to input a valid link');
|
|
||||||
}
|
}
|
||||||
|
return message.channel.send('You need to input a valid link');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue