From 31f1577019d40a737678374e517eeb749aeddb68 Mon Sep 17 00:00:00 2001 From: chrisk325 Date: Wed, 18 Mar 2026 14:53:46 +0530 Subject: [PATCH] add item type parser through tmdb lookup --- src/services/tmdbService.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/services/tmdbService.ts b/src/services/tmdbService.ts index 679f41f3..3dbb7bff 100644 --- a/src/services/tmdbService.ts +++ b/src/services/tmdbService.ts @@ -582,6 +582,32 @@ export class TMDBService { /** * Find TMDB ID by IMDB ID */ + /** + * Resolve both the TMDB ID and the correct content type ('movie' | 'series') for an IMDb ID. + * Uses TMDB's /find endpoint which returns tv_results and movie_results simultaneously, + * giving a definitive type without sequential guessing. + * TV results take priority since "other"-typed search results are usually series/anime. + */ + async findTypeAndIdByIMDB(imdbId: string): Promise<{ tmdbId: number; type: 'movie' | 'series' } | null> { + try { + const baseImdbId = imdbId.split(':')[0]; + const response = await axios.get(`${BASE_URL}/find/${baseImdbId}`, { + headers: await this.getHeaders(), + params: await this.getParams({ external_source: 'imdb_id' }), + }); + + if (response.data.tv_results?.length > 0) { + return { tmdbId: response.data.tv_results[0].id, type: 'series' }; + } + if (response.data.movie_results?.length > 0) { + return { tmdbId: response.data.movie_results[0].id, type: 'movie' }; + } + return null; + } catch { + return null; + } + } + async findTMDBIdByIMDB(imdbId: string, language: string = 'en-US'): Promise { const cacheKey = this.generateCacheKey('find_imdb', { imdbId, language });