From 9915234d38d4701c527081ccc21b566980375331 Mon Sep 17 00:00:00 2001 From: sephrat <34862846+sephrat@users.noreply.github.com> Date: Sat, 5 Feb 2022 22:14:38 +0100 Subject: [PATCH] fix(media-sync): Add sanity checks upon media server sync (#4493) * Add sanity checks upon media server sync Fixes Media content may be improperly imported into Ombi #4472 * Fix Jellyfin sync * Refactor Emby and Jellyfin provider ids * Use new method Any * Fix log formatting --- .../Models/Media/EmbyProviderids.cs | 10 ++++------ src/Ombi.Api.Emby/Ombi.Api.Emby.csproj | 1 + .../Models/Media/JellyfinProviderids.cs | 10 ++++------ src/Ombi.Api.Jellyfin/Ombi.Api.Jellyfin.csproj | 1 + .../Models/BaseProviderids.cs | 11 +++++++++++ .../Ombi.Api.MediaServer.csproj | 18 ++++++++++++++++++ src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs | 8 +++++++- src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs | 7 +++++++ .../Jobs/Jellyfin/JellyfinContentSync.cs | 7 ++++++- .../Jobs/Jellyfin/JellyfinEpisodeSync.cs | 9 ++++++++- src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs | 5 +++++ src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs | 7 +++++++ 12 files changed, 79 insertions(+), 15 deletions(-) create mode 100644 src/Ombi.Api.MediaServer/Models/BaseProviderids.cs create mode 100644 src/Ombi.Api.MediaServer/Ombi.Api.MediaServer.csproj diff --git a/src/Ombi.Api.Emby/Models/Media/EmbyProviderids.cs b/src/Ombi.Api.Emby/Models/Media/EmbyProviderids.cs index 8302ee3ee..4a19025de 100644 --- a/src/Ombi.Api.Emby/Models/Media/EmbyProviderids.cs +++ b/src/Ombi.Api.Emby/Models/Media/EmbyProviderids.cs @@ -1,12 +1,10 @@ -namespace Ombi.Api.Emby.Models.Movie +using Ombi.Api.MediaServer.Models; + +namespace Ombi.Api.Emby.Models.Movie { - public class EmbyProviderids + public class EmbyProviderids: BaseProviderids { - public string Tmdb { get; set; } - public string Imdb { get; set; } public string TmdbCollection { get; set; } - - public string Tvdb { get; set; } public string Zap2It { get; set; } public string TvRage { get; set; } } diff --git a/src/Ombi.Api.Emby/Ombi.Api.Emby.csproj b/src/Ombi.Api.Emby/Ombi.Api.Emby.csproj index f167146af..b524c9ce4 100644 --- a/src/Ombi.Api.Emby/Ombi.Api.Emby.csproj +++ b/src/Ombi.Api.Emby/Ombi.Api.Emby.csproj @@ -12,6 +12,7 @@ + diff --git a/src/Ombi.Api.Jellyfin/Models/Media/JellyfinProviderids.cs b/src/Ombi.Api.Jellyfin/Models/Media/JellyfinProviderids.cs index 9b47f9a1a..0896ec4e9 100644 --- a/src/Ombi.Api.Jellyfin/Models/Media/JellyfinProviderids.cs +++ b/src/Ombi.Api.Jellyfin/Models/Media/JellyfinProviderids.cs @@ -1,12 +1,10 @@ -namespace Ombi.Api.Jellyfin.Models.Movie +using Ombi.Api.MediaServer.Models; + +namespace Ombi.Api.Jellyfin.Models.Movie { - public class JellyfinProviderids + public class JellyfinProviderids: BaseProviderids { - public string Tmdb { get; set; } - public string Imdb { get; set; } public string TmdbCollection { get; set; } - - public string Tvdb { get; set; } public string Zap2It { get; set; } public string TvRage { get; set; } } diff --git a/src/Ombi.Api.Jellyfin/Ombi.Api.Jellyfin.csproj b/src/Ombi.Api.Jellyfin/Ombi.Api.Jellyfin.csproj index f167146af..dfdb5a93f 100644 --- a/src/Ombi.Api.Jellyfin/Ombi.Api.Jellyfin.csproj +++ b/src/Ombi.Api.Jellyfin/Ombi.Api.Jellyfin.csproj @@ -13,6 +13,7 @@ + \ No newline at end of file diff --git a/src/Ombi.Api.MediaServer/Models/BaseProviderids.cs b/src/Ombi.Api.MediaServer/Models/BaseProviderids.cs new file mode 100644 index 000000000..6044288c6 --- /dev/null +++ b/src/Ombi.Api.MediaServer/Models/BaseProviderids.cs @@ -0,0 +1,11 @@ +namespace Ombi.Api.MediaServer.Models +{ + public class BaseProviderids + { + public string Tmdb { get; set; } + public string Imdb { get; set; } + public string Tvdb { get; set; } + public bool Any() => + !string.IsNullOrEmpty(Imdb) || !string.IsNullOrEmpty(Tmdb) || !string.IsNullOrEmpty(Tvdb); + } +} \ No newline at end of file diff --git a/src/Ombi.Api.MediaServer/Ombi.Api.MediaServer.csproj b/src/Ombi.Api.MediaServer/Ombi.Api.MediaServer.csproj new file mode 100644 index 000000000..f167146af --- /dev/null +++ b/src/Ombi.Api.MediaServer/Ombi.Api.MediaServer.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + 3.0.0.0 + 3.0.0.0 + + + 8.0 + Debug;Release;NonUiBuild + + + + + + + + \ 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..646cbdee0 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs @@ -149,7 +149,7 @@ namespace Ombi.Schedule.Jobs.Emby foreach (var tvShow in tv.Items) { processed++; - if (string.IsNullOrEmpty(tvShow.ProviderIds?.Tvdb)) + if (!tvShow.ProviderIds.Any()) { _logger.LogInformation("Provider Id on tv {0} is null", tvShow.Name); continue; @@ -249,6 +249,12 @@ namespace Ombi.Schedule.Jobs.Emby var alreadyGoingToAdd = content.Any(x => x.EmbyId == movieInfo.Id); if (existingMovie == null && !alreadyGoingToAdd) { + + if (!movieInfo.ProviderIds.Any()) + { + _logger.LogWarning($"Movie {movieInfo.Name} has no relevant metadata. Skipping."); + 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..fec5ca0ce 100644 --- a/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinContentSync.cs @@ -127,7 +127,7 @@ namespace Ombi.Schedule.Jobs.Jellyfin { processed++; - if (string.IsNullOrEmpty(tvShow.ProviderIds?.Tvdb)) + if (!tvShow.ProviderIds.Any()) { _logger.LogInformation("Provider Id on tv {0} is null", tvShow.Name); continue; @@ -217,6 +217,11 @@ namespace Ombi.Schedule.Jobs.Jellyfin var alreadyGoingToAdd = content.Any(x => x.JellyfinId == movieInfo.Id); if (existingMovie == null && !alreadyGoingToAdd) { + if (!movieInfo.ProviderIds.Any()) + { + _logger.LogWarning($"Movie {movieInfo.Name} has no relevant metadata. Skipping."); + 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..6e2daa7b3 100644 --- a/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Jellyfin/JellyfinEpisodeSync.cs @@ -66,7 +66,7 @@ namespace Ombi.Schedule.Jobs.Jellyfin public async Task Execute(IJobExecutionContext job) { var settings = await _settings.GetSettingsAsync(); - + Api = _apiFactory.CreateClient(settings); await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) .SendAsync(NotificationHub.NotificationEvent, "Jellyfin Episode Sync Started"); @@ -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."); + continue; + } + _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..bdb7e70bc 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 {movie.title} has no relevant metadata. Skipping."); + 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,