From d8baa93289aa84cbc49dd9d59be2cfb44bb64f18 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 5 May 2019 20:39:52 -0700 Subject: [PATCH] Only check repacks for revision upgrades --- ...AnimeVersionUpgradeSpecificationFixture.cs | 1 - .../RepackSpecificationFixture.cs | 28 +++++++++++++ .../AnimeVersionUpgradeSpecification.cs | 4 +- .../Specifications/RepackSpecification.cs | 39 ++++++++++++------- 4 files changed, 54 insertions(+), 18 deletions(-) diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/AnimeVersionUpgradeSpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/AnimeVersionUpgradeSpecificationFixture.cs index f8a1a407c..0b69b5252 100644 --- a/src/NzbDrone.Core.Test/DecisionEngineTests/AnimeVersionUpgradeSpecificationFixture.cs +++ b/src/NzbDrone.Core.Test/DecisionEngineTests/AnimeVersionUpgradeSpecificationFixture.cs @@ -3,7 +3,6 @@ using FizzWare.NBuilder; using FluentAssertions; using Marr.Data; using NUnit.Framework; -using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.DecisionEngine.Specifications; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Parser.Model; diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/RepackSpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/RepackSpecificationFixture.cs index d5f329552..1fe7fff7d 100644 --- a/src/NzbDrone.Core.Test/DecisionEngineTests/RepackSpecificationFixture.cs +++ b/src/NzbDrone.Core.Test/DecisionEngineTests/RepackSpecificationFixture.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using FizzWare.NBuilder; using FluentAssertions; +using Moq; using NUnit.Framework; using NzbDrone.Core.Qualities; using NzbDrone.Core.DecisionEngine.Specifications; @@ -21,6 +22,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [SetUp] public void Setup() { + Mocker.Resolve(); + _parsedEpisodeInfo = Builder.CreateNew() .With(p => p.Quality = new QualityModel(Quality.SDTV, new Revision(2, 0, false))) @@ -63,12 +66,34 @@ namespace NzbDrone.Core.Test.DecisionEngineTests .BeTrue(); } + [Test] + public void should_return_true_if_is_a_repack_for_a_different_quality() + { + _parsedEpisodeInfo.Quality.Revision.IsRepack = true; + _episodes.First().EpisodeFileId = 1; + _episodes.First().EpisodeFile = Builder.CreateNew() + .With(e => e.Quality = new QualityModel(Quality.DVD)) + .With(e => e.ReleaseGroup = "Sonarr") + .Build(); + + var remoteEpisode = Builder.CreateNew() + .With(e => e.ParsedEpisodeInfo = _parsedEpisodeInfo) + .With(e => e.Episodes = _episodes) + .Build(); + + Subject.IsSatisfiedBy(remoteEpisode, null) + .Accepted + .Should() + .BeTrue(); + } + [Test] public void should_return_true_if_is_a_repack_for_existing_file() { _parsedEpisodeInfo.Quality.Revision.IsRepack = true; _episodes.First().EpisodeFileId = 1; _episodes.First().EpisodeFile = Builder.CreateNew() + .With(e => e.Quality = new QualityModel(Quality.SDTV)) .With(e => e.ReleaseGroup = "Sonarr") .Build(); @@ -89,6 +114,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests _parsedEpisodeInfo.Quality.Revision.IsRepack = true; _episodes.First().EpisodeFileId = 1; _episodes.First().EpisodeFile = Builder.CreateNew() + .With(e => e.Quality = new QualityModel(Quality.SDTV)) .With(e => e.ReleaseGroup = "NotSonarr") .Build(); @@ -109,6 +135,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests _parsedEpisodeInfo.Quality.Revision.IsRepack = true; _episodes.First().EpisodeFileId = 1; _episodes.First().EpisodeFile = Builder.CreateNew() + .With(e => e.Quality = new QualityModel(Quality.SDTV)) .With(e => e.ReleaseGroup = "") .Build(); @@ -131,6 +158,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests _episodes.First().EpisodeFileId = 1; _episodes.First().EpisodeFile = Builder.CreateNew() + .With(e => e.Quality = new QualityModel(Quality.SDTV)) .With(e => e.ReleaseGroup = "Sonarr") .Build(); diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/AnimeVersionUpgradeSpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/AnimeVersionUpgradeSpecification.cs index 7d687c1aa..82dcd6f42 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/AnimeVersionUpgradeSpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/AnimeVersionUpgradeSpecification.cs @@ -12,9 +12,9 @@ namespace NzbDrone.Core.DecisionEngine.Specifications private readonly UpgradableSpecification _upgradableSpecification; private readonly Logger _logger; - public AnimeVersionUpgradeSpecification(UpgradableSpecification UpgradableSpecification, Logger logger) + public AnimeVersionUpgradeSpecification(UpgradableSpecification upgradableSpecification, Logger logger) { - _upgradableSpecification = UpgradableSpecification; + _upgradableSpecification = upgradableSpecification; _logger = logger; } diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/RepackSpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/RepackSpecification.cs index f5fece28f..531b67d50 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/RepackSpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/RepackSpecification.cs @@ -9,10 +9,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications { public class RepackSpecification : IDecisionEngineSpecification { + private readonly UpgradableSpecification _upgradableSpecification; private readonly Logger _logger; - public RepackSpecification(Logger logger) + public RepackSpecification(UpgradableSpecification upgradableSpecification, Logger logger) { + _upgradableSpecification = upgradableSpecification; _logger = logger; } @@ -28,23 +30,30 @@ namespace NzbDrone.Core.DecisionEngine.Specifications foreach (var file in subject.Episodes.Where(c => c.EpisodeFileId != 0).Select(c => c.EpisodeFile.Value)) { - var releaseGroup = subject.ParsedEpisodeInfo.ReleaseGroup; - var fileReleaseGroup = file.ReleaseGroup; - - if (fileReleaseGroup.IsNullOrWhiteSpace()) + if (_upgradableSpecification.IsRevisionUpgrade(file.Quality, subject.ParsedEpisodeInfo.Quality)) { - return Decision.Reject("Unable to determine release group for the existing file"); - } + var releaseGroup = subject.ParsedEpisodeInfo.ReleaseGroup; + var fileReleaseGroup = file.ReleaseGroup; - if (releaseGroup.IsNullOrWhiteSpace()) - { - return Decision.Reject("Unable to determine release group for this release"); - } + if (fileReleaseGroup.IsNullOrWhiteSpace()) + { + return Decision.Reject("Unable to determine release group for the existing file"); + } - if (!fileReleaseGroup.Equals(releaseGroup, StringComparison.InvariantCultureIgnoreCase)) - { - _logger.Debug("Release is a repack for a different release group. Release Group: {0}. File release group: {0}", releaseGroup, fileReleaseGroup); - return Decision.Reject("Release is a repack for a different release group. Release Group: {0}. File release group: {0}", releaseGroup, fileReleaseGroup); + if (releaseGroup.IsNullOrWhiteSpace()) + { + return Decision.Reject("Unable to determine release group for this release"); + } + + if (!fileReleaseGroup.Equals(releaseGroup, StringComparison.InvariantCultureIgnoreCase)) + { + _logger.Debug( + "Release is a repack for a different release group. Release Group: {0}. File release group: {0}", + releaseGroup, fileReleaseGroup); + return Decision.Reject( + "Release is a repack for a different release group. Release Group: {0}. File release group: {0}", + releaseGroup, fileReleaseGroup); + } } }