aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Media/Anime
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-12-20 02:20:37 -0800
committerFuwn <[email protected]>2023-12-20 02:20:37 -0800
commita87fee111ccb501121b5aa3c1e48601f4869198a (patch)
treec1c55fc24a03bc7be848ee753ff76a76f397b4e2 /src/lib/Media/Anime
parentfeat(attributions): add more anilist details (diff)
downloaddue.moe-a87fee111ccb501121b5aa3c1e48601f4869198a.tar.xz
due.moe-a87fee111ccb501121b5aa3c1e48601f4869198a.zip
feat(schedule): match media to anilist
Diffstat (limited to 'src/lib/Media/Anime')
-rw-r--r--src/lib/Media/Anime/airing.ts24
-rw-r--r--src/lib/Media/Anime/season.ts11
2 files changed, 34 insertions, 1 deletions
diff --git a/src/lib/Media/Anime/airing.ts b/src/lib/Media/Anime/airing.ts
index 15abbf2a..9c13fb5d 100644
--- a/src/lib/Media/Anime/airing.ts
+++ b/src/lib/Media/Anime/airing.ts
@@ -6,7 +6,7 @@ import type { SubsPlease } from '$lib/subsPlease';
import levenshtein from 'fast-levenshtein';
import { totalEpisodes } from './episodes';
-interface Time {
+export interface Time {
title: string;
time: string;
day: string;
@@ -66,6 +66,28 @@ const findClosestMatch = (times: Time[], titles: string[]) => {
return closestMatch as Time | null;
};
+export const findClosestMedia = (media: Media[], matchFor: string) => {
+ if (!matchFor) return null;
+
+ let bestFitMedia: Media | null = null;
+ let smallestDistance = Infinity;
+
+ const normalizedSingleTitle = normalizeTitle(matchFor);
+
+ media.forEach((m) => {
+ [m.title.romaji, m.title.english, ...m.synonyms].filter(Boolean).forEach((title) => {
+ const distance = levenshtein.get(normalizedSingleTitle, normalizeTitle(title));
+
+ if (distance < smallestDistance && distance < normalizedSingleTitle.length / 2) {
+ smallestDistance = distance;
+ bestFitMedia = m;
+ }
+ });
+ });
+
+ return bestFitMedia as Media | null;
+};
+
export const injectAiringTime = (anime: Media, subsPlease: SubsPlease | null) => {
const airingAt = anime.nextAiringEpisode?.airingAt;
// const nativeUntilAiring = airingAt
diff --git a/src/lib/Media/Anime/season.ts b/src/lib/Media/Anime/season.ts
new file mode 100644
index 00000000..d7922e2b
--- /dev/null
+++ b/src/lib/Media/Anime/season.ts
@@ -0,0 +1,11 @@
+export const season = () => {
+ if (new Date().getMonth() >= 0 && new Date().getMonth() <= 2)
+ return 'WINTER' as 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL';
+ else if (new Date().getMonth() >= 3 && new Date().getMonth() <= 5)
+ return 'SPRING' as 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL';
+ else if (new Date().getMonth() >= 6 && new Date().getMonth() <= 8)
+ return 'SUMMER' as 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL';
+ else if (new Date().getMonth() >= 9 && new Date().getMonth() <= 11)
+ return 'FALL' as 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL';
+ else return 'WINTER' as 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL';
+};