make the loading message always show

merge-requests/4/head
loicbersier 5 years ago
parent 5e18aa5d67
commit d7baadc512

@ -49,6 +49,8 @@ class DownloadCommand extends Command {
}
if (link.includes('http') || link.includes('www')) {
let loadingmsg = await message.channel.send('Downloading <a:loadingmin:527579785212329984>');
if (args.alt) {
console.log('alt download!');
if (fs.existsSync(`${os.tmpdir()}/${fileName}.mp4`)) {
@ -56,13 +58,15 @@ class DownloadCommand extends Command {
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;
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');
});
});
@ -71,18 +75,13 @@ class DownloadCommand extends Command {
let video = youtubedl(link);
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);
loadingmsg.delete();
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('end', function () {
msg.delete();
});
});
video.on('info', function(info) {
video.on('info', async function(info) {
let duration = info.duration;
if (duration) {
duration = duration.replace(/:/g, '');
@ -90,6 +89,7 @@ class DownloadCommand extends Command {
if (duration > 500) {
video.pause();
video.unpipe();
loadingmsg.delete();
return message.channel.send('Can\'t download video longer than 5 minutes');
}
}
@ -103,16 +103,20 @@ class DownloadCommand extends Command {
needCompress = true;
}
});
video.on('end', function () {
video.on('end', async function () {
if (!needCompress) {
message.delete();
loadingmsg.delete();
return 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');
});
}
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 = {
input: `${os.tmpdir()}/${fileName}.mp4`,
output: `${os.tmpdir()}/${fileName}compressed.mp4`,
@ -121,15 +125,10 @@ class DownloadCommand extends Command {
//Compress vid if bigger than 8MB
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 => {
console.error(err);
loadingmsg.delete();
compressmsg.delete();
return message.channel.send('An error has occured while compressing the video');
});
handbrake.on('progress', progress => {
@ -139,11 +138,15 @@ class DownloadCommand extends Command {
progress.eta
);
});
handbrake.on('end', function () {
handbrake.on('end', async function () {
message.delete();
loadingmsg.delete();
compressmsg.delete();
return message.channel.send(`Downloaded by ${message.author.username}`, { files: [`${os.tmpdir()}/${fileName}compressed.mp4`] })
.catch(err => {
console.error(err);
loadingmsg.delete();
compressmsg.delete();
return message.channel.send('File too big');
});
});

Loading…
Cancel
Save