This commit is contained in:
notgne2 2021-01-27 00:37:19 -07:00
parent a34af57de3
commit cdcaf0e708
No known key found for this signature in database
GPG Key ID: BB661E172B42A7F8

View File

@ -31,7 +31,7 @@ async function thing() {
return item ? item.trim() : item; return item ? item.trim() : item;
}); });
const dir = await fs.mkdir(TMP_DIR); await fs.mkdir(TMP_DIR);
let files = []; let files = [];
let inputType = null; let inputType = null;
@ -49,11 +49,11 @@ async function thing() {
console.log('got a link'); console.log('got a link');
inputType = 'url'; inputType = 'url';
console.log(`Temporarily saving to ${dir.path}`); console.log(`Temporarily saving to ${TMP_DIR}`);
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]}`); 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'); console.log('Done saving');
const filesList = await fs.readdir(dir.path); const filesList = await fs.readdir(TMP_DIR);
files = filesList.map((rawFilePath) => { files = filesList.map((rawFilePath) => {
const filePath = Path.parse(rawFilePath); const filePath = Path.parse(rawFilePath);
@ -102,8 +102,8 @@ async function thing() {
if (title === null) title = 'Unknown'; if (title === null) title = 'Unknown';
return { return {
file: Path.join(dir.path, rawFilePath), file: Path.join(TMP_DIR, rawFilePath),
image: Path.join(dir.path, rawImagePath), image: Path.join(TMP_DIR, rawImagePath),
album, album,
artist, artist,
title, title,
@ -169,3 +169,8 @@ async function thing() {
await fs.rmdir(TMP_DIR, { recursive: true }); await fs.rmdir(TMP_DIR, { recursive: true });
} }
})(); })();
process.on('SIGINT', async () => {
await fs.rmdir(TMP_DIR, { recursive: true });
process.exit();
});