From 30644f65ea2e8437676422ae0b083c642a836887 Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Mon, 14 Mar 2022 09:29:58 -0400 Subject: [PATCH] fix(plex): find TV series in addition to movies from IMDb IDs (#1830) --- server/api/themoviedb/index.ts | 19 +++++++++++++------ server/lib/scanners/plex/index.ts | 12 ++++++------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/server/api/themoviedb/index.ts b/server/api/themoviedb/index.ts index d565c35ae..fceb07d23 100644 --- a/server/api/themoviedb/index.ts +++ b/server/api/themoviedb/index.ts @@ -561,13 +561,13 @@ class TheMovieDb extends ExternalAPI { } } - public async getMovieByImdbId({ + public async getMediaByImdbId({ imdbId, language = 'en', }: { imdbId: string; language?: string; - }): Promise { + }): Promise { try { const extResponse = await this.getByExternalId({ externalId: imdbId, @@ -583,12 +583,19 @@ class TheMovieDb extends ExternalAPI { return movie; } - throw new Error( - '[TMDb] Failed to find a title with the provided IMDB id' - ); + if (extResponse.tv_results[0]) { + const tvshow = await this.getTvShow({ + tvId: extResponse.tv_results[0].id, + language, + }); + + return tvshow; + } + + throw new Error(`No movie or show returned from API for ID ${imdbId}`); } catch (e) { throw new Error( - `[TMDb] Failed to get movie by external imdb ID: ${e.message}` + `[TMDb] Failed to find media using external IMDb ID: ${e.message}` ); } } diff --git a/server/lib/scanners/plex/index.ts b/server/lib/scanners/plex/index.ts index 20835b9a6..cd8dbd76a 100644 --- a/server/lib/scanners/plex/index.ts +++ b/server/lib/scanners/plex/index.ts @@ -371,10 +371,10 @@ class PlexScanner // If we got an IMDb ID, but no TMDb ID, lookup the TMDb ID with the IMDb ID if (mediaIds.imdbId && !mediaIds.tmdbId) { - const tmdbMovie = await this.tmdb.getMovieByImdbId({ + const tmdbMedia = await this.tmdb.getMediaByImdbId({ imdbId: mediaIds.imdbId, }); - mediaIds.tmdbId = tmdbMovie.id; + mediaIds.tmdbId = tmdbMedia.id; } // Cache GUIDs @@ -385,10 +385,10 @@ class PlexScanner const imdbMatch = plexitem.guid.match(imdbRegex); if (imdbMatch) { mediaIds.imdbId = imdbMatch[1]; - const tmdbMovie = await this.tmdb.getMovieByImdbId({ + const tmdbMedia = await this.tmdb.getMediaByImdbId({ imdbId: mediaIds.imdbId, }); - mediaIds.tmdbId = tmdbMovie.id; + mediaIds.tmdbId = tmdbMedia.id; } // Check if the agent is TMDb } else if (plexitem.guid.match(tmdbRegex)) { @@ -473,7 +473,7 @@ class PlexScanner mediaIds.tmdbId = result.tmdbId; mediaIds.imdbId = result?.imdbId; } else if (result?.imdbId) { - const tmdbMovie = await this.tmdb.getMovieByImdbId({ + const tmdbMovie = await this.tmdb.getMediaByImdbId({ imdbId: result.imdbId, }); mediaIds.tmdbId = tmdbMovie.id; @@ -522,7 +522,7 @@ class PlexScanner if (special.tmdbId) { await this.processPlexMovieByTmdbId(episode, special.tmdbId); } else if (special.imdbId) { - const tmdbMovie = await this.tmdb.getMovieByImdbId({ + const tmdbMovie = await this.tmdb.getMediaByImdbId({ imdbId: special.imdbId, }); await this.processPlexMovieByTmdbId(episode, tmdbMovie.id);