diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateQuality.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateQuality.cs index 0cd03b8a9..5f338a019 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateQuality.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateQuality.cs @@ -10,31 +10,34 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators { public class AggregateQuality : IAggregateLocalEpisode { - private readonly IEnumerable _augmentQualities; + private readonly List _augmentQualities; private readonly Logger _logger; public AggregateQuality(IEnumerable augmentQualities, Logger logger) { - _augmentQualities = augmentQualities; + _augmentQualities = augmentQualities.OrderBy(a => a.Order).ToList(); _logger = logger; } public LocalEpisode Aggregate(LocalEpisode localEpisode, DownloadClientItem downloadClientItem, bool otherFiles) { - var augmentedQualities = _augmentQualities.OrderBy(a => a.Order) - .Select(a => a.AugmentQuality(localEpisode, downloadClientItem)) - .Where(a => a != null) - .ToList(); - var source = QualitySource.Unknown; var sourceConfidence = Confidence.Default; var resolution = 0; var resolutionConfidence = Confidence.Default; var revision = new Revision(); - foreach (var augmentedQuality in augmentedQualities) + foreach (var augmentQuality in _augmentQualities) { + var augmentedQuality = augmentQuality.AugmentQuality(localEpisode, downloadClientItem); + if (augmentedQuality == null) + { + continue; + } + + _logger.Trace("Considering Source {0} ({1}) Resolution {2} ({3}) Revision {4} from {5}", augmentedQuality.Source, augmentedQuality.SourceConfidence, augmentedQuality.Resolution, augmentedQuality.ResolutionConfidence, augmentedQuality.Revision, augmentQuality.Name); + if (source == QualitySource.Unknown || augmentedQuality.SourceConfidence > sourceConfidence && augmentedQuality.Source != QualitySource.Unknown) { @@ -55,7 +58,7 @@ public LocalEpisode Aggregate(LocalEpisode localEpisode, DownloadClientItem down } } - _logger.Trace("Finding quality. Source: {0}. Resolution: {1}", source, resolution); + _logger.Trace("Selected Source {0} ({1}) Resolution {2} ({3}) Revision {4}", source, sourceConfidence, resolution, resolutionConfidence, revision); var quality = new QualityModel(QualityFinder.FindBySourceAndResolution(source, resolution), revision); diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromDownloadClientItem.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromDownloadClientItem.cs index 6b7288c17..fdb47d2fa 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromDownloadClientItem.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromDownloadClientItem.cs @@ -7,6 +7,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators.Augment public class AugmentQualityFromDownloadClientItem : IAugmentQuality { public int Order => 3; + public string Name => "DownloadClientItem"; public AugmentQualityResult AugmentQuality(LocalEpisode localEpisode, DownloadClientItem downloadClientItem) { diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromFileName.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromFileName.cs index 9ed47d715..0a88217fd 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromFileName.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromFileName.cs @@ -7,6 +7,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators.Augment public class AugmentQualityFromFileName : IAugmentQuality { public int Order => 1; + public string Name => "FileName"; public AugmentQualityResult AugmentQuality(LocalEpisode localEpisode, DownloadClientItem downloadClientItem) { diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromFolder.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromFolder.cs index 6594e6e8f..f1006c3f7 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromFolder.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromFolder.cs @@ -7,6 +7,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators.Augment public class AugmentQualityFromFolder : IAugmentQuality { public int Order => 2; + public string Name => "FolderName"; public AugmentQualityResult AugmentQuality(LocalEpisode localEpisode, DownloadClientItem downloadClientItem) { diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromMediaInfo.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromMediaInfo.cs index b728d0ddb..ece9a4e1a 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromMediaInfo.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromMediaInfo.cs @@ -1,3 +1,4 @@ +using NLog; using NzbDrone.Core.Download; using NzbDrone.Core.Parser.Model; @@ -5,7 +6,15 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators.Augment { public class AugmentQualityFromMediaInfo : IAugmentQuality { + private readonly Logger _logger; + public int Order => 4; + public string Name => "MediaInfo"; + + public AugmentQualityFromMediaInfo(Logger logger) + { + _logger = logger; + } public AugmentQualityResult AugmentQuality(LocalEpisode localEpisode, DownloadClientItem downloadClientItem) { @@ -15,27 +24,35 @@ public AugmentQualityResult AugmentQuality(LocalEpisode localEpisode, DownloadCl } var width = localEpisode.MediaInfo.Width; + var height = localEpisode.MediaInfo.Height; - if (width >= 3200) + + if (width >= 3200 || height >= 2100) { + _logger.Trace("Resolution {0}x{1} considered 2160p", width, height); return AugmentQualityResult.ResolutionOnly(2160, Confidence.MediaInfo); } - if (width >= 1800) + if (width >= 1800 || height >= 1000) { + _logger.Trace("Resolution {0}x{1} considered 1080p", width, height); return AugmentQualityResult.ResolutionOnly(1080, Confidence.MediaInfo); } - if (width >= 1200) + if (width >= 1200 || height >= 700) { + _logger.Trace("Resolution {0}x{1} considered 720p", width, height); return AugmentQualityResult.ResolutionOnly(720, Confidence.MediaInfo); } - if (width > 0) + if (width > 0 || height > 0) { + _logger.Trace("Resolution {0}x{1} considered 480p", width, height); return AugmentQualityResult.ResolutionOnly(480, Confidence.MediaInfo); } + _logger.Trace("Resolution {0}x{1}", width, height); + return null; } } diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromReleaseName.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromReleaseName.cs index f6bcc1dae..653dc1f2b 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromReleaseName.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityFromReleaseName.cs @@ -9,6 +9,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators.Augment public class AugmentQualityFromReleaseName : IAugmentQuality { public int Order => 5; + public string Name => "ReleaseName"; private readonly IDownloadHistoryService _downloadHistoryService; diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityResult.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityResult.cs index 885d90cca..3285ddfad 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityResult.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/AugmentQualityResult.cs @@ -4,6 +4,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators.Augment { public class AugmentQualityResult { + public string Name { get; set; } public QualitySource Source { get; set; } public Confidence SourceConfidence { get; set; } public int Resolution { get; set; } diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/IAugmentQuality.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/IAugmentQuality.cs index a8b722320..e4f20eff2 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/IAugmentQuality.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Quality/IAugmentQuality.cs @@ -6,6 +6,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators.Augment public interface IAugmentQuality { int Order { get; } + string Name { get; } AugmentQualityResult AugmentQuality(LocalEpisode localEpisode, DownloadClientItem downloadClientItem); } }