Use --rm-cache-dir when downloading a video

This commit is contained in:
loicbersier 2020-05-03 19:23:54 +02:00
parent 72d474f06a
commit 133538dbe9
2 changed files with 7 additions and 7 deletions

View file

@ -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);

View file

@ -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);