From bff4c5b7c6b31b3ba9755fd94f511d0ed3ead1f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=CA=9C=C9=AA=C9=B4=E1=B4=87=C9=AA=20N=E1=B4=8F=E1=B4=9C?= =?UTF-8?q?=E1=B4=A2=E1=B4=87=C9=B4?= <157171073+Shineii86@users.noreply.github.com> Date: Thu, 25 Jun 2026 08:59:58 +0530 Subject: [PATCH] Fix getWatchSources to handle both raw and slugged episode IDs - Handle raw pipe IDs (animedao:witch-hat-atelier:1) with colon separator - Handle slugged IDs (watch/bonk/147105/sub/animedao-1) with slash separator - Use rawPipeId for decoded ID recovery in both cases --- src/helpers/pipe.js | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/helpers/pipe.js b/src/helpers/pipe.js index 11b1720..13de4d9 100644 --- a/src/helpers/pipe.js +++ b/src/helpers/pipe.js @@ -408,20 +408,27 @@ const getWatchSources = async (provider, anilistId, category, slug) => { const episodes = provData.episodes?.[category] || []; let targetId = null; - // NOTE: After injectSourceSlugs, ep.id becomes "watch/{provider}/{anilistId}/{category}/{prefix}-{number}" - // Match the slug portion (last segment after the final "/") against the input slug. - // Use rawPipeId to get the original decoded ID for the pipe sources call. + // NOTE: Handle both raw pipe IDs ("animedao:witch-hat-atelier:1") and slugged IDs + // ("watch/bonk/147105/sub/animedao-1") which may exist if cache was mutated by injectSourceSlugs. + // Match slug against: last path segment (slugged) OR prefix-{number} (raw). for (const ep of episodes) { - const idParts = (ep.id || "").split("/"); - const slugSuffix = idParts[idParts.length - 1]; + const rawId = ep.id || ""; + let match = false; - if (slugSuffix === slug) { - // Decode rawPipeId back to original pipe format (e.g. "animedao:witch-hat-atelier:1") - if (ep.rawPipeId) { - targetId = translateId(ep.rawPipeId); - } else { - targetId = ep.id; - } + // Case 1: Slugged ID — "watch/{provider}/{anilistId}/{category}/{prefix}-{number}" + if (rawId.includes("/")) { + const slugSuffix = rawId.split("/").pop(); + match = slugSuffix === slug; + } + // Case 2: Raw pipe ID — "animedao:witch-hat-atelier:1" + else if (rawId.includes(":")) { + const prefix = rawId.split(":")[0]; + match = `${prefix}-${ep.number}` === slug; + } + + if (match) { + // Use rawPipeId if available (decoded pipe format), otherwise use the ep.id + targetId = ep.rawPipeId ? translateId(ep.rawPipeId) : rawId; break; } }