From 133538dbe9a33d59a31feca7519f43a1989d387a Mon Sep 17 00:00:00 2001 From: loicbersier Date: Sun, 3 May 2020 19:23:54 +0200 Subject: [PATCH] Use --rm-cache-dir when downloading a video --- commands/fun/ytp.js | 6 +++--- commands/utility/download.js | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/commands/fun/ytp.js b/commands/fun/ytp.js index c0675e1e..fa60e3c2 100644 --- a/commands/fun/ytp.js +++ b/commands/fun/ytp.js @@ -3,6 +3,8 @@ const YTPGenerator = require('ytpplus-node'); const os = require('os'); const fs = require('fs'); const youtubedl = require('youtube-dl'); +const MAX_CLIPS = 20; + class ytpCommand extends Command { constructor() { @@ -100,8 +102,6 @@ class ytpCommand extends Command { } async exec(message, args) { - let MAX_CLIPS = 20; - if (args.pool) { let mp4 = []; fs.readdirSync('./asset/ytp/userVid/').forEach(file => { @@ -123,7 +123,7 @@ class ytpCommand extends Command { } if (url) { - return youtubedl.exec(url, ['--no-playlist','--max-filesize', '50m', '--format=mp4', '-o', `./asset/ytp/userVid/${message.id}.mp4`], {}, function(err, output) { + return youtubedl.exec(url, ['--rm-cache-dir', '--no-playlist', '--max-filesize', '50m', '--format=mp4', '-o', `./asset/ytp/userVid/${message.id}.mp4`], {}, function(err, output) { console.log(output); if (err) { console.error(err); diff --git a/commands/utility/download.js b/commands/utility/download.js index 7c7cf465..56a365d8 100644 --- a/commands/utility/download.js +++ b/commands/utility/download.js @@ -69,10 +69,10 @@ class DownloadCommand extends Command { if (fs.existsSync(`${os.tmpdir()}/${fileName}`)) { fs.unlink(`${os.tmpdir()}/${fileName}`, (err) => { - if (err); + if (err) console.error(err); }); } - return youtubedl.exec(link, ['-o', `${os.tmpdir()}/${fileName}`], {}, async function(err) { + return youtubedl.exec(link, ['--rm-cache-dir', '-o', `${os.tmpdir()}/${fileName}`], {}, async function(err) { if (err) { console.error(err); loadingmsg.delete(); @@ -84,7 +84,7 @@ class DownloadCommand extends Command { if (fs.existsSync(`${os.tmpdir()}/${fileName}`)) { ext = await filetype.fromFile(`${os.tmpdir()}/${fileName}`); ext = ext.ext; // This look stupid but hey, it work - if (ext == '3gp') ext = 'mp4'; // Change 3gp file extension to mp4 so discord show the video ( and to stop people from complaining ) + if (ext === '3gp') ext = 'mp4'; // Change 3gp file extension to mp4 so discord show the video ( and to stop people from complaining ) fs.renameSync(`${os.tmpdir()}/${fileName}`, `${os.tmpdir()}/${fileName}.${ext}`); } else if (fs.existsSync(`${os.tmpdir()}/${fileName}.mkv`)) { // If it can't find the video assume it got merged and end with mkv fs.renameSync(`${os.tmpdir()}/${fileName}.mkv`, `${os.tmpdir()}/${fileName}.mp4`); // Discord play mkv just fine but it need to end with mp4 @@ -125,7 +125,7 @@ class DownloadCommand extends Command { // Every 5 seconds update the compress message with the % let editmsg = setInterval(() => { - compressEmbed.setDescription(`Ready in ${eta == '' ? 'soon enough' : eta}. ${percentComplete}% complete.`); + compressEmbed.setDescription(`Ready in ${eta === '' ? 'soon enough' : eta}. ${percentComplete}% complete.`); compressmsg.edit(compressEmbed); }, 5000);