From 78cac9fcfa07b35e59ac467a7713c9100dc349f3 Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 23 Sep 2019 22:10:51 -0400 Subject: [PATCH] Fixed: Use Modifier in Quality Aggregation --- .../Aggregators/AggregateQualityFixture.cs | 4 ++-- .../Aggregation/Aggregators/AggregateQuality.cs | 11 ++++++++++- .../AugmentQualityFromDownloadClientItem.cs | 2 ++ .../Quality/AugmentQualityFromFileName.cs | 2 ++ .../Quality/AugmentQualityFromFolder.cs | 2 ++ .../Augmenters/Quality/AugmentQualityResult.cs | 15 +++++++++++++-- src/NzbDrone.Core/Parser/ParsingService.cs | 2 +- src/NzbDrone.Core/Qualities/Quality.cs | 11 ----------- src/NzbDrone.Core/Qualities/QualityFinder.cs | 4 ++-- 9 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateQualityFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateQualityFixture.cs index 2a5ede3c8..f71ab5272 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateQualityFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateQualityFixture.cs @@ -32,10 +32,10 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators .Returns(AugmentQualityResult.ResolutionOnly(Resolution.R1080P, Confidence.MediaInfo)); _fileExtensionAugmenter.Setup(s => s.AugmentQuality(It.IsAny())) - .Returns(new AugmentQualityResult(Source.TV, Confidence.Fallback, Resolution.R720P, Confidence.Fallback, new Revision())); + .Returns(new AugmentQualityResult(Source.TV, Confidence.Fallback, Resolution.R720P, Confidence.Fallback, Modifier.NONE, Confidence.Fallback, new Revision())); _nameAugmenter.Setup(s => s.AugmentQuality(It.IsAny())) - .Returns(new AugmentQualityResult(Source.TV, Confidence.Default, Resolution.R480P, Confidence.Default, new Revision())); + .Returns(new AugmentQualityResult(Source.TV, Confidence.Default, Resolution.R480P, Confidence.Default, Modifier.NONE, Confidence.Default, new Revision())); } private void GivenAugmenters(params Mock[] mocks) diff --git a/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateQuality.cs b/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateQuality.cs index b5c03b174..298cf191b 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateQuality.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateQuality.cs @@ -30,6 +30,8 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators var sourceConfidence = Confidence.Default; var resolution = Resolution.Unknown; var resolutionConfidence = Confidence.Default; + var modifier = Modifier.NONE; + var modifierConfidence = Confidence.Default; var revison = new Revision(); foreach (var augmentedQuality in augmentedQualities) @@ -48,6 +50,13 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators resolutionConfidence = augmentedQuality.ResolutionConfidence; } + if (augmentedQuality.Modifier > modifier || + augmentedQuality.ModifierConfidence > modifierConfidence && augmentedQuality.Modifier != Modifier.NONE) + { + modifier = augmentedQuality.Modifier; + modifierConfidence = augmentedQuality.ModifierConfidence; + } + if (augmentedQuality.Revision != null && augmentedQuality.Revision > revison) { revison = augmentedQuality.Revision; @@ -56,7 +65,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators _logger.Trace("Finding quality. Source: {0}. Resolution: {1}", source, resolution); - var quality = new QualityModel(QualityFinder.FindBySourceAndResolution(source, resolution), revison); + var quality = new QualityModel(QualityFinder.FindBySourceAndResolution(source, resolution, modifier), revison); if (resolutionConfidence == Confidence.MediaInfo) { diff --git a/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromDownloadClientItem.cs b/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromDownloadClientItem.cs index a5586b28d..09f02fe6b 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromDownloadClientItem.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromDownloadClientItem.cs @@ -17,6 +17,8 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenter Confidence.Tag, quality.Quality.Resolution, Confidence.Tag, + quality.Quality.Modifier, + Confidence.Tag, quality.Revision); } } diff --git a/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromFileName.cs b/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromFileName.cs index 5d8a5cdcc..e45db6f80 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromFileName.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromFileName.cs @@ -22,6 +22,8 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenter confidence, quality.Quality.Resolution, confidence, + quality.Quality.Modifier, + confidence, quality.Revision); } } diff --git a/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromFolder.cs b/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromFolder.cs index 2c4f40fc7..574212c20 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromFolder.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromFolder.cs @@ -17,6 +17,8 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenter Confidence.Tag, quality.Quality.Resolution, Confidence.Tag, + quality.Quality.Modifier, + Confidence.Tag, quality.Revision); } } diff --git a/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityResult.cs b/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityResult.cs index bc3e25ef4..11d40e55a 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityResult.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityResult.cs @@ -9,29 +9,40 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenter public Confidence SourceConfidence { get; set; } public Resolution Resolution { get; set; } public Confidence ResolutionConfidence { get; set; } + public Modifier Modifier { get; set; } + public Confidence ModifierConfidence { get; set; } public Revision Revision { get; set; } public AugmentQualityResult(Source source, Confidence sourceConfidence, Resolution resolution, Confidence resolutionConfidence, + Modifier modifier, + Confidence modifierConfidence, Revision revision) { Source = source; SourceConfidence = sourceConfidence; Resolution = resolution; ResolutionConfidence = resolutionConfidence; + Modifier = modifier; + ModifierConfidence = modifierConfidence; Revision = revision; } public static AugmentQualityResult SourceOnly(Source source, Confidence sourceConfidence) { - return new AugmentQualityResult(source, sourceConfidence, 0, Confidence.Default, null); + return new AugmentQualityResult(source, sourceConfidence, 0, Confidence.Default, Modifier.NONE, Confidence.Default, null); } public static AugmentQualityResult ResolutionOnly(Resolution resolution, Confidence resolutionConfidence) { - return new AugmentQualityResult(Source.UNKNOWN, Confidence.Default, resolution, resolutionConfidence, null); + return new AugmentQualityResult(Source.UNKNOWN, Confidence.Default, resolution, resolutionConfidence, Modifier.NONE, Confidence.Default, null); + } + + public static AugmentQualityResult ModifierOnly(Modifier modifier, Confidence modifierConfidence) + { + return new AugmentQualityResult(Source.UNKNOWN, Confidence.Default, 0, Confidence.Default, modifier, modifierConfidence, null); } } } diff --git a/src/NzbDrone.Core/Parser/ParsingService.cs b/src/NzbDrone.Core/Parser/ParsingService.cs index 1868cfaa8..4118ac166 100644 --- a/src/NzbDrone.Core/Parser/ParsingService.cs +++ b/src/NzbDrone.Core/Parser/ParsingService.cs @@ -97,7 +97,7 @@ namespace NzbDrone.Core.Parser minimalInfo.Languages = LanguageParser.EnhanceLanguages(minimalInfo.SimpleReleaseTitle, minimalInfo.Languages); - minimalInfo.Quality.Quality = Quality.FindByInfo(minimalInfo.Quality.Source, minimalInfo.Quality.Resolution, + minimalInfo.Quality.Quality = QualityFinder.FindBySourceAndResolution(minimalInfo.Quality.Source, minimalInfo.Quality.Resolution, minimalInfo.Quality.Modifier); minimalInfo.Quality.CustomFormats = ParseCustomFormat(minimalInfo); diff --git a/src/NzbDrone.Core/Qualities/Quality.cs b/src/NzbDrone.Core/Qualities/Quality.cs index 71f0e31e1..a112e50b6 100644 --- a/src/NzbDrone.Core/Qualities/Quality.cs +++ b/src/NzbDrone.Core/Qualities/Quality.cs @@ -213,16 +213,5 @@ namespace NzbDrone.Core.Qualities { return quality.Id; } - - //TODO: Go back to fully parsing the quality from the start! - public static Quality FindByInfo(Source source, Resolution resolution, Modifier modifier) - { - return All.SingleOrDefault(q => - q.Source == source && ((q.Resolution == resolution) || - (q.Resolution == Resolution.Unknown)) && (q.Modifier == modifier)) ?? - All.FirstOrDefault(q => q.Source == source && ((q.Resolution == resolution) || - (q.Resolution == Resolution.Unknown))) ?? - Unknown; - } } } diff --git a/src/NzbDrone.Core/Qualities/QualityFinder.cs b/src/NzbDrone.Core/Qualities/QualityFinder.cs index c19b444b7..72f20f2a9 100644 --- a/src/NzbDrone.Core/Qualities/QualityFinder.cs +++ b/src/NzbDrone.Core/Qualities/QualityFinder.cs @@ -9,9 +9,9 @@ namespace NzbDrone.Core.Qualities { private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(QualityFinder)); - public static Quality FindBySourceAndResolution(Source source, Resolution resolution) + public static Quality FindBySourceAndResolution(Source source, Resolution resolution, Modifier modifer) { - var matchingQuality = Quality.All.SingleOrDefault(q => q.Source == source && q.Resolution == resolution); + var matchingQuality = Quality.All.SingleOrDefault(q => q.Source == source && q.Resolution == resolution && q.Modifier == modifer); if (matchingQuality != null) {