mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
NzbRestrictions are now used, no more allowed release groups
This commit is contained in:
parent
244d3a8a58
commit
8bb4b06d28
@ -1,58 +0,0 @@
|
|||||||
using FluentAssertions;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using NzbDrone.Core.Configuration;
|
|
||||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
|
||||||
using NzbDrone.Core.Parser.Model;
|
|
||||||
using NzbDrone.Core.Test.Framework;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
public class AllowedReleaseGroupSpecificationFixture : CoreTest<AllowedReleaseGroupSpecification>
|
|
||||||
{
|
|
||||||
private RemoteEpisode _parseResult;
|
|
||||||
|
|
||||||
[SetUp]
|
|
||||||
public void Setup()
|
|
||||||
{
|
|
||||||
_parseResult = new RemoteEpisode
|
|
||||||
{
|
|
||||||
Report = new ReportInfo
|
|
||||||
{
|
|
||||||
ReleaseGroup = "2HD"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_be_true_when_allowedReleaseGroups_is_empty()
|
|
||||||
{
|
|
||||||
|
|
||||||
Subject.IsSatisfiedBy(_parseResult).Should().BeTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_be_true_when_allowedReleaseGroups_is_nzbs_releaseGroup()
|
|
||||||
{
|
|
||||||
Subject.IsSatisfiedBy(_parseResult).Should().BeTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestCase("2HD")]
|
|
||||||
[TestCase("2hd")]
|
|
||||||
[TestCase("other, 2hd, next")]
|
|
||||||
[TestCase("other,2hd,next")]
|
|
||||||
[TestCase("other,2hd,next,")]
|
|
||||||
public void should_be_true_when_allowedReleaseGroups_contains_nzbs_releaseGroup(string allowedList)
|
|
||||||
{
|
|
||||||
Mocker.GetMock<IConfigService>().SetupGet(c => c.AllowedReleaseGroups).Returns(allowedList);
|
|
||||||
Subject.IsSatisfiedBy(_parseResult).Should().BeTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_be_false_when_allowedReleaseGroups_does_not_contain_nzbs_releaseGroup()
|
|
||||||
{
|
|
||||||
Mocker.GetMock<IConfigService>().SetupGet(c => c.AllowedReleaseGroups).Returns("other");
|
|
||||||
Subject.IsSatisfiedBy(_parseResult).Should().BeFalse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,51 @@
|
|||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class NotRestrictedNzbSpecificationFixture : CoreTest<NotRestrictedNzbSpecification>
|
||||||
|
{
|
||||||
|
private RemoteEpisode _parseResult;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_parseResult = new RemoteEpisode
|
||||||
|
{
|
||||||
|
Report = new ReportInfo
|
||||||
|
{
|
||||||
|
Title = "Dexter.S08E01.EDITED.WEBRip.x264-KYR"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_be_true_when_restrictions_are_empty()
|
||||||
|
{
|
||||||
|
Subject.IsSatisfiedBy(_parseResult).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("KYR")]
|
||||||
|
[TestCase("EDITED")]
|
||||||
|
[TestCase("2HD\nKYR")]
|
||||||
|
public void should_be_false_when_nzb_contains_a_restricted_term(string restrictions)
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IConfigService>().SetupGet(c => c.NzbRestrictions).Returns(restrictions);
|
||||||
|
Subject.IsSatisfiedBy(_parseResult).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("NotReal")]
|
||||||
|
[TestCase("LoL")]
|
||||||
|
[TestCase("Hello\nWorld")]
|
||||||
|
public void should_be_true_when_nzb_does_not_contain_a_restricted_term(string restrictions)
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IConfigService>().SetupGet(c => c.NzbRestrictions).Returns(restrictions);
|
||||||
|
Subject.IsSatisfiedBy(_parseResult).Should().BeTrue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -124,6 +124,7 @@
|
|||||||
<Compile Include="Datastore\PagingSpecExtenstionsTests\ToSortDirectionFixture.cs" />
|
<Compile Include="Datastore\PagingSpecExtenstionsTests\ToSortDirectionFixture.cs" />
|
||||||
<Compile Include="Datastore\PagingSpecExtenstionsTests\PagingOffsetFixture.cs" />
|
<Compile Include="Datastore\PagingSpecExtenstionsTests\PagingOffsetFixture.cs" />
|
||||||
<Compile Include="Datastore\ReflectionStrategyFixture\Benchmarks.cs" />
|
<Compile Include="Datastore\ReflectionStrategyFixture\Benchmarks.cs" />
|
||||||
|
<Compile Include="DecisionEngineTests\NotRestrictedNzbSpecificationFixture.cs" />
|
||||||
<Compile Include="Download\DownloadApprovedReportsTests\DownloadApprovedFixture.cs" />
|
<Compile Include="Download\DownloadApprovedReportsTests\DownloadApprovedFixture.cs" />
|
||||||
<Compile Include="Download\DownloadApprovedReportsTests\GetQualifiedReportsFixture.cs" />
|
<Compile Include="Download\DownloadApprovedReportsTests\GetQualifiedReportsFixture.cs" />
|
||||||
<Compile Include="Download\DownloadClientTests\BlackholeProviderFixture.cs" />
|
<Compile Include="Download\DownloadClientTests\BlackholeProviderFixture.cs" />
|
||||||
@ -167,7 +168,6 @@
|
|||||||
<Compile Include="EpisodeParseResultTest.cs" />
|
<Compile Include="EpisodeParseResultTest.cs" />
|
||||||
<Compile Include="ParserTests\QualityParserFixture.cs" />
|
<Compile Include="ParserTests\QualityParserFixture.cs" />
|
||||||
<Compile Include="Configuration\ConfigCachingFixture.cs" />
|
<Compile Include="Configuration\ConfigCachingFixture.cs" />
|
||||||
<Compile Include="DecisionEngineTests\AllowedReleaseGroupSpecificationFixture.cs" />
|
|
||||||
<Compile Include="DecisionEngineTests\CustomStartDateSpecificationFixture.cs" />
|
<Compile Include="DecisionEngineTests\CustomStartDateSpecificationFixture.cs" />
|
||||||
<Compile Include="ProviderTests\DiskScanProviderTests\GetVideoFilesFixture.cs" />
|
<Compile Include="ProviderTests\DiskScanProviderTests\GetVideoFilesFixture.cs" />
|
||||||
<Compile Include="ProviderTests\RecycleBinProviderTests\CleanupFixture.cs" />
|
<Compile Include="ProviderTests\RecycleBinProviderTests\CleanupFixture.cs" />
|
||||||
|
@ -277,12 +277,6 @@ public string NzbRestrictions
|
|||||||
set { SetValue("NzbRestrictions", value); }
|
set { SetValue("NzbRestrictions", value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string AllowedReleaseGroups
|
|
||||||
{
|
|
||||||
get { return GetValue("AllowedReleaseGroups", String.Empty); }
|
|
||||||
set { SetValue("AllowedReleaseGroups", value); }
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetValue(string key)
|
private string GetValue(string key)
|
||||||
{
|
{
|
||||||
return GetValue(key, String.Empty);
|
return GetValue(key, String.Empty);
|
||||||
|
@ -43,7 +43,6 @@ public interface IConfigService
|
|||||||
PriorityType NzbgetBacklogTvPriority { get; set; }
|
PriorityType NzbgetBacklogTvPriority { get; set; }
|
||||||
PriorityType NzbgetRecentTvPriority { get; set; }
|
PriorityType NzbgetRecentTvPriority { get; set; }
|
||||||
string NzbRestrictions { get; set; }
|
string NzbRestrictions { get; set; }
|
||||||
string AllowedReleaseGroups { get; set; }
|
|
||||||
string GetValue(string key, object defaultValue, bool persist = false);
|
string GetValue(string key, object defaultValue, bool persist = false);
|
||||||
void SetValue(string key, string value);
|
void SetValue(string key, string value);
|
||||||
void SaveValues(Dictionary<string, object> configValues);
|
void SaveValues(Dictionary<string, object> configValues);
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using NLog;
|
|
||||||
using NzbDrone.Core.Configuration;
|
|
||||||
using NzbDrone.Core.Model;
|
|
||||||
using NzbDrone.Core.Parser;
|
|
||||||
using NzbDrone.Core.Parser.Model;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
|
||||||
{
|
|
||||||
public class AllowedReleaseGroupSpecification : IDecisionEngineSpecification
|
|
||||||
{
|
|
||||||
private readonly IConfigService _configService;
|
|
||||||
private readonly Logger _logger;
|
|
||||||
|
|
||||||
public AllowedReleaseGroupSpecification(IConfigService configService, Logger logger)
|
|
||||||
{
|
|
||||||
_configService = configService;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public string RejectionReason
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "Release group is blacklisted.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
|
||||||
{
|
|
||||||
_logger.Trace("Beginning release group check for: {0}", subject);
|
|
||||||
|
|
||||||
//Todo: Make this use NzbRestrictions - How should whitelist be used? Will it override blacklist or vice-versa?
|
|
||||||
|
|
||||||
var allowed = _configService.AllowedReleaseGroups;
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(allowed))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
var reportReleaseGroup = subject.Report.ReleaseGroup.ToLower();
|
|
||||||
|
|
||||||
return allowed.ToLower().Split(',').Any(allowedGroup => allowedGroup.Trim() == reportReleaseGroup);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,57 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
|
using NzbDrone.Core.Model;
|
||||||
|
using NzbDrone.Core.Parser;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||||
|
{
|
||||||
|
public class NotRestrictedNzbSpecification : IDecisionEngineSpecification
|
||||||
|
{
|
||||||
|
private readonly IConfigService _configService;
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
public NotRestrictedNzbSpecification(IConfigService configService, Logger logger)
|
||||||
|
{
|
||||||
|
_configService = configService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string RejectionReason
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "Contrains restricted term.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
||||||
|
{
|
||||||
|
_logger.Trace("Checking if Nzb contains any restrictions: {0}", subject);
|
||||||
|
|
||||||
|
var restrictionsString = _configService.NzbRestrictions;
|
||||||
|
|
||||||
|
if (String.IsNullOrWhiteSpace(restrictionsString))
|
||||||
|
{
|
||||||
|
_logger.Trace("No restrictions configured, allowing: {0}", subject);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var restrictions = restrictionsString.Split('\n');
|
||||||
|
|
||||||
|
foreach (var restriction in restrictions)
|
||||||
|
{
|
||||||
|
if (subject.Report.Title.Contains(restriction))
|
||||||
|
{
|
||||||
|
_logger.Trace("{0} is restricted: {1}", subject, restriction);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.Trace("No restrictions apply, allowing: {0}", subject);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -227,12 +227,12 @@
|
|||||||
<Compile Include="DecisionEngine\DownloadDecision.cs" />
|
<Compile Include="DecisionEngine\DownloadDecision.cs" />
|
||||||
<Compile Include="DecisionEngine\IRejectWithReason.cs" />
|
<Compile Include="DecisionEngine\IRejectWithReason.cs" />
|
||||||
<Compile Include="DecisionEngine\IDecisionEngineSpecification.cs" />
|
<Compile Include="DecisionEngine\IDecisionEngineSpecification.cs" />
|
||||||
|
<Compile Include="DecisionEngine\Specifications\NotRestrictedNzbSpecification.cs" />
|
||||||
<Compile Include="DecisionEngine\Specifications\Search\SeasonMatchSpecification.cs" />
|
<Compile Include="DecisionEngine\Specifications\Search\SeasonMatchSpecification.cs" />
|
||||||
<Compile Include="DecisionEngine\Specifications\Search\DailyEpisodeMatchSpecification.cs" />
|
<Compile Include="DecisionEngine\Specifications\Search\DailyEpisodeMatchSpecification.cs" />
|
||||||
<Compile Include="DecisionEngine\Specifications\Search\IDecisionEngineSearchSpecification.cs" />
|
<Compile Include="DecisionEngine\Specifications\Search\IDecisionEngineSearchSpecification.cs" />
|
||||||
<Compile Include="DecisionEngine\Specifications\AcceptableSizeSpecification.cs" />
|
<Compile Include="DecisionEngine\Specifications\AcceptableSizeSpecification.cs" />
|
||||||
<Compile Include="DecisionEngine\DownloadDecisionMaker.cs" />
|
<Compile Include="DecisionEngine\DownloadDecisionMaker.cs" />
|
||||||
<Compile Include="DecisionEngine\Specifications\AllowedReleaseGroupSpecification.cs" />
|
|
||||||
<Compile Include="DecisionEngine\Specifications\NotInQueueSpecification.cs" />
|
<Compile Include="DecisionEngine\Specifications\NotInQueueSpecification.cs" />
|
||||||
<Compile Include="DecisionEngine\Specifications\CustomStartDateSpecification.cs" />
|
<Compile Include="DecisionEngine\Specifications\CustomStartDateSpecification.cs" />
|
||||||
<Compile Include="DecisionEngine\Specifications\LanguageSpecification.cs" />
|
<Compile Include="DecisionEngine\Specifications\LanguageSpecification.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user