From f556f2aaf24de92d8becaa0fb2c6d1a5f24398df Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 15 Jan 2013 17:36:02 -0800 Subject: [PATCH] Reject non-english releases NzbDrone, now with more rejection built in --- .../ParserTests/ParserFixture.cs | 1 + .../AllowedDownloadSpecificationFixture.cs | 19 +++++++ .../LanguageSpecificationFixture.cs | 57 +++++++++++++++++++ NzbDrone.Core/Model/ReportRejectionType.cs | 3 +- .../AllowedDownloadSpecification.cs | 6 +- .../DecisionEngine/LanguageSpecification.cs | 35 ++++++++++++ 6 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 NzbDrone.Core.Test/ProviderTests/DecisionEngineTests/LanguageSpecificationFixture.cs create mode 100644 NzbDrone.Core/Providers/DecisionEngine/LanguageSpecification.cs diff --git a/NzbDrone.Core.Test/ParserTests/ParserFixture.cs b/NzbDrone.Core.Test/ParserTests/ParserFixture.cs index 80b405786..e82c4b3aa 100644 --- a/NzbDrone.Core.Test/ParserTests/ParserFixture.cs +++ b/NzbDrone.Core.Test/ParserTests/ParserFixture.cs @@ -322,6 +322,7 @@ namespace NzbDrone.Core.Test.ParserTests [TestCase("person.of.interest.1x19.ita.720p.bdmux.x264-novarip", LanguageType.Italian)] [TestCase("Salamander.S01E01.FLEMISH.HDTV.x264-BRiGAND", LanguageType.Flemish)] [TestCase("H.Polukatoikia.S03E13.Greek.PDTV.XviD-Ouzo", LanguageType.Greek)] + [TestCase("Burn.Notice.S04E15.Brotherly.Love.GERMAN.DUBBED.WS.WEBRiP.XviD.REPACK-TVP", LanguageType.German)] public void parse_language(string postTitle, LanguageType language) { var result = Parser.ParseLanguage(postTitle); diff --git a/NzbDrone.Core.Test/ProviderTests/DecisionEngineTests/AllowedDownloadSpecificationFixture.cs b/NzbDrone.Core.Test/ProviderTests/DecisionEngineTests/AllowedDownloadSpecificationFixture.cs index a5e79c2a1..ff143f98a 100644 --- a/NzbDrone.Core.Test/ProviderTests/DecisionEngineTests/AllowedDownloadSpecificationFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DecisionEngineTests/AllowedDownloadSpecificationFixture.cs @@ -56,6 +56,10 @@ namespace NzbDrone.Core.Test.ProviderTests.DecisionEngineTests Mocker.GetMock() .Setup(c => c.IsSatisfiedBy(It.IsAny())) .Returns(true); + + Mocker.GetMock() + .Setup(c => c.IsSatisfiedBy(It.IsAny())) + .Returns(true); } private void WithProfileNotAllowed() @@ -100,6 +104,13 @@ namespace NzbDrone.Core.Test.ProviderTests.DecisionEngineTests .Returns(false); } + private void WithLanguageNotWanted() + { + Mocker.GetMock() + .Setup(c => c.IsSatisfiedBy(It.IsAny())) + .Returns(false); + } + [Test] public void should_be_allowed_if_all_conditions_are_met() { @@ -158,5 +169,13 @@ namespace NzbDrone.Core.Test.ProviderTests.DecisionEngineTests spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionType.QualityNotWanted); } + + [Test] + public void should_not_be_allowed_if_language_is_not_wanted() + { + WithLanguageNotWanted(); + + spec.IsSatisfiedBy(parseResult).Should().Be(ReportRejectionType.LanguageNotWanted); + } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/ProviderTests/DecisionEngineTests/LanguageSpecificationFixture.cs b/NzbDrone.Core.Test/ProviderTests/DecisionEngineTests/LanguageSpecificationFixture.cs new file mode 100644 index 000000000..796160a7a --- /dev/null +++ b/NzbDrone.Core.Test/ProviderTests/DecisionEngineTests/LanguageSpecificationFixture.cs @@ -0,0 +1,57 @@ +// 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.Test.Framework; + +namespace NzbDrone.Core.Test.ProviderTests.DecisionEngineTests +{ + [TestFixture] + // ReSharper disable InconsistentNaming + public class LanguageSpecificationFixture : CoreTest + { + private EpisodeParseResult parseResult; + + private void WithEnglishRelease() + { + parseResult = Builder + .CreateNew() + .With(p => p.Language = LanguageType.English) + .Build(); + } + + private void WithGermanRelease() + { + parseResult = Builder + .CreateNew() + .With(p => p.Language = LanguageType.German) + .Build(); + } + + [Test] + public void should_return_true_if_language_is_english() + { + WithEnglishRelease(); + + Mocker.Resolve().IsSatisfiedBy(parseResult).Should().BeTrue(); + } + + [Test] + public void should_return_false_if_language_is_german() + { + WithGermanRelease(); + + Mocker.Resolve().IsSatisfiedBy(parseResult).Should().BeFalse(); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Model/ReportRejectionType.cs b/NzbDrone.Core/Model/ReportRejectionType.cs index 9e2b6900d..54e33a7d1 100644 --- a/NzbDrone.Core/Model/ReportRejectionType.cs +++ b/NzbDrone.Core/Model/ReportRejectionType.cs @@ -18,6 +18,7 @@ namespace NzbDrone.Core.Model Skipped = 11, Failure = 12, ReleaseGroupNotWanted = 13, - AiredAfterCustomStartDate = 14 + AiredAfterCustomStartDate = 14, + LanguageNotWanted = 15 } } diff --git a/NzbDrone.Core/Providers/DecisionEngine/AllowedDownloadSpecification.cs b/NzbDrone.Core/Providers/DecisionEngine/AllowedDownloadSpecification.cs index 93d4f59a9..2c107dfc7 100644 --- a/NzbDrone.Core/Providers/DecisionEngine/AllowedDownloadSpecification.cs +++ b/NzbDrone.Core/Providers/DecisionEngine/AllowedDownloadSpecification.cs @@ -14,12 +14,14 @@ namespace NzbDrone.Core.Providers.DecisionEngine private readonly RetentionSpecification _retentionSpecification; private readonly AllowedReleaseGroupSpecification _allowedReleaseGroupSpecification; private readonly CustomStartDateSpecification _customStartDateSpecification; + private readonly LanguageSpecification _languageSpecification; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); public AllowedDownloadSpecification(QualityAllowedByProfileSpecification qualityAllowedByProfileSpecification, UpgradeDiskSpecification upgradeDiskSpecification, AcceptableSizeSpecification acceptableSizeSpecification, AlreadyInQueueSpecification alreadyInQueueSpecification, RetentionSpecification retentionSpecification, - AllowedReleaseGroupSpecification allowedReleaseGroupSpecification, CustomStartDateSpecification customStartDateSpecification) + AllowedReleaseGroupSpecification allowedReleaseGroupSpecification, CustomStartDateSpecification customStartDateSpecification, + LanguageSpecification languageSpecification) { _qualityAllowedByProfileSpecification = qualityAllowedByProfileSpecification; _upgradeDiskSpecification = upgradeDiskSpecification; @@ -28,6 +30,7 @@ namespace NzbDrone.Core.Providers.DecisionEngine _retentionSpecification = retentionSpecification; _allowedReleaseGroupSpecification = allowedReleaseGroupSpecification; _customStartDateSpecification = customStartDateSpecification; + _languageSpecification = languageSpecification; } public AllowedDownloadSpecification() @@ -39,6 +42,7 @@ namespace NzbDrone.Core.Providers.DecisionEngine if (!_qualityAllowedByProfileSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.QualityNotWanted; if (!_customStartDateSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.AiredAfterCustomStartDate; if (!_upgradeDiskSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.ExistingQualityIsEqualOrBetter; + if (!_languageSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.LanguageNotWanted; if (!_retentionSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.Retention; if (!_acceptableSizeSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.Size; if (!_allowedReleaseGroupSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.ReleaseGroupNotWanted; diff --git a/NzbDrone.Core/Providers/DecisionEngine/LanguageSpecification.cs b/NzbDrone.Core/Providers/DecisionEngine/LanguageSpecification.cs new file mode 100644 index 000000000..492098407 --- /dev/null +++ b/NzbDrone.Core/Providers/DecisionEngine/LanguageSpecification.cs @@ -0,0 +1,35 @@ +using System.Linq; +using NLog; +using NzbDrone.Core.Model; +using NzbDrone.Core.Providers.Core; + +namespace NzbDrone.Core.Providers.DecisionEngine +{ + public class LanguageSpecification + { + private readonly ConfigProvider _configProvider; + private static readonly Logger logger = LogManager.GetCurrentClassLogger(); + + public LanguageSpecification(ConfigProvider configProvider) + { + _configProvider = configProvider; + } + + public LanguageSpecification() + { + + } + + public virtual bool IsSatisfiedBy(EpisodeParseResult subject) + { + logger.Trace("Checking if report meets language requirements. {0}", subject.Language); + if (subject.Language != LanguageType.English) + { + logger.Trace("Report Language: {0} rejected because it is not english", subject.Language); + return false; + } + + return true; + } + } +}