aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-04-15 01:56:41 -0700
committerFuwn <[email protected]>2024-04-15 01:56:41 -0700
commit982320b52c4b79df9f0c8e5999cfcc47953b2e97 (patch)
treeb0af09af081ea6b965c59a4babd4fa67d6720757 /src/lib
parentfix(popup): popup blocks scroll on hidde mount (diff)
downloaddue.moe-982320b52c4b79df9f0c8e5999cfcc47953b2e97.tar.xz
due.moe-982320b52c4b79df9f0c8e5999cfcc47953b2e97.zip
feat(match): compare day of release
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Data/Static/matchExclude.json5
-rw-r--r--src/lib/Media/Anime/Airing/Subtitled/match.ts52
2 files changed, 29 insertions, 28 deletions
diff --git a/src/lib/Data/Static/matchExclude.json b/src/lib/Data/Static/matchExclude.json
index d35887d4..111bb868 100644
--- a/src/lib/Data/Static/matchExclude.json
+++ b/src/lib/Data/Static/matchExclude.json
@@ -1,4 +1 @@
-[
- "Meitou \"Isekai no Yu\" Kaitaku-ki: AraFou Onsen Mania Tensei-saki wa, Nonbiri Onsen Tengoku Deshita",
- "Sai-Kyo-Oh! Zukan: The Ultimate Battles"
-]
+[0]
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);