diff options
Diffstat (limited to 'src/lib/Media')
| -rw-r--r-- | src/lib/Media/Anime/Airing/animeSchedule.ts | 36 | ||||
| -rw-r--r-- | src/lib/Media/Anime/Airing/classify.test.ts | 2 |
2 files changed, 27 insertions, 11 deletions
diff --git a/src/lib/Media/Anime/Airing/animeSchedule.ts b/src/lib/Media/Anime/Airing/animeSchedule.ts index f3f6f85d..7bfe5ac3 100644 --- a/src/lib/Media/Anime/Airing/animeSchedule.ts +++ b/src/lib/Media/Anime/Airing/animeSchedule.ts @@ -1,9 +1,11 @@ // Data model for AnimeSchedule.net's weekly timetable, the source of truth for -// when subbed and dubbed episodes actually release. Unlike a fansub schedule, -// every release carries an absolute timestamp, an episode number, delay windows, -// and the streaming platforms it lands on. +// when native, subbed, and dubbed episodes actually release. Unlike a fansub +// schedule, every release carries an absolute timestamp, an episode number, +// delay windows, and the streaming platforms it lands on. -export type AirType = "sub" | "dub"; +// A release track. "native" is AnimeSchedule's "raw" (original-language) +// broadcast; "sub"/"dub" are the localised releases. +export type AirType = "native" | "sub" | "dub"; export interface Stream { platform: string; @@ -25,9 +27,10 @@ export interface AiringEntry { streams: Stream[]; } -// The merged sub + dub schedule for the current week. +// The merged native + sub + dub schedule for the current week. export interface AiringSchedule { generatedAt: number; + native: AiringEntry[]; sub: AiringEntry[]; dub: AiringEntry[]; } @@ -91,12 +94,19 @@ export const parseTimetable = (raw: unknown): AiringEntry[] => { const TIMETABLE_ENDPOINT = "https://animeschedule.net/api/v3/timetables"; -// Fetch and parse the current week's sub and dub timetables in one shot. The -// caller supplies the AnimeSchedule application token. +// Fetch and parse the current week's native, sub, and dub timetables in one +// shot. The caller supplies the AnimeSchedule application token. AnimeSchedule +// names the native broadcast "raw". export const fetchTimetables = async ( token: string, -): Promise<{ sub: AiringEntry[]; dub: AiringEntry[] }> => { - const fetchOne = async (airType: AirType): Promise<AiringEntry[]> => { +): Promise<{ + native: AiringEntry[]; + sub: AiringEntry[]; + dub: AiringEntry[]; +}> => { + const fetchOne = async ( + airType: "raw" | "sub" | "dub", + ): Promise<AiringEntry[]> => { try { const response = await fetch(`${TIMETABLE_ENDPOINT}?airType=${airType}`, { headers: { Authorization: `Bearer ${token}` }, @@ -108,7 +118,11 @@ export const fetchTimetables = async ( } }; - const [sub, dub] = await Promise.all([fetchOne("sub"), fetchOne("dub")]); + const [native, sub, dub] = await Promise.all([ + fetchOne("raw"), + fetchOne("sub"), + fetchOne("dub"), + ]); - return { sub, dub }; + return { native, sub, dub }; }; diff --git a/src/lib/Media/Anime/Airing/classify.test.ts b/src/lib/Media/Anime/Airing/classify.test.ts index 1019b303..eeff2036 100644 --- a/src/lib/Media/Anime/Airing/classify.test.ts +++ b/src/lib/Media/Anime/Airing/classify.test.ts @@ -16,6 +16,7 @@ import settings from "$stores/settings"; // sub at `airingAt`. const subScheduleFor = (media: Media, airingAt: number): AiringSchedule => ({ generatedAt: Math.floor(Date.now() / 1000), + native: [], sub: [ { route: `fixture-${media.id}`, @@ -196,6 +197,7 @@ describe("countdown source fallback", () => { const schedule: AiringSchedule = { generatedAt: Math.floor(Date.now() / 1000), + native: [], sub: [], dub: [], }; |