From 04447d9d4db8cc3d54baf0a721f4430cf77908c4 Mon Sep 17 00:00:00 2001 From: bakerboy448 <55419169+bakerboy448@users.noreply.github.com> Date: Thu, 22 Sep 2022 11:49:19 -0500 Subject: [PATCH] Fixed: Repack Preference Ignored --- .../RepackSpecificationFixture.cs | 68 +++++++++++++++++++ .../Specifications/RepackSpecification.cs | 20 +++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/RepackSpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/RepackSpecificationFixture.cs index 43f365730..d9c7d8312 100644 --- a/src/NzbDrone.Core.Test/DecisionEngineTests/RepackSpecificationFixture.cs +++ b/src/NzbDrone.Core.Test/DecisionEngineTests/RepackSpecificationFixture.cs @@ -1,9 +1,11 @@ +using System; using System.Collections.Generic; using System.Linq; using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; +using NzbDrone.Core.Configuration; using NzbDrone.Core.DecisionEngine.Specifications; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Parser.Model; @@ -172,5 +174,71 @@ public void should_return_false_if_release_group_for_release_is_unknown() .Should() .BeFalse(); } + + [Test] + public void should_return_true_when_repacks_are_not_preferred() + { + Mocker.GetMock() + .Setup(s => s.DownloadPropersAndRepacks) + .Returns(ProperDownloadTypes.DoNotPrefer); + + _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(); + + 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_when_repack_but_auto_download_repacks_is_true() + { + Mocker.GetMock() + .Setup(s => s.DownloadPropersAndRepacks) + .Returns(ProperDownloadTypes.PreferAndUpgrade); + + _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(); + + 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_false_when_repack_but_auto_download_repacks_is_false() + { + Mocker.GetMock() + .Setup(s => s.DownloadPropersAndRepacks) + .Returns(ProperDownloadTypes.DoNotUpgrade); + + _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(); + + var remoteEpisode = Builder.CreateNew() + .With(e => e.ParsedEpisodeInfo = _parsedEpisodeInfo) + .With(e => e.Episodes = _episodes) + .Build(); + + Subject.IsSatisfiedBy(remoteEpisode, null).Accepted.Should().BeFalse(); + } } } diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/RepackSpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/RepackSpecification.cs index a721a85f0..b82c7e564 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/RepackSpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/RepackSpecification.cs @@ -2,19 +2,23 @@ using System.Linq; using NLog; using NzbDrone.Common.Extensions; +using NzbDrone.Core.Configuration; using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Parser.Model; +using NzbDrone.Core.Qualities; namespace NzbDrone.Core.DecisionEngine.Specifications { public class RepackSpecification : IDecisionEngineSpecification { private readonly UpgradableSpecification _upgradableSpecification; + private readonly IConfigService _configService; private readonly Logger _logger; - public RepackSpecification(UpgradableSpecification upgradableSpecification, Logger logger) + public RepackSpecification(UpgradableSpecification upgradableSpecification, IConfigService configService, Logger logger) { _upgradableSpecification = upgradableSpecification; + _configService = configService; _logger = logger; } @@ -28,10 +32,24 @@ public Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCr return Decision.Accept(); } + var downloadPropersAndRepacks = _configService.DownloadPropersAndRepacks; + + if (downloadPropersAndRepacks == ProperDownloadTypes.DoNotPrefer) + { + _logger.Debug("Repacks are not preferred, skipping check"); + return Decision.Accept(); + } + foreach (var file in subject.Episodes.Where(c => c.EpisodeFileId != 0).Select(c => c.EpisodeFile.Value)) { if (_upgradableSpecification.IsRevisionUpgrade(file.Quality, subject.ParsedEpisodeInfo.Quality)) { + if (downloadPropersAndRepacks == ProperDownloadTypes.DoNotUpgrade) + { + _logger.Debug("Auto downloading of repacks is disabled"); + return Decision.Reject("Repack downloading is disabled"); + } + var releaseGroup = subject.ParsedEpisodeInfo.ReleaseGroup; var fileReleaseGroup = file.ReleaseGroup;