fix: tweak aniwatch call to support tower of god s2 being split into 2

This commit is contained in:
2024-10-24 08:51:46 -04:00
parent 882f9b1843
commit 59a7a5f8d4

View File

@@ -25,27 +25,34 @@ 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}`,
); );
if (!episodes || episodes.length === 0) {
return null; return null;
} }
return episodes.map<Episode>(({ episodeId, number, title }) => ({ // Tower of God S2
id: episodeId, if (aniListId == 153406) {
number, const aniwatchId = await getAniwatchId({
title, english: "Tower of God Season 2: Workshop Battle",
updatedAt: 0,
}));
}); });
if (!episodes || episodes.length === 0) { if (aniwatchId) {
return null; 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 };