From 66a5cb35d39a48a9b5b2490fcdd6bd840557f1a5 Mon Sep 17 00:00:00 2001 From: Inrixia Date: Mon, 7 Oct 2024 12:42:21 +1300 Subject: [PATCH] lib.makeTags - Handle cases where musicBrainz title is in another language --- plugins/_lib/makeTags.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/_lib/makeTags.ts b/plugins/_lib/makeTags.ts index 35461b1..ffad293 100644 --- a/plugins/_lib/makeTags.ts +++ b/plugins/_lib/makeTags.ts @@ -13,12 +13,22 @@ const sanitizeDisambiguation = (d?: string | null): string | false => { return d; }; +const englishCharRegex = /[a-zA-Z]/; +const hasEnglish = (str?: string) => !!str && /[a-zA-Z]/.test(str); + export const fullTitle = (tidal?: { title?: string; version?: string }, musicBrainz?: { title?: string; disambiguation?: string }) => { - let title = musicBrainz?.title ?? tidal?.title; + const brainzTitle = musicBrainz?.title; + const tidalTitle = tidal?.title; + + let title = brainzTitle ?? tidalTitle; + + // If the musicBrainz title is missing "feat .", use the tidal title. + const mbMissingFeat = tidalTitle?.includes("feat. ") && !brainzTitle?.includes("feat. "); - // If the musicBrainz title is missing "feat ." use the tidal title. - if (tidal?.title?.includes("feat. ") && !musicBrainz?.title?.includes("feat. ")) title = tidal?.title; + // If the musicBrainz title is in another language and the tidal one isnt, use the tidal title. + const mbInAnotherLanguage = !hasEnglish(brainzTitle) && hasEnglish(tidalTitle); + if (mbMissingFeat || mbInAnotherLanguage) title = tidalTitle; if (title === undefined) return undefined; const disambiguation = sanitizeDisambiguation(musicBrainz?.disambiguation ?? tidal?.version);