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
This commit is contained in:
Sʜɪɴᴇɪ Nᴏᴜᴢᴇɴ
2026-06-25 08:59:58 +05:30
parent 84d7e75372
commit bff4c5b7c6
+18 -11
View File
@@ -408,20 +408,27 @@ const getWatchSources = async (provider, anilistId, category, slug) => {
const episodes = provData.episodes?.[category] || []; const episodes = provData.episodes?.[category] || [];
let targetId = null; let targetId = null;
// NOTE: After injectSourceSlugs, ep.id becomes "watch/{provider}/{anilistId}/{category}/{prefix}-{number}" // NOTE: Handle both raw pipe IDs ("animedao:witch-hat-atelier:1") and slugged IDs
// Match the slug portion (last segment after the final "/") against the input slug. // ("watch/bonk/147105/sub/animedao-1") which may exist if cache was mutated by injectSourceSlugs.
// Use rawPipeId to get the original decoded ID for the pipe sources call. // Match slug against: last path segment (slugged) OR prefix-{number} (raw).
for (const ep of episodes) { for (const ep of episodes) {
const idParts = (ep.id || "").split("/"); const rawId = ep.id || "";
const slugSuffix = idParts[idParts.length - 1]; let match = false;
if (slugSuffix === slug) { // Case 1: Slugged ID — "watch/{provider}/{anilistId}/{category}/{prefix}-{number}"
// Decode rawPipeId back to original pipe format (e.g. "animedao:witch-hat-atelier:1") if (rawId.includes("/")) {
if (ep.rawPipeId) { const slugSuffix = rawId.split("/").pop();
targetId = translateId(ep.rawPipeId); match = slugSuffix === slug;
} else {
targetId = ep.id;
} }
// 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; break;
} }
} }