Reject non-english releases

NzbDrone, now with more rejection built in
pull/6/head
Mark McDowall 12 years ago
parent 7eb522f871
commit f556f2aaf2

@ -322,6 +322,7 @@ namespace NzbDrone.Core.Test.ParserTests
[TestCase("person.of.interest.1x19.ita.720p.bdmux.x264-novarip", LanguageType.Italian)] [TestCase("person.of.interest.1x19.ita.720p.bdmux.x264-novarip", LanguageType.Italian)]
[TestCase("Salamander.S01E01.FLEMISH.HDTV.x264-BRiGAND", LanguageType.Flemish)] [TestCase("Salamander.S01E01.FLEMISH.HDTV.x264-BRiGAND", LanguageType.Flemish)]
[TestCase("H.Polukatoikia.S03E13.Greek.PDTV.XviD-Ouzo", LanguageType.Greek)] [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) public void parse_language(string postTitle, LanguageType language)
{ {
var result = Parser.ParseLanguage(postTitle); var result = Parser.ParseLanguage(postTitle);

@ -56,6 +56,10 @@ namespace NzbDrone.Core.Test.ProviderTests.DecisionEngineTests
Mocker.GetMock<CustomStartDateSpecification>() Mocker.GetMock<CustomStartDateSpecification>()
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>())) .Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
.Returns(true); .Returns(true);
Mocker.GetMock<LanguageSpecification>()
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
.Returns(true);
} }
private void WithProfileNotAllowed() private void WithProfileNotAllowed()
@ -100,6 +104,13 @@ namespace NzbDrone.Core.Test.ProviderTests.DecisionEngineTests
.Returns(false); .Returns(false);
} }
private void WithLanguageNotWanted()
{
Mocker.GetMock<LanguageSpecification>()
.Setup(c => c.IsSatisfiedBy(It.IsAny<EpisodeParseResult>()))
.Returns(false);
}
[Test] [Test]
public void should_be_allowed_if_all_conditions_are_met() 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); 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);
}
} }
} }

@ -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<EpisodeParseResult>
.CreateNew()
.With(p => p.Language = LanguageType.English)
.Build();
}
private void WithGermanRelease()
{
parseResult = Builder<EpisodeParseResult>
.CreateNew()
.With(p => p.Language = LanguageType.German)
.Build();
}
[Test]
public void should_return_true_if_language_is_english()
{
WithEnglishRelease();
Mocker.Resolve<LanguageSpecification>().IsSatisfiedBy(parseResult).Should().BeTrue();
}
[Test]
public void should_return_false_if_language_is_german()
{
WithGermanRelease();
Mocker.Resolve<LanguageSpecification>().IsSatisfiedBy(parseResult).Should().BeFalse();
}
}
}

@ -18,6 +18,7 @@ namespace NzbDrone.Core.Model
Skipped = 11, Skipped = 11,
Failure = 12, Failure = 12,
ReleaseGroupNotWanted = 13, ReleaseGroupNotWanted = 13,
AiredAfterCustomStartDate = 14 AiredAfterCustomStartDate = 14,
LanguageNotWanted = 15
} }
} }

@ -14,12 +14,14 @@ namespace NzbDrone.Core.Providers.DecisionEngine
private readonly RetentionSpecification _retentionSpecification; private readonly RetentionSpecification _retentionSpecification;
private readonly AllowedReleaseGroupSpecification _allowedReleaseGroupSpecification; private readonly AllowedReleaseGroupSpecification _allowedReleaseGroupSpecification;
private readonly CustomStartDateSpecification _customStartDateSpecification; private readonly CustomStartDateSpecification _customStartDateSpecification;
private readonly LanguageSpecification _languageSpecification;
private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private static readonly Logger logger = LogManager.GetCurrentClassLogger();
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, CustomStartDateSpecification customStartDateSpecification) AllowedReleaseGroupSpecification allowedReleaseGroupSpecification, CustomStartDateSpecification customStartDateSpecification,
LanguageSpecification languageSpecification)
{ {
_qualityAllowedByProfileSpecification = qualityAllowedByProfileSpecification; _qualityAllowedByProfileSpecification = qualityAllowedByProfileSpecification;
_upgradeDiskSpecification = upgradeDiskSpecification; _upgradeDiskSpecification = upgradeDiskSpecification;
@ -28,6 +30,7 @@ namespace NzbDrone.Core.Providers.DecisionEngine
_retentionSpecification = retentionSpecification; _retentionSpecification = retentionSpecification;
_allowedReleaseGroupSpecification = allowedReleaseGroupSpecification; _allowedReleaseGroupSpecification = allowedReleaseGroupSpecification;
_customStartDateSpecification = customStartDateSpecification; _customStartDateSpecification = customStartDateSpecification;
_languageSpecification = languageSpecification;
} }
public AllowedDownloadSpecification() public AllowedDownloadSpecification()
@ -39,6 +42,7 @@ namespace NzbDrone.Core.Providers.DecisionEngine
if (!_qualityAllowedByProfileSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.QualityNotWanted; if (!_qualityAllowedByProfileSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.QualityNotWanted;
if (!_customStartDateSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.AiredAfterCustomStartDate; if (!_customStartDateSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.AiredAfterCustomStartDate;
if (!_upgradeDiskSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.ExistingQualityIsEqualOrBetter; if (!_upgradeDiskSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.ExistingQualityIsEqualOrBetter;
if (!_languageSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.LanguageNotWanted;
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 (!_allowedReleaseGroupSpecification.IsSatisfiedBy(subject)) return ReportRejectionType.ReleaseGroupNotWanted;

@ -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;
}
}
}
Loading…
Cancel
Save