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