chore: update aniwatch calls
aniwatch API had breaking changes
This commit is contained in:
@@ -71,14 +71,67 @@ export async function getEpisodesFromAniwatch(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchEpisodes(
|
||||||
|
aniwatchId: string,
|
||||||
|
aniListId: number,
|
||||||
|
): Promise<
|
||||||
|
| {
|
||||||
|
number: number;
|
||||||
|
id: string;
|
||||||
|
updatedAt: number;
|
||||||
|
description?: string | null | undefined;
|
||||||
|
title?: string | null | undefined;
|
||||||
|
img?: string | null | undefined;
|
||||||
|
rating?: number | null | undefined;
|
||||||
|
}[]
|
||||||
|
| null
|
||||||
|
> {
|
||||||
|
return await fetch(
|
||||||
|
`https://aniwatch.up.railway.app/api/v2/hianime/anime/${aniwatchId}/episodes`,
|
||||||
|
)
|
||||||
|
.then(
|
||||||
|
(res) =>
|
||||||
|
res.json() as Promise<{
|
||||||
|
success: boolean;
|
||||||
|
data: AniwatchEpisodesResponse;
|
||||||
|
}>,
|
||||||
|
)
|
||||||
|
.then(({ success, data }) => {
|
||||||
|
if (!success || data.totalEpisodes === 0) {
|
||||||
|
console.error(
|
||||||
|
`Error trying to load episodes from aniwatch; aniListId: ${aniListId}, totalEpisodes: ${totalEpisodes}`,
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const { totalEpisodes, episodes } = data;
|
||||||
|
|
||||||
|
return episodes.map<Episode>(({ episodeId, number, title }) => ({
|
||||||
|
id: episodeId,
|
||||||
|
number,
|
||||||
|
title,
|
||||||
|
updatedAt: 0,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function getAniwatchId(
|
function getAniwatchId(
|
||||||
animeTitle: Partial<{ english: string; userPreferred: string }>,
|
animeTitle: Partial<{ english: string; userPreferred: string }>,
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
return fetch(
|
return fetch(
|
||||||
`https://aniwatch.up.railway.app/anime/search?q=${encodeURIComponent(animeTitle.english ?? animeTitle.userPreferred!)}`,
|
`https://aniwatch.up.railway.app/api/v2/hianime/search?q=${encodeURIComponent(animeTitle.english ?? animeTitle.userPreferred!)}`,
|
||||||
)
|
)
|
||||||
.then((res) => res.json<AniwatchSearchResponse>())
|
.then(
|
||||||
.then(({ animes }) => {
|
(res) =>
|
||||||
|
res.json() as Promise<{
|
||||||
|
success: boolean;
|
||||||
|
data: AniwatchSearchResponse;
|
||||||
|
}>,
|
||||||
|
)
|
||||||
|
.then(({ success, data: { animes } }) => {
|
||||||
|
if (!success) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const bestMatchingTitle = findBestMatchingTitle(
|
const bestMatchingTitle = findBestMatchingTitle(
|
||||||
animeTitle,
|
animeTitle,
|
||||||
animes.map((anime) => ({
|
animes.map((anime) => ({
|
||||||
|
|||||||
@@ -6,14 +6,21 @@ export async function getSourcesFromAniwatch(
|
|||||||
): Promise<FetchUrlResponse | null> {
|
): Promise<FetchUrlResponse | null> {
|
||||||
console.log(`Fetching sources from aniwatch for ${watchId}`);
|
console.log(`Fetching sources from aniwatch for ${watchId}`);
|
||||||
const { source, intro, outro, subtitles } = await fetch(
|
const { source, intro, outro, subtitles } = await fetch(
|
||||||
`https://aniwatch.up.railway.app/anime/episode-srcs?id=${encodeURIComponent(watchId)}`,
|
`https://aniwatch.up.railway.app/api/v2/hianime/episode/sources?animeEpisodeId=${encodeURIComponent(watchId)}`,
|
||||||
)
|
)
|
||||||
.then((res) => res.json<AniwatchEpisodeUrlResponse>())
|
.then(
|
||||||
.then(({ intro, outro, sources, tracks }) => {
|
(res) =>
|
||||||
if (!sources || sources.length === 0) {
|
res.json() as Promise<{
|
||||||
|
success: boolean;
|
||||||
|
data: AniwatchEpisodeUrlResponse;
|
||||||
|
}>,
|
||||||
|
)
|
||||||
|
.then(({ success, data }) => {
|
||||||
|
if (!success || !data.sources || data.sources.length === 0) {
|
||||||
return { source: null };
|
return { source: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { intro, outro, sources, tracks } = data;
|
||||||
return {
|
return {
|
||||||
intro: convertSkipTime(intro),
|
intro: convertSkipTime(intro),
|
||||||
outro: convertSkipTime(outro),
|
outro: convertSkipTime(outro),
|
||||||
|
|||||||
Reference in New Issue
Block a user