From cdcaf0e708b4c37a5e2a597f195e7784905fee04 Mon Sep 17 00:00:00 2001 From: notgne2 Date: Wed, 27 Jan 2021 00:37:19 -0700 Subject: [PATCH] ok idc --- index.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index e0ab108..3847170 100644 --- a/index.js +++ b/index.js @@ -31,7 +31,7 @@ async function thing() { return item ? item.trim() : item; }); - const dir = await fs.mkdir(TMP_DIR); + await fs.mkdir(TMP_DIR); let files = []; let inputType = null; @@ -49,11 +49,11 @@ async function thing() { console.log('got a link'); inputType = 'url'; - console.log(`Temporarily saving to ${dir.path}`); - await exec(`youtube-dl --write-thumbnail -f bestaudio -x -o "${dir.path}/[%(album)s] -- [%(artist)s] -- [%(track_number)s] -- [%(track)s] -- [%(title)s].%(ext)s" ${process.argv[2]}`); + console.log(`Temporarily saving to ${TMP_DIR}`); + await exec(`youtube-dl --write-thumbnail -f bestaudio -x -o "${TMP_DIR}/[%(album)s] -- [%(artist)s] -- [%(track_number)s] -- [%(track)s] -- [%(title)s].%(ext)s" ${process.argv[2]}`); console.log('Done saving'); - const filesList = await fs.readdir(dir.path); + const filesList = await fs.readdir(TMP_DIR); files = filesList.map((rawFilePath) => { const filePath = Path.parse(rawFilePath); @@ -102,8 +102,8 @@ async function thing() { if (title === null) title = 'Unknown'; return { - file: Path.join(dir.path, rawFilePath), - image: Path.join(dir.path, rawImagePath), + file: Path.join(TMP_DIR, rawFilePath), + image: Path.join(TMP_DIR, rawImagePath), album, artist, title, @@ -169,3 +169,8 @@ async function thing() { await fs.rmdir(TMP_DIR, { recursive: true }); } })(); + +process.on('SIGINT', async () => { + await fs.rmdir(TMP_DIR, { recursive: true }); + process.exit(); +}); \ No newline at end of file