From 39408d758a2727cdcbdf9adcfab8c61ed56af142 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Fri, 13 Sep 2019 19:06:29 +0200 Subject: [PATCH] put the vid in tmp --- commands/utility/download.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/commands/utility/download.js b/commands/utility/download.js index 776bc64..227e947 100644 --- a/commands/utility/download.js +++ b/commands/utility/download.js @@ -2,6 +2,7 @@ const { Command } = require('discord-akairo'); const fs = require('fs'); const youtubedl = require('youtube-dl'); const hbjs = require('handbrake-js'); +const os = require('os'); class DownloadCommand extends Command { constructor() { @@ -42,24 +43,24 @@ class DownloadCommand extends Command { let fileName; if (args.spoiler) { - fileName = 'SPOILER_video'; + fileName = `SPOILER_${message.author.id}_video`; } else { - fileName = 'video'; + fileName = `${message.author.id}_video`; } if (link.includes('http') || link.includes('www')) { if (args.alt) { console.log('alt download!'); - if (fs.existsSync(`./${fileName}.mp4`)) { - fs.unlink(`./${fileName}.mp4`, (err) => { + if (fs.existsSync(`${os.tmpdir()}/${fileName}.mp4`)) { + fs.unlink(`${os.tmpdir()}/${fileName}.mp4`, (err) => { if (err); }); } - return youtubedl.exec(args.link, ['-o', `./${fileName}.mp4`], {}, function(err, output) { + return youtubedl.exec(args.link, ['-o', `${os.tmpdir()}/${fileName}.mp4`], {}, function(err, output) { if (err) throw err; console.log(output.join('\n')); message.delete(); - message.channel.send(`Downloaded by ${message.author.username}`, { files: [`./${fileName}.mp4`] }) + message.channel.send(`Downloaded by ${message.author.username}`, { files: [`${os.tmpdir()}/${fileName}.mp4`] }) .catch(err => { console.error(err); return message.channel.send('File too big'); @@ -69,7 +70,7 @@ class DownloadCommand extends Command { let video = youtubedl(link); - video.pipe(fs.createWriteStream(`./${fileName}.mp4`)); + video.pipe(fs.createWriteStream(`${os.tmpdir()}/${fileName}.mp4`)); video.on('error', function error(err) { console.log('error 2:', err); message.channel.send('An error has occured, I can\'t download from the link you provided.'); @@ -105,7 +106,7 @@ class DownloadCommand extends Command { video.on('end', function () { if (!needCompress) { message.delete(); - return message.channel.send(`Downloaded by ${message.author.username}`, { files: [`./${fileName}.mp4`] }) + return message.channel.send(`Downloaded by ${message.author.username}`, { files: [`${os.tmpdir()}/${fileName}.mp4`] }) .catch(err => { console.error(err); return message.channel.send('File too big'); @@ -140,7 +141,7 @@ class DownloadCommand extends Command { }); handbrake.on('end', function () { message.delete(); - return message.channel.send(`Downloaded by ${message.author.username}`, { files: [`./${fileName}Ready.mp4`] }) + return message.channel.send(`Downloaded by ${message.author.username}`, { files: [`${os.tmpdir()}/${fileName}Ready.mp4`] }) .catch(err => { console.error(err); return message.channel.send('File too big');