From 75791f5428e73bc823ddd2eecbdf565b960119d6 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Wed, 20 Dec 2023 03:01:45 -0800 Subject: feat(airing): strengthen subsplease matcher --- src/lib/Media/Anime/airing.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/lib/Media/Anime') diff --git a/src/lib/Media/Anime/airing.ts b/src/lib/Media/Anime/airing.ts index 9c13fb5d..4029b644 100644 --- a/src/lib/Media/Anime/airing.ts +++ b/src/lib/Media/Anime/airing.ts @@ -39,11 +39,13 @@ const secondsUntil = (targetTime: string, targetDay: string) => { return secondsDifference > 0 ? secondsDifference : secondsDifference + 7 * 24 * 60 * 60; }; -const normalizeTitle = (title: string) => - (title || '') +const normalizeTitle = (title: string | null) => { + return (title || '') .toLowerCase() - .replace(/season \d+|s\d+/g, '') + .replace(/season \d+|s\d+|\W/g, '') + .replace(/\b(\d)(st|nd|rd|th)\b/g, '$1') .trim(); +}; const findClosestMatch = (times: Time[], titles: string[]) => { let closestMatch: Time | null = null; @@ -56,7 +58,10 @@ const findClosestMatch = (times: Time[], titles: string[]) => { const normalizedItemTitle = normalizeTitle(item.title); const distance = levenshtein.get(normalizedAnimeTitle, normalizedItemTitle); - if (distance < smallestDistance && distance < normalizedAnimeTitle.length / 2) { + if ( + distance < smallestDistance && + distance < Math.max(3, normalizedAnimeTitle.length * 0.4) + ) { smallestDistance = distance; closestMatch = item; } -- cgit v1.2.3