Update useSkipTime.ts

This commit is contained in:
Pas 2026-01-02 12:38:52 -07:00
parent 26c1043eb2
commit 649550db85

View file

@ -9,6 +9,7 @@ import { getTurnstileToken } from "@/utils/turnstile";
// Thanks Nemo for this API
const FED_SKIPS_BASE_URL = "https://fed-skips.pstream.mov";
// const VELORA_BASE_URL = "https://veloratv.ru/api/intro-end/confirmed";
const INTRODB_BASE_URL = "https://api.introdb.app/intro";
const MAX_RETRIES = 3;
export function useSkipTime() {
@ -82,19 +83,45 @@ export function useSkipTime() {
}
};
const fetchIntroDBTime = async (): Promise<number | null> => {
if (!meta?.imdbId || meta.type === "movie") return null;
try {
const apiUrl = `${INTRODB_BASE_URL}?imdb_id=${meta.imdbId}&season=${meta.season?.number}&episode=${meta.episode?.number}`;
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error("IntroDB API request failed");
}
const data = await response.json();
if (data && typeof data.end_ms === "number") {
// Convert milliseconds to seconds
return Math.floor(data.end_ms / 1000);
}
return null;
} catch (error) {
console.error("Error fetching IntroDB time:", error);
return null;
}
};
const fetchSkipTime = async (): Promise<void> => {
// If user has febbox key, prioritize Fed-skips (better quality)
if (febboxKey) {
const fedSkipsTime = await fetchFedSkipsTime();
if (fedSkipsTime !== null) {
setSkiptime(fedSkipsTime);
// return;
return;
}
}
// // Fall back to Velora API (available to all users)
// const veloraSkipTime = await fetchVeloraSkipTime();
// setSkiptime(veloraSkipTime);
// Fall back to IntroDB API (available to all users)
const introDBTime = await fetchIntroDBTime();
setSkiptime(introDBTime);
};
fetchSkipTime();