fix: tweak aniwatch call to support tower of god s2 being split into 2
This commit is contained in:
@@ -25,29 +25,36 @@ export async function getEpisodesFromAniwatch(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const episodes: Episode[] | null = await fetch(
|
const episodes: Episode[] | null = await fetchEpisodes(
|
||||||
`https://aniwatch.up.railway.app/anime/episodes/${aniwatchId}`,
|
aniwatchId,
|
||||||
)
|
aniListId,
|
||||||
.then((res) => res.json<AniwatchEpisodesResponse>())
|
);
|
||||||
.then(({ totalEpisodes, episodes }) => {
|
|
||||||
if (totalEpisodes === 0) {
|
|
||||||
console.error(
|
|
||||||
`Error trying to load episodes from aniwatch; aniListId: ${aniListId}, totalEpisodes: ${totalEpisodes}`,
|
|
||||||
);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return episodes.map<Episode>(({ episodeId, number, title }) => ({
|
|
||||||
id: episodeId,
|
|
||||||
number,
|
|
||||||
title,
|
|
||||||
updatedAt: 0,
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
if (!episodes || episodes.length === 0) {
|
if (!episodes || episodes.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tower of God S2
|
||||||
|
if (aniListId == 153406) {
|
||||||
|
const aniwatchId = await getAniwatchId({
|
||||||
|
english: "Tower of God Season 2: Workshop Battle",
|
||||||
|
});
|
||||||
|
if (aniwatchId) {
|
||||||
|
const lastEpisodeOfPreviousTitle = episodes.at(-1)!!.number;
|
||||||
|
return {
|
||||||
|
providerId: "aniwatch",
|
||||||
|
episodes: await fetchEpisodes(aniwatchId, aniListId).then(
|
||||||
|
(extraEpisodes) =>
|
||||||
|
episodes.concat(
|
||||||
|
extraEpisodes?.map(({ number, ...episode }) => ({
|
||||||
|
...episode,
|
||||||
|
number: number + lastEpisodeOfPreviousTitle,
|
||||||
|
})) ?? [],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return { providerId: "aniwatch", episodes };
|
return { providerId: "aniwatch", episodes };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (shouldRetry && "response" in error && error.response.status === 429) {
|
if (shouldRetry && "response" in error && error.response.status === 429) {
|
||||||
|
|||||||
Reference in New Issue
Block a user