From d9787dc32aace808d196f6f87456ef45de3d7bbf Mon Sep 17 00:00:00 2001 From: TidusJar Date: Tue, 20 Aug 2024 20:47:28 +0100 Subject: [PATCH] fix(plex): Fixed some errors around the scanner that was causing the scan to fail --- src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs | 14 +++++++++++++- src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs | 15 ++++++++------- .../Repository/PlexContentRepository.cs | 2 +- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs b/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs index d7c05d71e..adf6bddca 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging; using Ombi.Api.Emby; using Ombi.Api.Jellyfin; using Ombi.Api.Plex; +using Ombi.Api.Plex.Models; using Ombi.Api.TheMovieDb; using Ombi.Api.TheMovieDb.Models; using Ombi.Api.TvMaze; @@ -286,7 +287,18 @@ namespace Ombi.Schedule.Jobs.Ombi continue; } var servers = settings.Servers[0]; - var metaData = await _plexApi.GetMetadata(servers.PlexAuthToken, settings.Servers[0].FullUri, movie.Key); + PlexMetadata metaData = null; + + try + { + metaData = await _plexApi.GetMetadata(servers.PlexAuthToken, settings.Servers[0].FullUri, movie.Key); + } + catch (Exception e) + { + _log.LogError($"Could not find the metadata for title: '{movie.Title}', skipping"); + _log.LogDebug(e, $"Could not find the metadata for title: '{movie.Title}', skipping"); + continue; + } var guids = new List(); var meta = metaData.MediaContainer.Metadata.FirstOrDefault(); diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs index 365110d9c..596a6202a 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs @@ -304,6 +304,13 @@ namespace Ombi.Schedule.Jobs.Plex var existing = await Repo.GetFirstContentByCustom(x => x.Title == movie.title && x.ReleaseYear == movie.year.ToString() && x.Type == MediaType.Movie); + + + if (existing == null) + { + // Let's just check the key + existing = await Repo.GetByKey(movie.ratingKey); + } if (existing != null) { // We need to see if this is a different quality, @@ -340,13 +347,7 @@ namespace Ombi.Schedule.Jobs.Plex Logger.LogDebug($"We already have movie {movie.title}"); continue; - } - - //var hasSameKey = await Repo.GetByKey(movie.ratingKey); - //if (hasSameKey != null) - //{ - // await Repo.Delete(hasSameKey); - //} + } Logger.LogDebug("Adding movie {0}", movie.title); var guids = new List(); diff --git a/src/Ombi.Store/Repository/PlexContentRepository.cs b/src/Ombi.Store/Repository/PlexContentRepository.cs index 9f34af6a1..1d9a35cd4 100644 --- a/src/Ombi.Store/Repository/PlexContentRepository.cs +++ b/src/Ombi.Store/Repository/PlexContentRepository.cs @@ -94,7 +94,7 @@ namespace Ombi.Store.Repository public async Task GetByKey(string key) { - return await Db.PlexServerContent.Include(x => x.Seasons).FirstOrDefaultAsync(x => x.Key == key); + return await Db.PlexServerContent.Include(x => x.Seasons).Include(x => x.Episodes).FirstOrDefaultAsync(x => x.Key == key); } public IEnumerable GetWhereContentByCustom(Expression> predicate)