From f3ea979b8bd77842780ce8e6928b16237dd779cf Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 22 Feb 2022 21:35:28 +0000 Subject: [PATCH] fix(mediaserver): fixed some more issues in the media server sync and availability checks --- .../Rule/Search/EmbyAvailabilityRuleTests.cs | 3 +++ .../Rule/Search/JellyfinAvailabilityRuleTests.cs | 3 +++ .../Rule/Rules/Search/EmbyAvailabilityRule.cs | 7 +++++++ .../Rules/Search/JellyfinAvailabilityRule.cs | 9 ++++++++- .../Rule/Rules/Search/PlexAvailabilityRule.cs | 16 ++++++++++++++-- src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs | 12 +++++++++++- 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/Ombi.Core.Tests/Rule/Search/EmbyAvailabilityRuleTests.cs b/src/Ombi.Core.Tests/Rule/Search/EmbyAvailabilityRuleTests.cs index e3ec6cffe..484e872e2 100644 --- a/src/Ombi.Core.Tests/Rule/Search/EmbyAvailabilityRuleTests.cs +++ b/src/Ombi.Core.Tests/Rule/Search/EmbyAvailabilityRuleTests.cs @@ -8,6 +8,7 @@ using Ombi.Core.Rule.Rules.Search; using Ombi.Core.Services; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; +using Ombi.Settings.Settings.Models; using Ombi.Store.Entities; using Ombi.Store.Repository; using Ombi.Store.Repository.Requests; @@ -51,6 +52,7 @@ namespace Ombi.Core.Tests.Rule.Search [Test] public async Task Movie_ShouldBe_Available_WhenFoundInEmby_4K() { + FeatureMock.Setup(x => x.FeatureEnabled(FeatureNames.Movie4KRequests)).ReturnsAsync(true); ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny())).ReturnsAsync(new EmbyContent { TheMovieDbId = "123", @@ -70,6 +72,7 @@ namespace Ombi.Core.Tests.Rule.Search [Test] public async Task Movie_ShouldBe_Available_WhenFoundInEmby_Both() { + FeatureMock.Setup(x => x.FeatureEnabled(FeatureNames.Movie4KRequests)).ReturnsAsync(true); ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny())).ReturnsAsync(new EmbyContent { TheMovieDbId = "123", diff --git a/src/Ombi.Core.Tests/Rule/Search/JellyfinAvailabilityRuleTests.cs b/src/Ombi.Core.Tests/Rule/Search/JellyfinAvailabilityRuleTests.cs index 6da5787b6..f56876e48 100644 --- a/src/Ombi.Core.Tests/Rule/Search/JellyfinAvailabilityRuleTests.cs +++ b/src/Ombi.Core.Tests/Rule/Search/JellyfinAvailabilityRuleTests.cs @@ -8,6 +8,7 @@ using Ombi.Core.Rule.Rules.Search; using Ombi.Core.Services; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; +using Ombi.Settings.Settings.Models; using Ombi.Store.Entities; using Ombi.Store.Repository; using Ombi.Store.Repository.Requests; @@ -51,6 +52,7 @@ namespace Ombi.Core.Tests.Rule.Search [Test] public async Task Movie_ShouldBe_Available_WhenFoundInJellyfin_4K() { + FeatureMock.Setup(x => x.FeatureEnabled(FeatureNames.Movie4KRequests)).ReturnsAsync(true); ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny())).ReturnsAsync(new JellyfinContent { TheMovieDbId = "123", @@ -70,6 +72,7 @@ namespace Ombi.Core.Tests.Rule.Search [Test] public async Task Movie_ShouldBe_Available_WhenFoundInJellyfin_Both() { + FeatureMock.Setup(x => x.FeatureEnabled(FeatureNames.Movie4KRequests)).ReturnsAsync(true); ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny())).ReturnsAsync(new JellyfinContent { TheMovieDbId = "123", diff --git a/src/Ombi.Core/Rule/Rules/Search/EmbyAvailabilityRule.cs b/src/Ombi.Core/Rule/Rules/Search/EmbyAvailabilityRule.cs index 79158ee43..d28f50cc0 100644 --- a/src/Ombi.Core/Rule/Rules/Search/EmbyAvailabilityRule.cs +++ b/src/Ombi.Core/Rule/Rules/Search/EmbyAvailabilityRule.cs @@ -82,6 +82,13 @@ namespace Ombi.Core.Rule.Rules.Search obj.EmbyUrl = item.Url; obj.Quality = item.Quality; } + + if (item.Quality.HasValue()) + { + obj.Available = true; + obj.EmbyUrl = item.Url; + obj.Quality = item.Quality; + } } else { diff --git a/src/Ombi.Core/Rule/Rules/Search/JellyfinAvailabilityRule.cs b/src/Ombi.Core/Rule/Rules/Search/JellyfinAvailabilityRule.cs index 7cab89991..f10ac4bdd 100644 --- a/src/Ombi.Core/Rule/Rules/Search/JellyfinAvailabilityRule.cs +++ b/src/Ombi.Core/Rule/Rules/Search/JellyfinAvailabilityRule.cs @@ -88,13 +88,20 @@ namespace Ombi.Core.Rule.Rules.Search { movie.Available4K = true; obj.JellyfinUrl = item.Url; - } + } else { obj.Available = true; obj.EmbyUrl = item.Url; obj.Quality = item.Quality; } + + if (item.Quality.HasValue()) + { + obj.Available = true; + obj.EmbyUrl = item.Url; + obj.Quality = item.Quality; + } } else { diff --git a/src/Ombi.Core/Rule/Rules/Search/PlexAvailabilityRule.cs b/src/Ombi.Core/Rule/Rules/Search/PlexAvailabilityRule.cs index 1742f9f20..ab5b3a6c6 100644 --- a/src/Ombi.Core/Rule/Rules/Search/PlexAvailabilityRule.cs +++ b/src/Ombi.Core/Rule/Rules/Search/PlexAvailabilityRule.cs @@ -3,9 +3,11 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Ombi.Core.Models.Search; using Ombi.Core.Rule.Interfaces; +using Ombi.Core.Services; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; using Ombi.Helpers; +using Ombi.Settings.Settings.Models; using Ombi.Store.Entities; using Ombi.Store.Repository; @@ -14,12 +16,15 @@ namespace Ombi.Core.Rule.Rules.Search public class PlexAvailabilityRule : BaseSearchRule, IRules { private readonly ISettingsService _plexSettings; + private readonly IFeatureService _featureService; - public PlexAvailabilityRule(IPlexContentRepository repo, ILogger log, ISettingsService plexSettings) + public PlexAvailabilityRule(IPlexContentRepository repo, ILogger log, ISettingsService plexSettings, + IFeatureService featureService) { PlexContentRepository = repo; Log = log; _plexSettings = plexSettings; + _featureService = featureService; } private IPlexContentRepository PlexContentRepository { get; } @@ -92,10 +97,17 @@ namespace Ombi.Core.Rule.Rules.Search if (obj is SearchMovieViewModel movie) { - if (item.Has4K) + var is4kEnabled = await _featureService.FeatureEnabled(FeatureNames.Movie4KRequests); + + if (item.Has4K && is4kEnabled) { movie.Available4K = true; } + else + { + obj.Available = true; + obj.Quality = item.Quality; + } if (item.Quality.HasValue()) { diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs index 04b28d6e7..71bc5dcf4 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs @@ -307,9 +307,13 @@ namespace Ombi.Schedule.Jobs.Plex // We need to see if this is a different quality, // We want to know if this is a 4k content for example var foundQualities = movie.Media?.Select(x => x.videoResolution); - + var qualitySaved = false; foreach (var quality in foundQualities) { + if (qualitySaved) + { + break; + } if (quality.Equals(existing.Quality)) { // We got it @@ -322,6 +326,12 @@ namespace Ombi.Schedule.Jobs.Plex Logger.LogDebug($"We already have movie {movie.title}, But found a 4K version!"); existing.Has4K = true; await Repo.Update(existing); + } + else + { + qualitySaved = true; + existing.Quality = quality; + await Repo.Update(existing); } }