From 9e30eb471e503b4cdc6c6eac9a32a0d86d969c12 Mon Sep 17 00:00:00 2001 From: shafat420 Date: Sat, 21 Jun 2025 16:51:37 +0600 Subject: [PATCH] fix --- src/index.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 5638b4e..1a73926 100644 --- a/src/index.js +++ b/src/index.js @@ -222,9 +222,20 @@ app.get('/animepahe/hls/:anilistId/:episode', cache('15 minutes'), async (req, r return res.status(404).json({ error: 'No episodes found for this anime on AnimePahe' }); } - // Find the episode with the matching number - const targetEpisode = mappingResult.animepahe.episodes.find(ep => ep.number === parseInt(episode)); - + // Try to find the episode with the exact number first (e.g., AnimePahe episode numbers) + let targetEpisode = mappingResult.animepahe.episodes.find( + ep => ep.number === parseInt(episode, 10) + ); + + if (!targetEpisode) { + const requestedIndex = parseInt(episode, 10) - 1; // convert to 0-based index + const episodesArr = mappingResult.animepahe.episodes; + + if (requestedIndex >= 0 && requestedIndex < episodesArr.length) { + targetEpisode = episodesArr[requestedIndex]; + } + } + if (!targetEpisode) { return res.status(404).json({ error: `Episode ${episode} not found on AnimePahe` }); }