Restrict nzbs based on release group, server side
New: Only grab NZBs if release group is wanted (configurable)
This commit is contained in:
parent
2a316e0b98
commit
67064ec495
|
@ -114,6 +114,7 @@
|
||||||
<Compile Include="ProviderTests\AnalyticsProviderTests\AnalyticsProviderFixture.cs" />
|
<Compile Include="ProviderTests\AnalyticsProviderTests\AnalyticsProviderFixture.cs" />
|
||||||
<Compile Include="ProviderTests\ConfigProviderTests\ConfigCachingFixture.cs" />
|
<Compile Include="ProviderTests\ConfigProviderTests\ConfigCachingFixture.cs" />
|
||||||
<Compile Include="ProviderTests\BannerProviderTest.cs" />
|
<Compile Include="ProviderTests\BannerProviderTest.cs" />
|
||||||
|
<Compile Include="ProviderTests\DecisionEngineTests\AllowedReleaseGroupSpecificationFixture.cs" />
|
||||||
<Compile Include="ProviderTests\Metadata\Xbmc_ForEpisodeFile_Fixture.cs" />
|
<Compile Include="ProviderTests\Metadata\Xbmc_ForEpisodeFile_Fixture.cs" />
|
||||||
<Compile Include="ProviderTests\Metadata\Xbmc_ForSeries_Fixture.cs" />
|
<Compile Include="ProviderTests\Metadata\Xbmc_ForSeries_Fixture.cs" />
|
||||||
<Compile Include="ProviderTests\SearchHistoryProviderTest.cs" />
|
<Compile Include="ProviderTests\SearchHistoryProviderTest.cs" />
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
// ReSharper disable RedundantUsingDirective
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.Model;
|
||||||
|
using NzbDrone.Core.Providers;
|
||||||
|
using NzbDrone.Core.Providers.Core;
|
||||||
|
using NzbDrone.Core.Providers.DecisionEngine;
|
||||||
|
using NzbDrone.Core.Repository;
|
||||||
|
using NzbDrone.Core.Repository.Quality;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.ProviderTests.DecisionEngineTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
public class AllowedReleaseGroupSpecificationFixture : CoreTest
|
||||||
|
{
|
||||||
|
private EpisodeParseResult parseResult;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
parseResult = new EpisodeParseResult
|
||||||
|
{
|
||||||
|
SeriesTitle = "Title",
|
||||||
|
Language = LanguageType.English,
|
||||||
|
Quality = new Quality(QualityTypes.SDTV, true),
|
||||||
|
EpisodeNumbers = new List<int> { 3 },
|
||||||
|
SeasonNumber = 12,
|
||||||
|
AirDate = DateTime.Now.AddDays(-12).Date,
|
||||||
|
ReleaseGroup = "2HD"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_be_true_when_allowedReleaseGroups_is_empty()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<ConfigProvider>().SetupGet(s => s.AllowedReleaseGroups).Returns(String.Empty);
|
||||||
|
Mocker.Resolve<AllowedReleaseGroupSpecification>().IsSatisfiedBy(parseResult).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_be_true_when_allowedReleaseGroups_is_nzbs_releaseGroup()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<ConfigProvider>().SetupGet(s => s.AllowedReleaseGroups).Returns("2HD");
|
||||||
|
Mocker.Resolve<AllowedReleaseGroupSpecification>().IsSatisfiedBy(parseResult).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_be_true_when_allowedReleaseGroups_contains_nzbs_releaseGroup()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<ConfigProvider>().SetupGet(s => s.AllowedReleaseGroups).Returns("2HD, LOL");
|
||||||
|
Mocker.Resolve<AllowedReleaseGroupSpecification>().IsSatisfiedBy(parseResult).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_be_false_when_allowedReleaseGroups_does_not_contain_nzbs_releaseGroup()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<ConfigProvider>().SetupGet(s => s.AllowedReleaseGroups).Returns("LOL,DTD");
|
||||||
|
Mocker.Resolve<AllowedReleaseGroupSpecification>().IsSatisfiedBy(parseResult).Should().BeFalse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,5 +17,6 @@ namespace NzbDrone.Core.Model
|
||||||
DownloadClientFailure = 10,
|
DownloadClientFailure = 10,
|
||||||
Skipped = 11,
|
Skipped = 11,
|
||||||
Failure = 12,
|
Failure = 12,
|
||||||
|
ReleaseGroupNotWanted = 13
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -289,6 +289,7 @@
|
||||||
<Compile Include="Model\Xbmc\ErrorResult.cs" />
|
<Compile Include="Model\Xbmc\ErrorResult.cs" />
|
||||||
<Compile Include="Model\Xbmc\IconType.cs" />
|
<Compile Include="Model\Xbmc\IconType.cs" />
|
||||||
<Compile Include="Providers\BannerProvider.cs" />
|
<Compile Include="Providers\BannerProvider.cs" />
|
||||||
|
<Compile Include="Providers\DecisionEngine\AllowedReleaseGroupSpecification.cs" />
|
||||||
<Compile Include="Providers\Indexer\NzbClub.cs" />
|
<Compile Include="Providers\Indexer\NzbClub.cs" />
|
||||||
<Compile Include="Providers\Indexer\NzbIndex.cs" />
|
<Compile Include="Providers\Indexer\NzbIndex.cs" />
|
||||||
<Compile Include="Providers\Indexer\FileSharingTalk.cs" />
|
<Compile Include="Providers\Indexer\FileSharingTalk.cs" />
|
||||||
|
|
|
@ -514,6 +514,12 @@ namespace NzbDrone.Core.Providers.Core
|
||||||
set { SetValue("MetadataUseBanners", value); }
|
set { SetValue("MetadataUseBanners", value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual string AllowedReleaseGroups
|
||||||
|
{
|
||||||
|
get { return GetValue("AllowedReleaseGroups"); }
|
||||||
|
set { SetValue("AllowedReleaseGroups", value); }
|
||||||
|
}
|
||||||
|
|
||||||
private string GetValue(string key)
|
private string GetValue(string key)
|
||||||
{
|
{
|
||||||
return GetValue(key, String.Empty);
|
return GetValue(key, String.Empty);
|
||||||
|
|
|
@ -13,18 +13,21 @@ namespace NzbDrone.Core.Providers.DecisionEngine
|
||||||
private readonly AcceptableSizeSpecification _acceptableSizeSpecification;
|
private readonly AcceptableSizeSpecification _acceptableSizeSpecification;
|
||||||
private readonly AlreadyInQueueSpecification _alreadyInQueueSpecification;
|
private readonly AlreadyInQueueSpecification _alreadyInQueueSpecification;
|
||||||
private readonly RetentionSpecification _retentionSpecification;
|
private readonly RetentionSpecification _retentionSpecification;
|
||||||
|
private readonly AllowedReleaseGroupSpecification _allowedReleaseGroupSpecification;
|
||||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
public AllowedDownloadSpecification(QualityAllowedByProfileSpecification qualityAllowedByProfileSpecification,
|
public AllowedDownloadSpecification(QualityAllowedByProfileSpecification qualityAllowedByProfileSpecification,
|
||||||
UpgradeDiskSpecification upgradeDiskSpecification, AcceptableSizeSpecification acceptableSizeSpecification,
|
UpgradeDiskSpecification upgradeDiskSpecification, AcceptableSizeSpecification acceptableSizeSpecification,
|
||||||
AlreadyInQueueSpecification alreadyInQueueSpecification, RetentionSpecification retentionSpecification)
|
AlreadyInQueueSpecification alreadyInQueueSpecification, RetentionSpecification retentionSpecification,
|
||||||
|
AllowedReleaseGroupSpecification allowedReleaseGroupSpecification)
|
||||||
{
|
{
|
||||||
_qualityAllowedByProfileSpecification = qualityAllowedByProfileSpecification;
|
_qualityAllowedByProfileSpecification = qualityAllowedByProfileSpecification;
|
||||||
_upgradeDiskSpecification = upgradeDiskSpecification;
|
_upgradeDiskSpecification = upgradeDiskSpecification;
|
||||||
_acceptableSizeSpecification = acceptableSizeSpecification;
|
_acceptableSizeSpecification = acceptableSizeSpecification;
|
||||||
_alreadyInQueueSpecification = alreadyInQueueSpecification;
|
_alreadyInQueueSpecification = alreadyInQueueSpecification;
|
||||||
_retentionSpecification = retentionSpecification;
|
_retentionSpecification = retentionSpecification;
|
||||||
|
_allowedReleaseGroupSpecification = allowedReleaseGroupSpecification;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AllowedDownloadSpecification()
|
public AllowedDownloadSpecification()
|
||||||
|
@ -37,8 +40,9 @@ namespace NzbDrone.Core.Providers.DecisionEngine
|
||||||
if (!_upgradeDiskSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.ExistingQualityIsEqualOrBetter;
|
if (!_upgradeDiskSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.ExistingQualityIsEqualOrBetter;
|
||||||
if (!_retentionSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.Retention;
|
if (!_retentionSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.Retention;
|
||||||
if (!_acceptableSizeSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.Size;
|
if (!_acceptableSizeSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.Size;
|
||||||
|
if (!_allowedReleaseGroupSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.ReleaseGroupNotWanted;
|
||||||
if (_alreadyInQueueSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.AlreadyInQueue;
|
if (_alreadyInQueueSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.AlreadyInQueue;
|
||||||
|
|
||||||
logger.Debug("Episode {0} is needed", subject);
|
logger.Debug("Episode {0} is needed", subject);
|
||||||
return ReportRejectionType.None;
|
return ReportRejectionType.None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using NLog;
|
||||||
|
using Ninject;
|
||||||
|
using NzbDrone.Core.Model;
|
||||||
|
using NzbDrone.Core.Providers.Core;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Providers.DecisionEngine
|
||||||
|
{
|
||||||
|
public class AllowedReleaseGroupSpecification
|
||||||
|
{
|
||||||
|
private readonly ConfigProvider _configProvider;
|
||||||
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
public AllowedReleaseGroupSpecification(ConfigProvider configProvider)
|
||||||
|
{
|
||||||
|
_configProvider = configProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AllowedReleaseGroupSpecification()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual bool IsSatisfiedBy(EpisodeParseResult subject)
|
||||||
|
{
|
||||||
|
logger.Trace("Beginning release group check for: {0}", subject);
|
||||||
|
|
||||||
|
var allowed = _configProvider.AllowedReleaseGroups;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(allowed))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
foreach(var group in allowed.Trim(',', ' ').Split(','))
|
||||||
|
{
|
||||||
|
if (subject.ReleaseGroup.Equals(group.Trim(' '), StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
logger.Trace("Item: {0}'s release group is wanted: {1}", subject, subject.ReleaseGroup);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Trace("Item: {0}'s release group is not wanted: {1}", subject, subject.ReleaseGroup);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue