Fixed: Skip anime version upgrade check if Proper/Repacks are not preferred

Closes #4468
This commit is contained in:
Mark McDowall 2022-12-11 18:01:51 -08:00
parent e42edf1d33
commit 8bea8a10da
2 changed files with 28 additions and 1 deletions

View File

@ -2,6 +2,7 @@ using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Parser.Model;
@ -21,6 +22,10 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[SetUp]
public void Setup()
{
Mocker.GetMock<IConfigService>()
.Setup(s => s.DownloadPropersAndRepacks)
.Returns(ProperDownloadTypes.PreferAndUpgrade);
Mocker.Resolve<UpgradableSpecification>();
_subject = Mocker.Resolve<AnimeVersionUpgradeSpecification>();
@ -104,5 +109,15 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{
_subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeFalse();
}
[Test]
public void should_return_true_when_repacks_are_not_preferred()
{
Mocker.GetMock<IConfigService>()
.Setup(s => s.DownloadPropersAndRepacks)
.Returns(ProperDownloadTypes.DoNotPrefer);
_subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeFalse();
}
}
}

View File

@ -1,8 +1,10 @@
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;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.DecisionEngine.Specifications
@ -10,11 +12,13 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
public class AnimeVersionUpgradeSpecification : IDecisionEngineSpecification
{
private readonly UpgradableSpecification _upgradableSpecification;
private readonly IConfigService _configService;
private readonly Logger _logger;
public AnimeVersionUpgradeSpecification(UpgradableSpecification upgradableSpecification, Logger logger)
public AnimeVersionUpgradeSpecification(UpgradableSpecification upgradableSpecification, IConfigService configService, Logger logger)
{
_upgradableSpecification = upgradableSpecification;
_configService = configService;
_logger = logger;
}
@ -30,6 +34,14 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
return Decision.Accept();
}
var downloadPropersAndRepacks = _configService.DownloadPropersAndRepacks;
if (downloadPropersAndRepacks == ProperDownloadTypes.DoNotPrefer)
{
_logger.Debug("Version upgrades 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 (file == null)