From f2200f793d2340db0c2c7e5fdeab3a5d619fd442 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 29 Sep 2019 16:27:54 -0400 Subject: [PATCH] Fixed: Quality Finder Tweaks --- .../Qualities/QualityFinderFixture.cs | 29 +++++++++++++++++-- src/NzbDrone.Core/Qualities/QualityFinder.cs | 22 ++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core.Test/Qualities/QualityFinderFixture.cs b/src/NzbDrone.Core.Test/Qualities/QualityFinderFixture.cs index abaa44586..63c30397f 100644 --- a/src/NzbDrone.Core.Test/Qualities/QualityFinderFixture.cs +++ b/src/NzbDrone.Core.Test/Qualities/QualityFinderFixture.cs @@ -8,8 +8,34 @@ namespace NzbDrone.Core.Test.Qualities [TestFixture] public class QualityFinderFixture { + [TestCase(Source.CAM, 480, Modifier.NONE)] + [TestCase(Source.CAM, 1080, Modifier.NONE)] + [TestCase(Source.CAM, 0, Modifier.NONE)] + public void should_return_CAM(Source source, Resolution resolution, Modifier modifier) + { + QualityFinder.FindBySourceAndResolution(source, resolution, modifier).Should().Be(Quality.CAM); + } + + [TestCase(Source.CAM, 1080, Modifier.SCREENER)] + [TestCase(Source.CAM, 0, Modifier.SCREENER)] + public void should_return_Unknown(Source source, Resolution resolution, Modifier modifier) + { + QualityFinder.FindBySourceAndResolution(source, resolution, modifier).Should().Be(Quality.Unknown); + } + + [TestCase(Source.DVD, 480, Modifier.REMUX)] + public void should_return_DVD_Remux(Source source, Resolution resolution, Modifier modifier) + { + QualityFinder.FindBySourceAndResolution(source, resolution, modifier).Should().Be(Quality.DVDR); + } + + [TestCase(Source.DVD, 480, Modifier.NONE)] + public void should_return_DVD(Source source, Resolution resolution, Modifier modifier) + { + QualityFinder.FindBySourceAndResolution(source, resolution, modifier).Should().Be(Quality.DVD); + } + [TestCase(Source.TV, 480, Modifier.NONE)] - [TestCase(Source.UNKNOWN, 480, Modifier.NONE)] public void should_return_SDTV(Source source, Resolution resolution, Modifier modifier) { QualityFinder.FindBySourceAndResolution(source, resolution, modifier).Should().Be(Quality.SDTV); @@ -30,7 +56,6 @@ namespace NzbDrone.Core.Test.Qualities } [TestCase(Source.BLURAY, 720, Modifier.NONE)] - [TestCase(Source.DVD, 720, Modifier.NONE)] public void should_return_Bluray720p(Source source, Resolution resolution, Modifier modifier) { QualityFinder.FindBySourceAndResolution(source, resolution, modifier).Should().Be(Quality.Bluray720p); diff --git a/src/NzbDrone.Core/Qualities/QualityFinder.cs b/src/NzbDrone.Core/Qualities/QualityFinder.cs index 383361810..fd4a2ae30 100644 --- a/src/NzbDrone.Core/Qualities/QualityFinder.cs +++ b/src/NzbDrone.Core/Qualities/QualityFinder.cs @@ -11,6 +11,7 @@ namespace NzbDrone.Core.Qualities public static Quality FindBySourceAndResolution(Source source, Resolution resolution, Modifier modifer) { + // Check for a perfect 3-way match var matchingQuality = Quality.All.SingleOrDefault(q => q.Source == source && q.Resolution == resolution && q.Modifier == modifer); if (matchingQuality != null) @@ -18,6 +19,27 @@ namespace NzbDrone.Core.Qualities return matchingQuality; } + // Check for Source and Modifier Match for Qualities with Unknown Resolution + var matchingQualitiesUnknownResolution = Quality.All.Where(q => q.Source == source && (q.Resolution == Resolution.Unknown) && q.Modifier == modifer && q != Quality.Unknown); + + if (matchingQualitiesUnknownResolution.Any()) + { + if (matchingQualitiesUnknownResolution.Count() == 1) + { + return matchingQualitiesUnknownResolution.First(); + } + + foreach (var quality in matchingQualitiesUnknownResolution) + { + if (quality.Source >= source) + { + Logger.Warn("Unable to find exact quality for {0}, {1}, and {2}. Using {3} as fallback", source, resolution, modifer, quality); + return quality; + } + } + } + + //Check for Modifier match var matchingModifier = Quality.All.Where(q => q.Modifier == modifer); var matchingResolution = matchingModifier.Where(q => q.Resolution == resolution)