diff options
| author | Fuwn <[email protected]> | 2023-12-20 03:01:45 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-12-20 03:01:45 -0800 |
| commit | 75791f5428e73bc823ddd2eecbdf565b960119d6 (patch) | |
| tree | 3c8723dc1e8c8dfc052b514ed0c52f88e5ba3272 /src/lib | |
| parent | feat(schedule): display episode (diff) | |
| download | due.moe-75791f5428e73bc823ddd2eecbdf565b960119d6.tar.xz due.moe-75791f5428e73bc823ddd2eecbdf565b960119d6.zip | |
feat(airing): strengthen subsplease matcher
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/Media/Anime/airing.ts | 13 |
1 files changed, 9 insertions, 4 deletions
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; } |