From 47dfaa26c006eec08c8606b9a8c99dbdf6a1f753 Mon Sep 17 00:00:00 2001 From: tapframe Date: Sun, 21 Sep 2025 13:44:55 +0530 Subject: [PATCH] kitsu bug fix --- src/hooks/useMetadata.ts | 12 +++++++++- src/services/stremioService.ts | 43 ++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/hooks/useMetadata.ts b/src/hooks/useMetadata.ts index 170a9ebd..761272cf 100644 --- a/src/hooks/useMetadata.ts +++ b/src/hooks/useMetadata.ts @@ -871,7 +871,17 @@ export const useMetadata = ({ id, type, addonId }: UseMetadataProps): UseMetadat let supportsIdPrefix = false; // Extract ID prefix from the ID - const idPrefix = id.split(':')[0]; + let idPrefix = id.split(':')[0]; + + // For IMDb IDs (tt...), extract just the 'tt' prefix + if (idPrefix.startsWith('tt')) { + idPrefix = 'tt'; + } + // For Kitsu IDs, keep the full prefix + else if (idPrefix === 'kitsu') { + idPrefix = 'kitsu'; + } + // For other prefixes, keep as is for (const resource of addon.resources) { // Check if the current element is a ResourceObject diff --git a/src/services/stremioService.ts b/src/services/stremioService.ts index 54aa10b8..a2739da0 100644 --- a/src/services/stremioService.ts +++ b/src/services/stremioService.ts @@ -930,11 +930,11 @@ class StremioService { let tmdbId: string | null = null; let season: number | undefined = undefined; let episode: number | undefined = undefined; + let idType: 'imdb' | 'kitsu' | 'tmdb' = 'imdb'; try { const idParts = id.split(':'); let baseId: string; - let idType: 'imdb' | 'kitsu' | 'tmdb' = 'imdb'; // Handle different episode ID formats if (idParts[0] === 'series') { @@ -991,24 +991,26 @@ class StremioService { } else { // For kitsu IDs, skip local scrapers as they don't support kitsu logger.log('🔧 [getStreams] Skipping local scrapers for kitsu ID:', baseId); - return; + // Don't return here - continue to Stremio addon processing } } catch (error) { return; // Skip local scrapers if ID parsing fails } - // Execute local scrapers asynchronously with TMDB ID - localScraperService.getStreams(scraperType, tmdbId, season, episode, (streams, scraperId, scraperName, error) => { - if (error) { - if (callback) { - callback(null, scraperId, scraperName, error); + // Execute local scrapers asynchronously with TMDB ID (only for IMDb IDs) + if (idType === 'imdb' && tmdbId) { + localScraperService.getStreams(scraperType, tmdbId, season, episode, (streams, scraperId, scraperName, error) => { + if (error) { + if (callback) { + callback(null, scraperId, scraperName, error); + } + } else if (streams && streams.length > 0) { + if (callback) { + callback(streams, scraperId, scraperName, null); + } } - } else if (streams && streams.length > 0) { - if (callback) { - callback(streams, scraperId, scraperName, null); - } - } - }); + }); + } } } } catch (error) { @@ -1036,8 +1038,19 @@ class StremioService { let supportsIdPrefix = false; // Extract ID prefix from the ID - const idPrefix = id.split(':')[0]; - logger.log(`🔍 [getStreams] Checking if addon supports ID prefix: ${idPrefix}`); + let idPrefix = id.split(':')[0]; + + // For IMDb IDs (tt...), extract just the 'tt' prefix + if (idPrefix.startsWith('tt')) { + idPrefix = 'tt'; + } + // For Kitsu IDs, keep the full prefix + else if (idPrefix === 'kitsu') { + idPrefix = 'kitsu'; + } + // For other prefixes, keep as is + + logger.log(`🔍 [getStreams] Checking if addon supports ID prefix: ${idPrefix} (from ${id.split(':')[0]})`); // Iterate through the resources array, checking each element for (const resource of addon.resources) {