Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/use-card-shared-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export function useCardSharedState({
inCinema,
rerun,
newBadge: !inCinema && !rerun ? deriveBadge(meta) : null,
hasDub: settings.showDubBadge && isAnime && dubReady && animeHasDub(meta.id),
hasDub:
settings.showDubBadge &&
isAnime &&
dubReady &&
animeHasDub(meta.id.startsWith("kitsu:") ? meta.malId : meta.id),
watched,
inWatchlist,
inLocalLibrary,
Expand Down
35 changes: 14 additions & 21 deletions src/lib/providers/anime-dub-sub.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
import { safeFetch } from "@/lib/safe-fetch";

const FEED_URL =
"https://raw.githubusercontent.com/RockinChaos/AniSchedule/master/raw/dub-schedule.json";
"https://raw.githubusercontent.com/RockinChaos/AniSchedule/master/raw/v2/dub-schedule.json";

let byMal: Set<number> | null = null;
let byAnilist: Set<number> | null = null;
let inflight: Promise<void> | null = null;
const subs = new Set<() => void>();

export type DubFeedEntry = {
title?: string | null;
romaji?: string | null;
english?: string | null;
episodeDate?: string | null;
episodeNumber?: number | null;
media?: {
media?: {
id?: number | null;
idMal?: number | null;
type?: string | null;
format?: string | null;
isAdult?: boolean | null;
title?: { romaji?: string | null; english?: string | null } | null;
coverImage?: { extraLarge?: string | null; medium?: string | null } | null;
bannerImage?: string | null;
} | null;
} | null;
id?: number | null;
idMal?: number | null;
format?: string | null;
isAdult?: boolean | null;
title?: { romaji?: string | null; english?: string | null; native?: string | null } | string | null;
coverImage?: { extraLarge?: string | null; medium?: string | null; color?: string | null } | null;
bannerImage?: string | null;
airingSchedule?: { nodes?: Array<{ episode?: number | null; airingAt?: number | string | null }> | null } | null;
};

let feedCache: { entries: DubFeedEntry[]; at: number } | null = null;
Expand Down Expand Up @@ -55,8 +46,8 @@ function load(): Promise<void> {
const mal = new Set<number>();
const ani = new Set<number>();
for (const e of arr) {
const m = e?.media?.media?.idMal;
const a = e?.media?.media?.id;
const m = e?.idMal;
const a = e?.id;
if (typeof m === "number") mal.add(m);
if (typeof a === "number") ani.add(a);
}
Expand Down Expand Up @@ -87,8 +78,10 @@ export function subscribeDubSet(fn: () => void): () => void {
};
}

export function animeHasDub(metaId: string): boolean {
export function animeHasDub(metaId: string | number | undefined): boolean {
if (!byMal) return false;
if (typeof metaId === "number") return Number.isFinite(metaId) && byMal.has(metaId);
if (metaId == null) return false;
if (metaId.startsWith("mal:")) {
const m = Number(metaId.slice(4));
if (Number.isFinite(m) && byMal.has(m)) return true;
Expand Down
Loading