mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-14 11:23:42 +02:00
parent
1b3acb52f1
commit
e70d92f670
@ -0,0 +1,106 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class RepackSpecificationFixture : CoreTest<RepackSpecification>
|
||||
{
|
||||
private ParsedEpisodeInfo _parsedEpisodeInfo;
|
||||
private List<Episode> _episodes;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_parsedEpisodeInfo = Builder<ParsedEpisodeInfo>.CreateNew()
|
||||
.With(p => p.Quality = new QualityModel(Quality.SDTV,
|
||||
new Revision(2, 0, false)))
|
||||
.With(p => p.ReleaseGroup = "Sonarr")
|
||||
.Build();
|
||||
|
||||
_episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 0)
|
||||
.BuildList();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_it_is_not_a_repack()
|
||||
{
|
||||
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_there_are_is_no_episode_file()
|
||||
{
|
||||
_parsedEpisodeInfo.Quality.Revision.IsRepack = true;
|
||||
|
||||
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.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_false_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.ReleaseGroup = "NotSonarr")
|
||||
.Build();
|
||||
|
||||
var remoteEpisode = Builder<RemoteEpisode>.CreateNew()
|
||||
.With(e => e.ParsedEpisodeInfo = _parsedEpisodeInfo)
|
||||
.With(e => e.Episodes = _episodes)
|
||||
.Build();
|
||||
|
||||
Subject.IsSatisfiedBy(remoteEpisode, null)
|
||||
.Accepted
|
||||
.Should()
|
||||
.BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
@ -159,6 +159,7 @@
|
||||
<Compile Include="Datastore\SqliteSchemaDumperTests\SqliteSchemaDumperFixture.cs" />
|
||||
<Compile Include="DecisionEngineTests\AcceptableSizeSpecificationFixture.cs" />
|
||||
<Compile Include="DecisionEngineTests\AnimeVersionUpgradeSpecificationFixture.cs" />
|
||||
<Compile Include="DecisionEngineTests\RepackSpecificationFixture.cs" />
|
||||
<Compile Include="DecisionEngineTests\MultiSeasonSpecificationFixture.cs" />
|
||||
<Compile Include="DecisionEngineTests\UpgradeAllowedSpecificationFixture .cs" />
|
||||
<Compile Include="DecisionEngineTests\FullSeasonSpecificationFixture.cs" />
|
||||
|
@ -374,6 +374,16 @@ public void should_parse_quality_from_extension(string title)
|
||||
QualityParser.ParseQuality(title).QualityDetectionSource.Should().Be(QualityDetectionSource.Extension);
|
||||
}
|
||||
|
||||
[TestCase("Series Title S04E87 REPACK 720p HDTV x264 aAF", true)]
|
||||
[TestCase("Series.Title.S04E87.REPACK.720p.HDTV.x264-aAF", true)]
|
||||
[TestCase("Series.Title.S04E87.PROPER.720p.HDTV.x264-aAF", false)]
|
||||
public void should_be_able_to_parse_repack(string title, bool isRepack)
|
||||
{
|
||||
var result = QualityParser.ParseQuality(title);
|
||||
result.Revision.Version.Should().Be(2);
|
||||
result.Revision.IsRepack.Should().Be(isRepack);
|
||||
}
|
||||
|
||||
private void ParseAndVerifyQuality(string title, Quality quality, bool proper)
|
||||
{
|
||||
var result = QualityParser.ParseQuality(title);
|
||||
|
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
public class RepackSpecification : IDecisionEngineSpecification
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
public RepackSpecification(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public SpecificationPriority Priority => SpecificationPriority.Database;
|
||||
public RejectionType Type => RejectionType.Permanent;
|
||||
|
||||
public Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
|
||||
{
|
||||
if (!subject.ParsedEpisodeInfo.Quality.Revision.IsRepack)
|
||||
{
|
||||
return Decision.Accept();
|
||||
}
|
||||
|
||||
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.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);
|
||||
}
|
||||
}
|
||||
|
||||
return Decision.Accept();
|
||||
}
|
||||
}
|
||||
}
|
@ -145,6 +145,7 @@
|
||||
<Compile Include="CustomFilters\CustomFilterService.cs" />
|
||||
<Compile Include="Datastore\Migration\127_rename_release_profiles.cs" />
|
||||
<Compile Include="Datastore\Migration\126_add_custom_filters.cs" />
|
||||
<Compile Include="DecisionEngine\Specifications\RepackSpecification.cs" />
|
||||
<Compile Include="DecisionEngine\Specifications\MultiSeasonSpecification.cs" />
|
||||
<Compile Include="DecisionEngine\Specifications\UpgradeAllowedSpecification.cs" />
|
||||
<Compile Include="Exceptions\DownloadClientRejectedReleaseException.cs" />
|
||||
|
@ -32,9 +32,12 @@ public class QualityParser
|
||||
private static readonly Regex RawHDRegex = new Regex(@"\b(?<rawhd>RawHD|1080i[-_. ]HDTV|Raw[-_. ]HD|MPEG[-_. ]?2)\b",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
private static readonly Regex ProperRegex = new Regex(@"\b(?<proper>proper|repack|rerip)\b",
|
||||
private static readonly Regex ProperRegex = new Regex(@"\b(?<proper>proper|rerip)\b",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
private static readonly Regex RepackRegex = new Regex(@"\b(?<repack>repack)\b",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
private static readonly Regex VersionRegex = new Regex(@"\dv(?<version>\d)\b|\[v(?<version>\d)\]",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
@ -425,6 +428,12 @@ private static QualityModel ParseQualityModifiers(string name, string normalized
|
||||
result.Revision.Version = 2;
|
||||
}
|
||||
|
||||
if (RepackRegex.IsMatch(normalizedName))
|
||||
{
|
||||
result.Revision.Version = 2;
|
||||
result.Revision.IsRepack = true;
|
||||
}
|
||||
|
||||
var versionRegexResult = VersionRegex.Match(normalizedName);
|
||||
|
||||
if (versionRegexResult.Success)
|
||||
@ -433,7 +442,7 @@ private static QualityModel ParseQualityModifiers(string name, string normalized
|
||||
}
|
||||
|
||||
// TODO: re-enable this when we have a reliable way to determine real
|
||||
// TODO: Only treat it as a real if it comes AFTER the season/epsiode number
|
||||
// TODO: Only treat it as a real if it comes AFTER the season/episode number
|
||||
var realRegexResult = RealRegex.Matches(name);
|
||||
|
||||
if (realRegexResult.Count > 0)
|
||||
|
@ -9,14 +9,16 @@ private Revision()
|
||||
{
|
||||
}
|
||||
|
||||
public Revision(int version = 1, int real = 0)
|
||||
public Revision(int version = 1, int real = 0, bool isRepack = false)
|
||||
{
|
||||
Version = version;
|
||||
Real = real;
|
||||
IsRepack = isRepack;
|
||||
}
|
||||
|
||||
public int Version { get; set; }
|
||||
public int Real { get; set; }
|
||||
public bool IsRepack { get; set; }
|
||||
|
||||
public bool Equals(Revision other)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user