mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-14 11:23:42 +02:00
Only check repacks for revision upgrades
This commit is contained in:
parent
d8c2640959
commit
d8baa93289
@ -3,7 +3,6 @@
|
||||
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;
|
||||
|
@ -2,6 +2,7 @@
|
||||
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 @@ public class RepackSpecificationFixture : CoreTest<RepackSpecification>
|
||||
[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 @@ public void should_return_true_if_there_are_is_no_episode_file()
|
||||
.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 @@ public void should_return_false_if_is_a_repack_for_a_different_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 = "NotSonarr")
|
||||
.Build();
|
||||
|
||||
@ -109,6 +135,7 @@ public void should_return_false_if_release_group_for_existing_file_is_unknown()
|
||||
_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 @@ public void should_return_false_if_release_group_for_release_is_unknown()
|
||||
|
||||
_episodes.First().EpisodeFileId = 1;
|
||||
_episodes.First().EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
||||
.With(e => e.Quality = new QualityModel(Quality.SDTV))
|
||||
.With(e => e.ReleaseGroup = "Sonarr")
|
||||
.Build();
|
||||
|
||||
|
@ -12,9 +12,9 @@ public class AnimeVersionUpgradeSpecification : IDecisionEngineSpecification
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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 @@ public Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCr
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user