From f926d9428856d29027d6cca3ada8e9925f221a44 Mon Sep 17 00:00:00 2001 From: Florian Dupret <34862846+sephrat@users.noreply.github.com> Date: Fri, 4 Feb 2022 17:47:17 +0100 Subject: [PATCH] Add sanity checks upon media server sync Fixes Media content may be improperly imported into Ombi #4472 --- src/Ombi.Api.Emby/Models/Media/EmbyProviderids.cs | 14 ++++++++++++++ .../Models/Media/JellyfinProviderids.cs | 14 ++++++++++++++ src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs | 7 +++++++ src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs | 7 +++++++ .../Jobs/Jellyfin/JellyfinContentSync.cs | 6 ++++++ .../Jobs/Jellyfin/JellyfinEpisodeSync.cs | 7 +++++++ src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs | 5 +++++ src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs | 7 +++++++ 8 files changed, 67 insertions(+) diff --git a/src/Ombi.Api.Emby/Models/Media/EmbyProviderids.cs b/src/Ombi.Api.Emby/Models/Media/EmbyProviderids.cs index 8302ee3ee..ca85ed1a5 100644 --- a/src/Ombi.Api.Emby/Models/Media/EmbyProviderids.cs +++ b/src/Ombi.Api.Emby/Models/Media/EmbyProviderids.cs @@ -9,5 +9,19 @@ public string Tvdb { get; set; } public string Zap2It { get; set; } public string TvRage { get; set; } + + public bool Any() + { + if (string.IsNullOrEmpty(Imdb) + && string.IsNullOrEmpty(Tmdb) + && string.IsNullOrEmpty(Tvdb)) + { + return true; + } + else + { + return false; + } + } } } \ No newline at end of file diff --git a/src/Ombi.Api.Jellyfin/Models/Media/JellyfinProviderids.cs b/src/Ombi.Api.Jellyfin/Models/Media/JellyfinProviderids.cs index 9b47f9a1a..275797af5 100644 --- a/src/Ombi.Api.Jellyfin/Models/Media/JellyfinProviderids.cs +++ b/src/Ombi.Api.Jellyfin/Models/Media/JellyfinProviderids.cs @@ -9,5 +9,19 @@ public string Tvdb { get; set; } public string Zap2It { get; set; } public string TvRage { get; set; } + + public bool Any() + { + if (string.IsNullOrEmpty(Imdb) + && string.IsNullOrEmpty(Tmdb) + && string.IsNullOrEmpty(Tvdb)) + { + return true; + } + else + { + return false; + } + } } } \ No newline at end of file diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs index cb7eaefd3..aa66f6531 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs @@ -249,6 +249,13 @@ namespace Ombi.Schedule.Jobs.Emby var alreadyGoingToAdd = content.Any(x => x.EmbyId == movieInfo.Id); if (existingMovie == null && !alreadyGoingToAdd) { + + if (string.IsNullOrEmpty(movieInfo.ProviderIds?.Imdb) + && string.IsNullOrEmpty(movieInfo.ProviderIds?.Tmdb)) + { + _logger.LogWarning($"Movie {0} has no relevant metadata. Skipping.", movieInfo.Name); + return; + } _logger.LogDebug("Adding new movie {0}", movieInfo.Name); content.Add(new EmbyContent { diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs index c1ca48ef7..b3c1ffbab 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs @@ -152,6 +152,13 @@ namespace Ombi.Schedule.Jobs.Emby if (existingEpisode == null && !existingInList) { + // Sanity checks + if (ep.IndexNumber == 0) + { + _logger.LogWarning($"Episode {ep.Name} has no episode number. Skipping."); + continue; + } + _logger.LogDebug("Adding new episode {0} to parent {1}", ep.Name, ep.SeriesName); // add it epToAdd.Add(new EmbyEpisode diff --git a/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinContentSync.cs b/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinContentSync.cs index 60ee42210..3ac849836 100644 --- a/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinContentSync.cs @@ -217,6 +217,12 @@ namespace Ombi.Schedule.Jobs.Jellyfin var alreadyGoingToAdd = content.Any(x => x.JellyfinId == movieInfo.Id); if (existingMovie == null && !alreadyGoingToAdd) { + if (string.IsNullOrEmpty(movieInfo.ProviderIds?.Imdb) + && string.IsNullOrEmpty(movieInfo.ProviderIds?.Tmdb)) + { + _logger.LogWarning($"Movie {0} has no relevant metadata. Skipping.", movieInfo.Name); + return; + } _logger.LogDebug("Adding new movie {0}", movieInfo.Name); content.Add(new JellyfinContent { diff --git a/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinEpisodeSync.cs index 27e50c9b7..1d188b541 100644 --- a/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinEpisodeSync.cs @@ -128,6 +128,13 @@ namespace Ombi.Schedule.Jobs.Jellyfin if (existingEpisode == null && !existingInList) { + // Sanity checks + if (ep.IndexNumber == 0) // no check on season number, Season 0 can be Specials + { + _logger.LogWarning($"Episode {ep.Name} has no episode number. Skipping."); + return; + } + _logger.LogDebug("Adding new episode {0} to parent {1}", ep.Name, ep.SeriesName); // add it epToAdd.Add(new JellyfinEpisode diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs index df96457d0..e9499b952 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs @@ -342,6 +342,11 @@ namespace Ombi.Schedule.Jobs.Plex } } + if (!guids.Any()) + { + Logger.LogWarning($"Movie {0} has no relevant metadata. Skipping.", movie.title); + continue; + } var providerIds = PlexHelper.GetProviderIdsFromMetadata(guids.ToArray()); var item = new PlexServerContent diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs index 4a088ca7b..c17af088c 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs @@ -179,6 +179,13 @@ namespace Ombi.Schedule.Jobs.Plex episode.grandparentRatingKey = seriesExists.Key; } + // Sanity checks + if (episode.index == 0) + { + _log.LogWarning($"Episode {episode.title} has no episode number. Skipping."); + continue; + } + ep.Add(new PlexEpisode { EpisodeNumber = episode.index,