aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Media/Anime
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Media/Anime')
-rw-r--r--src/lib/Media/Anime/Airing/Subtitled/match.ts52
1 files changed, 28 insertions, 24 deletions
diff --git a/src/lib/Media/Anime/Airing/Subtitled/match.ts b/src/lib/Media/Anime/Airing/Subtitled/match.ts
index 56df053f..cb73a1e3 100644
--- a/src/lib/Media/Anime/Airing/Subtitled/match.ts
+++ b/src/lib/Media/Anime/Airing/Subtitled/match.ts
@@ -57,30 +57,38 @@ const calculateWeightedSimilarity = (title1: string, title2: string): number =>
return score / (Math.max(tokens1.length, tokens2.length) * 2);
};
-export const findClosestMatch = (times: Time[], titles: string[]): Time | null => {
- if (titles.some((title) => excludeMatch.includes(title))) return null;
+export const findClosestMatch = (times: Time[], anime: Media): Time | null => {
+ if (excludeMatch.includes(anime.id)) return null;
let bestMatch: Time | null = null;
let bestScore = 0;
- titles.filter(Boolean).forEach((searchTitle) => {
- if (searchTitle.includes('OVA') || searchTitle.includes('Special')) return;
-
- const normalizedSearchTitle = preprocessTitle(searchTitle);
-
- times.forEach((time) => {
- const normalizedTimeTitle = preprocessTitle(time.title);
- const similarityScore = calculateWeightedSimilarity(
- normalizedSearchTitle,
- normalizedTimeTitle
- );
-
- if (similarityScore > bestScore) {
- bestScore = similarityScore;
- bestMatch = time;
- }
+ [anime.title.romaji, anime.title.english, ...anime.synonyms]
+ .filter(Boolean)
+ .forEach((searchTitle) => {
+ if (searchTitle.includes('OVA') || searchTitle.includes('Special')) return;
+
+ const normalizedSearchTitle = preprocessTitle(searchTitle);
+
+ times.forEach((time) => {
+ const normalizedTimeTitle = preprocessTitle(time.title);
+ const similarityScore = calculateWeightedSimilarity(
+ normalizedSearchTitle,
+ normalizedTimeTitle
+ );
+
+ if (
+ similarityScore > bestScore &&
+ time.day ===
+ new Date((anime.nextAiringEpisode?.airingAt || 0) * 1000).toLocaleString('en-US', {
+ weekday: 'long'
+ })
+ ) {
+ bestScore = similarityScore;
+ bestMatch = time;
+ }
+ });
});
- });
return bestMatch;
};
@@ -163,11 +171,7 @@ export const injectAiringTime = (anime: Media, subsPlease: SubsPlease | null) =>
}
if ((anime.nextAiringEpisode?.episode || 0) > 1) {
- const foundTime: Time | null = findClosestMatch(times, [
- anime.title.romaji,
- anime.title.english,
- ...anime.synonyms
- ]);
+ const foundTime: Time | null = findClosestMatch(times, anime);
if (foundTime) {
untilAiring = secondsUntil((foundTime as Time).time, (foundTime as Time).day);