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;
});
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();
});