Only check repacks for revision upgrades

This commit is contained in:
Mark McDowall 2019-05-05 20:39:52 -07:00
parent d8c2640959
commit d8baa93289
4 changed files with 54 additions and 18 deletions

View File

@ -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;

View File

@ -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<UpgradableSpecification>();
_parsedEpisodeInfo = Builder<ParsedEpisodeInfo>.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<EpisodeFile>.CreateNew()
.With(e => e.Quality = new QualityModel(Quality.DVD))
.With(e => e.ReleaseGroup = "Sonarr")
.Build();
var remoteEpisode = Builder<RemoteEpisode>.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<EpisodeFile>.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<EpisodeFile>.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<EpisodeFile>.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<EpisodeFile>.CreateNew()
.With(e => e.Quality = new QualityModel(Quality.SDTV))
.With(e => e.ReleaseGroup = "Sonarr")
.Build();

View File

@ -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;
}

View File

@ -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);
}
}
}