From 57c5d5a0a5be4c9dd171bc35bfc92ecfb87463cf Mon Sep 17 00:00:00 2001 From: loicbersier Date: Sun, 10 Nov 2019 22:37:02 +0100 Subject: [PATCH] Show % when compressing --- commands/utility/download.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/commands/utility/download.js b/commands/utility/download.js index 13b41f7a..a1a8ce31 100644 --- a/commands/utility/download.js +++ b/commands/utility/download.js @@ -96,17 +96,33 @@ class DownloadCommand extends Command { compressmsg.delete(); return message.channel.send('An error has occured while compressing the video'); }); + + + let percentComplete; + let eta; + handbrake.on('progress', progress => { - console.log( - 'Percent complete: %s, ETA: %s', - progress.percentComplete, - progress.eta - ); + percentComplete = progress.percentComplete; + eta = progress.eta; + console.log(`Percent complete: ${progress.percentComplete}, ETA: ${progress.eta}`); }); + + // Every 5 seconds update the compress message with the % + setInterval(() => { + compressmsg.edit(`Compression status: Percent complete: ${percentComplete}, ETA: ${eta}\nWant it to go faster? Donate to the dev with the donate command, so i can get a better server and do it faster!`); + }, 5000); + handbrake.on('end', async function () { + file = fs.statSync(`${os.tmpdir()}/${fileName}compressed.mp4`); + fileSize = file.size / 1000000.0; + message.delete(); compressmsg.delete(); + if (fileSize > 8) { + return message.channel.send('File too big!'); + } + return message.channel.send({embed: Embed, files: [`${os.tmpdir()}/${fileName}compressed.mp4`]}) .catch(err => { console.error(err);