chore: update aniwatch calls
aniwatch API had breaking changes
This commit is contained in:
@@ -71,14 +71,67 @@ export async function getEpisodesFromAniwatch(
|
||||
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(
|
||||
animeTitle: Partial<{ english: string; userPreferred: string }>,
|
||||
): Promise<string | undefined> {
|
||||
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(({ animes }) => {
|
||||
.then(
|
||||
(res) =>
|
||||
res.json() as Promise<{
|
||||
success: boolean;
|
||||
data: AniwatchSearchResponse;
|
||||
}>,
|
||||
)
|
||||
.then(({ success, data: { animes } }) => {
|
||||
if (!success) {
|
||||
return;
|
||||
}
|
||||
|
||||
const bestMatchingTitle = findBestMatchingTitle(
|
||||
animeTitle,
|
||||
animes.map((anime) => ({
|
||||
|
||||
@@ -6,14 +6,21 @@ export async function getSourcesFromAniwatch(
|
||||
): Promise<FetchUrlResponse | null> {
|
||||
console.log(`Fetching sources from aniwatch for ${watchId}`);
|
||||
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(({ intro, outro, sources, tracks }) => {
|
||||
if (!sources || sources.length === 0) {
|
||||
.then(
|
||||
(res) =>
|
||||
res.json() as Promise<{
|
||||
success: boolean;
|
||||
data: AniwatchEpisodeUrlResponse;
|
||||
}>,
|
||||
)
|
||||
.then(({ success, data }) => {
|
||||
if (!success || !data.sources || data.sources.length === 0) {
|
||||
return { source: null };
|
||||
}
|
||||
|
||||
const { intro, outro, sources, tracks } = data;
|
||||
return {
|
||||
intro: convertSkipTime(intro),
|
||||
outro: convertSkipTime(outro),
|
||||
|
||||
Reference in New Issue
Block a user