diff --git a/api/lotus.ts b/api/lotus.ts index 7161aae..ca27bfd 100644 --- a/api/lotus.ts +++ b/api/lotus.ts @@ -21,20 +21,15 @@ const lotus = { }; export function normaliseArtistMetadata(rawArtist: string) { - const removeUnwantedTokens = (raw: string | string[], regex: RegExp) => - typeof raw === 'string' ? raw.split(regex) : raw.join(" ").split(regex) - .map((s) => s.trim()) - .filter(Boolean) - .filter((s) => !s.match(regex)) - - const featTokens = /\s(&|feat\.?|ft\.?)\s/i; - const commaTokens = /(、|,\s)/i; - - const base = [featTokens, commaTokens].reduce((acc, regex) => { - return acc.flatMap((s) => removeUnwantedTokens(s, regex)); - }, [rawArtist]); - - let artist = base.join(";"); + const removeUnwantedTokens = (raw: string, regex: RegExp): string => + raw.split(regex) + .map((s) => s.trim()) + .filter(Boolean) + .join(";"); + + const separators = /\s(?:&|feat\.?|ft\.?)\s|[\u3001]|\s*,\s*/i; + let artist = removeUnwantedTokens(rawArtist, separators); + for (const [key, transform] of Object.entries(combinedArtists)) { if (artist.toLowerCase().includes(key.toLowerCase())) { const pattern = new RegExp(key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "gi"); diff --git a/commands/tidy.ts b/commands/tidy.ts index d986e5c..56ce79f 100644 --- a/commands/tidy.ts +++ b/commands/tidy.ts @@ -23,9 +23,9 @@ export async function executeTidyCommand(args: string[]): Promise deleteScrobble(browser, { artist: track.artist, diff --git a/readme.md b/readme.md index 5500d55..a1042a8 100644 --- a/readme.md +++ b/readme.md @@ -17,7 +17,7 @@ a minimal CLI toolkit for working with [last.fm] scrobbles - [x] command-line commands - [x] individual track scrobbling - [ ] multiple album loop scrobbling -- [x] scrobble correction +- [x] scrobble correction - [x] using [lotus] - [ ] using [musicbrainz] api - [x] export filtering (date ranges, artist/album filters)