diff --git a/src/NzbDrone.Core.Test/CustomFormats/Specifications/LanguageSpecification/MultiLanguageFixture.cs b/src/NzbDrone.Core.Test/CustomFormats/Specifications/LanguageSpecification/MultiLanguageFixture.cs index afc775398..74fb5b30b 100644 --- a/src/NzbDrone.Core.Test/CustomFormats/Specifications/LanguageSpecification/MultiLanguageFixture.cs +++ b/src/NzbDrone.Core.Test/CustomFormats/Specifications/LanguageSpecification/MultiLanguageFixture.cs @@ -42,6 +42,26 @@ public void should_match_one_language() Subject.IsSatisfiedBy(_input).Should().BeTrue(); } + [Test] + public void should_match_language_if_other_languages_are_present() + { + Subject.Value = Language.French.Id; + Subject.ExceptLanguage = true; + Subject.Negate = false; + + Subject.IsSatisfiedBy(_input).Should().BeTrue(); + } + + [Test] + public void should_match_language_if_not_original_language_is_present() + { + Subject.Value = Language.Original.Id; + Subject.ExceptLanguage = true; + Subject.Negate = false; + + Subject.IsSatisfiedBy(_input).Should().BeTrue(); + } + [Test] public void should_not_match_different_language() { @@ -68,5 +88,15 @@ public void should_not_match_negated_when_all_languages_do_not_match() Subject.IsSatisfiedBy(_input).Should().BeTrue(); } + + [Test] + public void should_not_match_negate_language_if_other_languages_are_present() + { + Subject.Value = Language.Spanish.Id; + Subject.ExceptLanguage = true; + Subject.Negate = true; + + Subject.IsSatisfiedBy(_input).Should().BeFalse(); + } } } diff --git a/src/NzbDrone.Core.Test/CustomFormats/Specifications/LanguageSpecification/SingleLanguageFixture.cs b/src/NzbDrone.Core.Test/CustomFormats/Specifications/LanguageSpecification/SingleLanguageFixture.cs index faee8afe7..af5fc64ad 100644 --- a/src/NzbDrone.Core.Test/CustomFormats/Specifications/LanguageSpecification/SingleLanguageFixture.cs +++ b/src/NzbDrone.Core.Test/CustomFormats/Specifications/LanguageSpecification/SingleLanguageFixture.cs @@ -67,5 +67,15 @@ public void should_match_negated_different_language() Subject.IsSatisfiedBy(_input).Should().BeTrue(); } + + [Test] + public void should_match_negated_except_language_if_language_is_only_present_language() + { + Subject.Value = Language.French.Id; + Subject.ExceptLanguage = true; + Subject.Negate = true; + + Subject.IsSatisfiedBy(_input).Should().BeTrue(); + } } } diff --git a/src/NzbDrone.Core/CustomFormats/Specifications/LanguageSpecification.cs b/src/NzbDrone.Core/CustomFormats/Specifications/LanguageSpecification.cs index d841b7053..9632af893 100644 --- a/src/NzbDrone.Core/CustomFormats/Specifications/LanguageSpecification.cs +++ b/src/NzbDrone.Core/CustomFormats/Specifications/LanguageSpecification.cs @@ -30,6 +30,9 @@ public class LanguageSpecification : CustomFormatSpecificationBase [FieldDefinition(1, Label = "CustomFormatsSpecificationLanguage", Type = FieldType.Select, SelectOptions = typeof(LanguageFieldConverter))] public int Value { get; set; } + [FieldDefinition(1, Label = "CustomFormatsSpecificationExceptLanguage", HelpText = "CustomFormatsSpecificationExceptLanguageHelpText", Type = FieldType.Checkbox)] + public bool ExceptLanguage { get; set; } + public override bool IsSatisfiedBy(CustomFormatInput input) { if (Negate) @@ -46,6 +49,11 @@ protected override bool IsSatisfiedByWithoutNegate(CustomFormatInput input) ? input.Series.OriginalLanguage : (Language)Value; + if (ExceptLanguage) + { + return input.Languages?.Any(l => l != comparedLanguage) ?? false; + } + return input.Languages?.Contains(comparedLanguage) ?? false; } @@ -55,6 +63,11 @@ private bool IsSatisfiedByWithNegate(CustomFormatInput input) ? input.Series.OriginalLanguage : (Language)Value; + if (ExceptLanguage) + { + return !input.Languages?.Any(l => l != comparedLanguage) ?? false; + } + return !input.Languages?.Contains(comparedLanguage) ?? false; } diff --git a/src/NzbDrone.Core/Localization/Core/en.json b/src/NzbDrone.Core/Localization/Core/en.json index 3e77ffdc1..aba736a67 100644 --- a/src/NzbDrone.Core/Localization/Core/en.json +++ b/src/NzbDrone.Core/Localization/Core/en.json @@ -290,6 +290,8 @@ "CustomFormatsSettingsTriggerInfo": "A Custom Format will be applied to a release or file when it matches at least one of each of the different condition types chosen.", "CustomFormatsSpecificationFlag": "Flag", "CustomFormatsSpecificationLanguage": "Language", + "CustomFormatsSpecificationExceptLanguage": "Except Language", + "CustomFormatsSpecificationExceptLanguageHelpText": "Matches if any language other than the selected language is present", "CustomFormatsSpecificationMaximumSize": "Maximum Size", "CustomFormatsSpecificationMaximumSizeHelpText": "Release must be less than or equal to this size", "CustomFormatsSpecificationMinimumSize": "Minimum Size",