Only check repacks for revision upgrades
This commit is contained in:
parent
d8c2640959
commit
d8baa93289
|
@ -3,7 +3,6 @@ using FizzWare.NBuilder;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Marr.Data;
|
using Marr.Data;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.DecisionEngine;
|
|
||||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||||
using NzbDrone.Core.MediaFiles;
|
using NzbDrone.Core.MediaFiles;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
|
|
@ -2,6 +2,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FizzWare.NBuilder;
|
using FizzWare.NBuilder;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Qualities;
|
using NzbDrone.Core.Qualities;
|
||||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||||
|
@ -21,6 +22,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
|
Mocker.Resolve<UpgradableSpecification>();
|
||||||
|
|
||||||
_parsedEpisodeInfo = Builder<ParsedEpisodeInfo>.CreateNew()
|
_parsedEpisodeInfo = Builder<ParsedEpisodeInfo>.CreateNew()
|
||||||
.With(p => p.Quality = new QualityModel(Quality.SDTV,
|
.With(p => p.Quality = new QualityModel(Quality.SDTV,
|
||||||
new Revision(2, 0, false)))
|
new Revision(2, 0, false)))
|
||||||
|
@ -63,12 +66,34 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||||
.BeTrue();
|
.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]
|
[Test]
|
||||||
public void should_return_true_if_is_a_repack_for_existing_file()
|
public void should_return_true_if_is_a_repack_for_existing_file()
|
||||||
{
|
{
|
||||||
_parsedEpisodeInfo.Quality.Revision.IsRepack = true;
|
_parsedEpisodeInfo.Quality.Revision.IsRepack = true;
|
||||||
_episodes.First().EpisodeFileId = 1;
|
_episodes.First().EpisodeFileId = 1;
|
||||||
_episodes.First().EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
_episodes.First().EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
||||||
|
.With(e => e.Quality = new QualityModel(Quality.SDTV))
|
||||||
.With(e => e.ReleaseGroup = "Sonarr")
|
.With(e => e.ReleaseGroup = "Sonarr")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
@ -89,6 +114,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||||
_parsedEpisodeInfo.Quality.Revision.IsRepack = true;
|
_parsedEpisodeInfo.Quality.Revision.IsRepack = true;
|
||||||
_episodes.First().EpisodeFileId = 1;
|
_episodes.First().EpisodeFileId = 1;
|
||||||
_episodes.First().EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
_episodes.First().EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
||||||
|
.With(e => e.Quality = new QualityModel(Quality.SDTV))
|
||||||
.With(e => e.ReleaseGroup = "NotSonarr")
|
.With(e => e.ReleaseGroup = "NotSonarr")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
@ -109,6 +135,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||||
_parsedEpisodeInfo.Quality.Revision.IsRepack = true;
|
_parsedEpisodeInfo.Quality.Revision.IsRepack = true;
|
||||||
_episodes.First().EpisodeFileId = 1;
|
_episodes.First().EpisodeFileId = 1;
|
||||||
_episodes.First().EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
_episodes.First().EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
||||||
|
.With(e => e.Quality = new QualityModel(Quality.SDTV))
|
||||||
.With(e => e.ReleaseGroup = "")
|
.With(e => e.ReleaseGroup = "")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
@ -131,6 +158,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||||
|
|
||||||
_episodes.First().EpisodeFileId = 1;
|
_episodes.First().EpisodeFileId = 1;
|
||||||
_episodes.First().EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
_episodes.First().EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
||||||
|
.With(e => e.Quality = new QualityModel(Quality.SDTV))
|
||||||
.With(e => e.ReleaseGroup = "Sonarr")
|
.With(e => e.ReleaseGroup = "Sonarr")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,9 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||||
private readonly UpgradableSpecification _upgradableSpecification;
|
private readonly UpgradableSpecification _upgradableSpecification;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public AnimeVersionUpgradeSpecification(UpgradableSpecification UpgradableSpecification, Logger logger)
|
public AnimeVersionUpgradeSpecification(UpgradableSpecification upgradableSpecification, Logger logger)
|
||||||
{
|
{
|
||||||
_upgradableSpecification = UpgradableSpecification;
|
_upgradableSpecification = upgradableSpecification;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||||
{
|
{
|
||||||
public class RepackSpecification : IDecisionEngineSpecification
|
public class RepackSpecification : IDecisionEngineSpecification
|
||||||
{
|
{
|
||||||
|
private readonly UpgradableSpecification _upgradableSpecification;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public RepackSpecification(Logger logger)
|
public RepackSpecification(UpgradableSpecification upgradableSpecification, Logger logger)
|
||||||
{
|
{
|
||||||
|
_upgradableSpecification = upgradableSpecification;
|
||||||
_logger = logger;
|
_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))
|
foreach (var file in subject.Episodes.Where(c => c.EpisodeFileId != 0).Select(c => c.EpisodeFile.Value))
|
||||||
{
|
{
|
||||||
var releaseGroup = subject.ParsedEpisodeInfo.ReleaseGroup;
|
if (_upgradableSpecification.IsRevisionUpgrade(file.Quality, subject.ParsedEpisodeInfo.Quality))
|
||||||
var fileReleaseGroup = file.ReleaseGroup;
|
|
||||||
|
|
||||||
if (fileReleaseGroup.IsNullOrWhiteSpace())
|
|
||||||
{
|
{
|
||||||
return Decision.Reject("Unable to determine release group for the existing file");
|
var releaseGroup = subject.ParsedEpisodeInfo.ReleaseGroup;
|
||||||
}
|
var fileReleaseGroup = file.ReleaseGroup;
|
||||||
|
|
||||||
if (releaseGroup.IsNullOrWhiteSpace())
|
if (fileReleaseGroup.IsNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
return Decision.Reject("Unable to determine release group for this release");
|
return Decision.Reject("Unable to determine release group for the existing file");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fileReleaseGroup.Equals(releaseGroup, StringComparison.InvariantCultureIgnoreCase))
|
if (releaseGroup.IsNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
_logger.Debug("Release is a repack for a different release group. Release Group: {0}. File release group: {0}", releaseGroup, fileReleaseGroup);
|
return Decision.Reject("Unable to determine release group for this release");
|
||||||
return Decision.Reject("Release is a repack for a different release group. Release Group: {0}. File release group: {0}", releaseGroup, fileReleaseGroup);
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue