From 03cecb33559e27199c5a174fc86de0c4550fe666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C4=81rti=C5=86=C5=A1=20Mo=C5=BEeiko?= Date: Sun, 14 Feb 2021 15:35:05 -0800 Subject: [PATCH] fix(plex-sync): get correct Plex metadata for Hama movie items (#901) fixes #898 --- server/job/plexsync/index.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/server/job/plexsync/index.ts b/server/job/plexsync/index.ts index 3ed5870db..9cef1cfdc 100644 --- a/server/job/plexsync/index.ts +++ b/server/job/plexsync/index.ts @@ -353,6 +353,25 @@ class JobPlexSync { } } + // movies with hama agent actually are tv shows with at least one episode in it + // try to get first episode of any season - cannot hardcode season or episode number + // because sometimes user can have it in other season/ep than s01e01 + private async processHamaMovie( + metadata: PlexMetadata, + tmdbMovie: TmdbMovieDetails | undefined, + tmdbMovieId: number + ) { + const season = metadata.Children?.Metadata[0]; + if (season) { + const episodes = await this.plexClient.getChildrenMetadata( + season.ratingKey + ); + if (episodes) { + await this.processMovieWithId(episodes[0], tmdbMovie, tmdbMovieId); + } + } + } + private async processShow(plexitem: PlexLibraryItem) { const mediaRepository = getRepository(Media); @@ -431,8 +450,8 @@ class JobPlexSync { // if lookup of tvshow above failed, then try movie with tmdbid/imdbid // note - some tv shows have imdbid set too, that's why this need to go second if (result?.tmdbId) { - return await this.processMovieWithId( - plexitem, + return await this.processHamaMovie( + metadata, undefined, result.tmdbId ); @@ -440,8 +459,8 @@ class JobPlexSync { const tmdbMovie = await this.tmdb.getMovieByImdbId({ imdbId: result.imdbId, }); - return await this.processMovieWithId( - plexitem, + return await this.processHamaMovie( + metadata, tmdbMovie, tmdbMovie.id );