feat(aniwatch): Improves title matching logic

- Enhances title matching accuracy when fetching Aniwatch IDs.
- Prioritizes user-preferred titles and falls back to English titles.
- Ensures only one fetch call is made per title if both english and userPreferred title are same.
- Adds a score threshold to filter low-quality matches.
- Fixes a bug where the episode list was not being returned.
This commit is contained in:
2025-04-23 09:32:52 -04:00
parent 00720565b4
commit b8ae211956
3 changed files with 96 additions and 21 deletions

View File

@@ -81,18 +81,23 @@ export function fetchEpisodes(
app.openapi(route, async (c) => {
const aniListId = Number(c.req.param("aniListId"));
const { result: episodes, errorOccurred } = await fetchEpisodes(
const { result, errorOccurred } = await fetchEpisodes(
aniListId,
env(c, "workerd"),
);
if (errorOccurred) {
if (errorOccurred || !result) {
return c.json(ErrorResponse, { status: 500 });
}
const { episodes, providerId } = result;
if (!episodes || episodes.length === 0) {
return c.json(ErrorResponse, { status: 404 });
}
return c.json({
success: true,
result: episodes ?? [],
result: { providerId, episodes },
});
});