From de8c0a08804f758c19c45ee5010bbf4fad954d01 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Thu, 28 Mar 2024 11:17:59 +0200 Subject: [PATCH] Fixed deduplication issues --- src/client/components/MusicLibrary.ts | 13 ++++++++++++- src/client/components/downloaders/Spotify.ts | 8 ++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/client/components/MusicLibrary.ts b/src/client/components/MusicLibrary.ts index 86a1d1f..d8d1227 100644 --- a/src/client/components/MusicLibrary.ts +++ b/src/client/components/MusicLibrary.ts @@ -197,7 +197,18 @@ class MusicLibrary implements Initialisable } // Expensive call - const metadata = await parseFile(fp, { skipCovers: true }); + let metadata = null; + try + { + metadata = await parseFile(fp, { skipCovers: true }); + } + catch (err) + { + const error = err as Error; + if (!error.message.includes('MIME-type')) + this.#logger.error(error); + return; + } const { common } = metadata; // Fall back to file and folder name if artist or title not available const segmets = fp.replace(this.#path, '').split(path.sep); diff --git a/src/client/components/downloaders/Spotify.ts b/src/client/components/downloaders/Spotify.ts index 25f68f0..edc6a45 100644 --- a/src/client/components/downloaders/Spotify.ts +++ b/src/client/components/downloaders/Spotify.ts @@ -71,6 +71,10 @@ class SpotifyDownloader extends Downloader if (!this.downloadDir) throw new Error('No download directory defined'); + const songIds = path.join(this.downloadDir!, '.song_ids'); + if (!fs.existsSync(songIds)) + fs.writeFileSync(songIds, ''); + const match = url.match(/spotify\.com\/track\/(\w+)/u); if (!match) throw new MusicPlayerError('The bot will only process track URLs'); @@ -177,7 +181,7 @@ class SpotifyDownloader extends Downloader if (!line) return null; - const elements = line.split('\t'); + const elements = line.split('\t').map(str => str.trim()); const fileName = elements[elements.length - 1]; return this.#parseFilename(fileName); } @@ -185,7 +189,7 @@ class SpotifyDownloader extends Downloader #parseFilename (fileName: string) { const [ name, ext ] = fileName.split('.'); - const [ artist, song, album ] = name.split('---'); + const [ artist, song, album ] = name.split('---').map(str => str.trim()); return { fileName, artist,