From 6a6d6f9e0dd17cc74592192ef0de01a3cb95452b Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 8 May 2019 21:04:12 -0700 Subject: [PATCH] Fixed: Importing of preferred release over a proper/repack --- .../UpgradeSpecificationFixture.cs | 45 ++++++++++++++++++- .../Specifications/UpgradeSpecification.cs | 37 ++++++++++----- 2 files changed, 69 insertions(+), 13 deletions(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/UpgradeSpecificationFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/UpgradeSpecificationFixture.cs index 3119f5776..72eb0101b 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/UpgradeSpecificationFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/UpgradeSpecificationFixture.cs @@ -3,6 +3,7 @@ using FluentAssertions; using Marr.Data; using NUnit.Framework; +using NzbDrone.Core.Configuration; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications; using NzbDrone.Core.Parser.Model; @@ -126,7 +127,6 @@ public void should_return_false_if_language_upgrade_for_existing_episodeFile_and Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse(); } - [Test] public void should_return_true_if_upgrade_for_existing_episodeFile_for_multi_episodes() { @@ -180,7 +180,6 @@ public void should_return_false_if_language_upgrade_for_existing_episodeFile_for Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse(); } - [Test] public void should_return_false_if_not_an_upgrade_for_existing_episodeFile() { @@ -238,5 +237,47 @@ public void should_return_false_if_not_an_upgrade_for_one_existing_episodeFile_f Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse(); } + + [Test] + public void should_return_false_if_not_a_revision_upgrade_and_prefers_propers() + { + Mocker.GetMock() + .Setup(s => s.DownloadPropersAndRepacks) + .Returns(ProperDownloadTypes.PreferAndUpgrade); + + _localEpisode.Episodes = Builder.CreateListOfSize(1) + .All() + .With(e => e.EpisodeFileId = 1) + .With(e => e.EpisodeFile = new LazyLoaded( + new EpisodeFile + { + Quality = new QualityModel(Quality.HDTV720p, new Revision(version: 2)) + })) + .Build() + .ToList(); + + Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse(); + } + + [Test] + public void should_return_true_if_not_a_revision_upgrade_and_does_not_prefer_propers() + { + Mocker.GetMock() + .Setup(s => s.DownloadPropersAndRepacks) + .Returns(ProperDownloadTypes.DoNotPrefer); + + _localEpisode.Episodes = Builder.CreateListOfSize(1) + .All() + .With(e => e.EpisodeFileId = 1) + .With(e => e.EpisodeFile = new LazyLoaded( + new EpisodeFile + { + Quality = new QualityModel(Quality.HDTV720p, new Revision(version: 2)) + })) + .Build() + .ToList(); + + Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue(); + } } } diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/UpgradeSpecification.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/UpgradeSpecification.cs index 03bdca940..156c0ab74 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/UpgradeSpecification.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/UpgradeSpecification.cs @@ -1,5 +1,6 @@ using System.Linq; using NLog; +using NzbDrone.Core.Configuration; using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.Download; using NzbDrone.Core.Parser.Model; @@ -10,30 +11,44 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications { public class UpgradeSpecification : IImportDecisionEngineSpecification { + private readonly IConfigService _configService; private readonly Logger _logger; - public UpgradeSpecification(Logger logger) + public UpgradeSpecification(IConfigService configService, Logger logger) { + _configService = configService; _logger = logger; } public Decision IsSatisfiedBy(LocalEpisode localEpisode, DownloadClientItem downloadClientItem) { + var downloadPropersAndRepacks = _configService.DownloadPropersAndRepacks; var qualityComparer = new QualityModelComparer(localEpisode.Series.QualityProfile); var languageComparer = new LanguageComparer(localEpisode.Series.LanguageProfile); - - if (localEpisode.Episodes.Any(e => e.EpisodeFileId != 0 && qualityComparer.Compare(e.EpisodeFile.Value.Quality, localEpisode.Quality) > 0)) - { - _logger.Debug("This file isn't a quality upgrade for all episodes. Skipping {0}", localEpisode.Path); - return Decision.Reject("Not an upgrade for existing episode file(s)"); - } - - if (localEpisode.Episodes.Any(e => e.EpisodeFileId != 0 && - languageComparer.Compare(e.EpisodeFile.Value.Language, localEpisode.Language) > 0 && - qualityComparer.Compare(e.EpisodeFile.Value.Quality, localEpisode.Quality) == 0)) + + foreach (var episode in localEpisode.Episodes.Where(e => e.EpisodeFileId > 0)) { + var episodeFile = episode.EpisodeFile.Value; + var qualityCompare = qualityComparer.Compare(localEpisode.Quality.Quality, episodeFile.Quality.Quality); + + if (qualityCompare < 0) + { + _logger.Debug("This file isn't a quality upgrade for all episodes. Skipping {0}", localEpisode.Path); + return Decision.Reject("Not an upgrade for existing episode file(s)"); + } + + if (downloadPropersAndRepacks != ProperDownloadTypes.DoNotPrefer && + localEpisode.Quality.Revision.CompareTo(episodeFile.Quality.Revision) < 0) + { + _logger.Debug("This file isn't a quality upgrade for all episodes. Skipping {0}", localEpisode.Path); + return Decision.Reject("Not an upgrade for existing episode file(s)"); + } + + if (languageComparer.Compare(localEpisode.Language, episodeFile.Language) < 0 && qualityCompare == 0) + { _logger.Debug("This file isn't a language upgrade for all episodes. Skipping {0}", localEpisode.Path); return Decision.Reject("Not an upgrade for existing episode file(s)"); + } } return Decision.Accept();