diff options
| author | Fuwn <[email protected]> | 2024-01-08 22:46:21 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-01-08 22:48:23 -0800 |
| commit | 1effa62e12ade886e5273d96b4d1d11d055aaf6b (patch) | |
| tree | bdfdaa698cc7371c9dd49f43cd7ec4e95fe1dc52 /src/lib/Media/Anime | |
| parent | feat(match): better schedule match algorithm (diff) | |
| download | due.moe-1effa62e12ade886e5273d96b4d1d11d055aaf6b.tar.xz due.moe-1effa62e12ade886e5273d96b4d1d11d055aaf6b.zip | |
feat(match): anime better match algorithm
Diffstat (limited to 'src/lib/Media/Anime')
| -rw-r--r-- | src/lib/Media/Anime/Airing/Subtitled/match.ts | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/lib/Media/Anime/Airing/Subtitled/match.ts b/src/lib/Media/Anime/Airing/Subtitled/match.ts index 1bf31b6f..74302353 100644 --- a/src/lib/Media/Anime/Airing/Subtitled/match.ts +++ b/src/lib/Media/Anime/Airing/Subtitled/match.ts @@ -2,7 +2,6 @@ import { get } from 'svelte/store'; import type { Media } from '../../../../AniList/media'; import settings from '$stores/settings'; import type { SubsPlease } from '$lib/Media/Anime/Airing/Subtitled/subsPlease'; -import levenshtein from 'fast-levenshtein'; import stringSimilarity from 'string-similarity'; export interface Time { @@ -42,21 +41,21 @@ const normalizeTitle = (title: string | null) => { const findClosestMatch = (times: Time[], titles: string[]) => { let closestMatch: Time | null = null; - let smallestDistance = Infinity; - titles.forEach((animeTitle) => { - const normalizedAnimeTitle = normalizeTitle(animeTitle); + titles.forEach((title) => { + const normalisedTitle = normalizeTitle(title); - times.forEach((item) => { - const normalizedItemTitle = normalizeTitle(item.title); - const distance = levenshtein.get(normalizedAnimeTitle, normalizedItemTitle); + times.forEach((time) => { + const normalisedTimeTitle = normalizeTitle(time.title); + const distance = stringSimilarity.compareTwoStrings(normalisedTitle, normalisedTimeTitle); if ( - distance < smallestDistance && - distance < Math.max(3, normalizedAnimeTitle.length * 0.4) + distance > 0.5 && + (closestMatch === null || + distance > + stringSimilarity.compareTwoStrings(normalisedTitle, normalizeTitle(closestMatch.title))) ) { - smallestDistance = distance; - closestMatch = item; + closestMatch = time; } }); }); |