forked from Supositware/Haha-Yes
make the loading message always show
This commit is contained in:
parent
5e18aa5d67
commit
d7baadc512
1 changed files with 21 additions and 18 deletions
|
@ -49,6 +49,8 @@ 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>');
|
||||||
|
|
||||||
if (args.alt) {
|
if (args.alt) {
|
||||||
console.log('alt download!');
|
console.log('alt download!');
|
||||||
if (fs.existsSync(`${os.tmpdir()}/${fileName}.mp4`)) {
|
if (fs.existsSync(`${os.tmpdir()}/${fileName}.mp4`)) {
|
||||||
|
@ -56,13 +58,15 @@ class DownloadCommand extends Command {
|
||||||
if (err);
|
if (err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return youtubedl.exec(args.link, ['-o', `${os.tmpdir()}/${fileName}.mp4`], {}, function(err, output) {
|
return youtubedl.exec(args.link, ['-o', `${os.tmpdir()}/${fileName}.mp4`], {}, async function(err, output) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log(output.join('\n'));
|
console.log(output.join('\n'));
|
||||||
message.delete();
|
message.delete();
|
||||||
|
loadingmsg.delete();
|
||||||
message.channel.send(`Downloaded by ${message.author.username}`, { files: [`${os.tmpdir()}/${fileName}.mp4`] })
|
message.channel.send(`Downloaded by ${message.author.username}`, { files: [`${os.tmpdir()}/${fileName}.mp4`] })
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
loadingmsg.delete();
|
||||||
return message.channel.send('File too big');
|
return message.channel.send('File too big');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -71,18 +75,13 @@ class DownloadCommand extends Command {
|
||||||
|
|
||||||
let video = youtubedl(link);
|
let video = youtubedl(link);
|
||||||
video.pipe(fs.createWriteStream(`${os.tmpdir()}/${fileName}.mp4`));
|
video.pipe(fs.createWriteStream(`${os.tmpdir()}/${fileName}.mp4`));
|
||||||
video.on('error', function error(err) {
|
video.on('error', async function error(err) {
|
||||||
console.log('error 2:', err);
|
console.log('error 2:', err);
|
||||||
|
loadingmsg.delete();
|
||||||
message.channel.send('An error has occured, I can\'t download from the link you provided.');
|
message.channel.send('An error has occured, I can\'t download from the link you provided.');
|
||||||
});
|
});
|
||||||
|
|
||||||
message.channel.send('Downloading <a:loadingmin:527579785212329984>').then(msg => {
|
video.on('info', async function(info) {
|
||||||
video.on('end', function () {
|
|
||||||
msg.delete();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
video.on('info', function(info) {
|
|
||||||
let duration = info.duration;
|
let duration = info.duration;
|
||||||
if (duration) {
|
if (duration) {
|
||||||
duration = duration.replace(/:/g, '');
|
duration = duration.replace(/:/g, '');
|
||||||
|
@ -90,6 +89,7 @@ class DownloadCommand extends Command {
|
||||||
if (duration > 500) {
|
if (duration > 500) {
|
||||||
video.pause();
|
video.pause();
|
||||||
video.unpipe();
|
video.unpipe();
|
||||||
|
loadingmsg.delete();
|
||||||
return message.channel.send('Can\'t download video longer than 5 minutes');
|
return message.channel.send('Can\'t download video longer than 5 minutes');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,16 +103,20 @@ class DownloadCommand extends Command {
|
||||||
needCompress = true;
|
needCompress = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
video.on('end', function () {
|
video.on('end', async function () {
|
||||||
if (!needCompress) {
|
if (!needCompress) {
|
||||||
message.delete();
|
message.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`] })
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
loadingmsg.delete();
|
||||||
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!');
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
input: `${os.tmpdir()}/${fileName}.mp4`,
|
input: `${os.tmpdir()}/${fileName}.mp4`,
|
||||||
output: `${os.tmpdir()}/${fileName}compressed.mp4`,
|
output: `${os.tmpdir()}/${fileName}compressed.mp4`,
|
||||||
|
@ -121,15 +125,10 @@ class DownloadCommand extends Command {
|
||||||
|
|
||||||
//Compress vid if bigger than 8MB
|
//Compress vid if bigger than 8MB
|
||||||
let handbrake = hbjs.spawn(options);
|
let handbrake = hbjs.spawn(options);
|
||||||
handbrake.on('start', function() {
|
|
||||||
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!').then(msg => {
|
|
||||||
handbrake.on('end', async function () {
|
|
||||||
await msg.delete();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
handbrake.on('error', err => {
|
handbrake.on('error', err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
loadingmsg.delete();
|
||||||
|
compressmsg.delete();
|
||||||
return message.channel.send('An error has occured while compressing the video');
|
return message.channel.send('An error has occured while compressing the video');
|
||||||
});
|
});
|
||||||
handbrake.on('progress', progress => {
|
handbrake.on('progress', progress => {
|
||||||
|
@ -139,11 +138,15 @@ class DownloadCommand extends Command {
|
||||||
progress.eta
|
progress.eta
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
handbrake.on('end', function () {
|
handbrake.on('end', async function () {
|
||||||
message.delete();
|
message.delete();
|
||||||
|
loadingmsg.delete();
|
||||||
|
compressmsg.delete();
|
||||||
return message.channel.send(`Downloaded by ${message.author.username}`, { files: [`${os.tmpdir()}/${fileName}compressed.mp4`] })
|
return message.channel.send(`Downloaded by ${message.author.username}`, { files: [`${os.tmpdir()}/${fileName}compressed.mp4`] })
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
loadingmsg.delete();
|
||||||
|
compressmsg.delete();
|
||||||
return message.channel.send('File too big');
|
return message.channel.send('File too big');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue