mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-04 00:29:44 +02:00
New: Improve multi-language negate Custom Format
(cherry picked from commit 42b11528b4699b8343887185c93a02b139192d83) Closes #9720
This commit is contained in:
parent
31a714e6b3
commit
3191a883dc
@ -0,0 +1,71 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.CustomFormats;
|
||||||
|
using NzbDrone.Core.Languages;
|
||||||
|
using NzbDrone.Core.Movies;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.CustomFormats.Specifications.LanguageSpecification
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class MultiLanguageFixture : CoreTest<Core.CustomFormats.LanguageSpecification>
|
||||||
|
{
|
||||||
|
private CustomFormatInput _input;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_input = new CustomFormatInput
|
||||||
|
{
|
||||||
|
MovieInfo = Builder<ParsedMovieInfo>.CreateNew().Build(),
|
||||||
|
Movie = Builder<Movie>.CreateNew().With(m => m.MovieMetadata.Value.OriginalLanguage = Language.English).Build(),
|
||||||
|
Size = 100.Megabytes(),
|
||||||
|
Languages = new List<Language>
|
||||||
|
{
|
||||||
|
Language.English,
|
||||||
|
Language.French
|
||||||
|
},
|
||||||
|
Filename = "Movie.Title.2024"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_match_one_language()
|
||||||
|
{
|
||||||
|
Subject.Value = Language.French.Id;
|
||||||
|
Subject.Negate = false;
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_input).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_match_different_language()
|
||||||
|
{
|
||||||
|
Subject.Value = Language.Spanish.Id;
|
||||||
|
Subject.Negate = false;
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_input).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_match_negated_when_one_language_matches()
|
||||||
|
{
|
||||||
|
Subject.Value = Language.French.Id;
|
||||||
|
Subject.Negate = true;
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_input).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_match_negated_when_all_languages_do_not_match()
|
||||||
|
{
|
||||||
|
Subject.Value = Language.Spanish.Id;
|
||||||
|
Subject.Negate = true;
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_input).Should().BeTrue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.CustomFormats;
|
||||||
|
using NzbDrone.Core.Languages;
|
||||||
|
using NzbDrone.Core.Movies;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.CustomFormats.Specifications.LanguageSpecification
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class OriginalLanguageFixture : CoreTest<Core.CustomFormats.LanguageSpecification>
|
||||||
|
{
|
||||||
|
private CustomFormatInput _input;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_input = new CustomFormatInput
|
||||||
|
{
|
||||||
|
MovieInfo = Builder<ParsedMovieInfo>.CreateNew().Build(),
|
||||||
|
Movie = Builder<Movie>.CreateNew().With(m => m.MovieMetadata.Value.OriginalLanguage = Language.English).Build(),
|
||||||
|
Size = 100.Megabytes(),
|
||||||
|
Languages = new List<Language>
|
||||||
|
{
|
||||||
|
Language.French
|
||||||
|
},
|
||||||
|
Filename = "Movie.Title.2024"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GivenLanguages(params Language[] languages)
|
||||||
|
{
|
||||||
|
_input.Languages = languages.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_match_same_single_language()
|
||||||
|
{
|
||||||
|
GivenLanguages(Language.English);
|
||||||
|
|
||||||
|
Subject.Value = Language.Original.Id;
|
||||||
|
Subject.Negate = false;
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_input).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_match_different_single_language()
|
||||||
|
{
|
||||||
|
Subject.Value = Language.Original.Id;
|
||||||
|
Subject.Negate = false;
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_input).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_match_negated_same_single_language()
|
||||||
|
{
|
||||||
|
GivenLanguages(Language.English);
|
||||||
|
|
||||||
|
Subject.Value = Language.Original.Id;
|
||||||
|
Subject.Negate = true;
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_input).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_match_negated_different_single_language()
|
||||||
|
{
|
||||||
|
Subject.Value = Language.Original.Id;
|
||||||
|
Subject.Negate = true;
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_input).Should().BeTrue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.CustomFormats;
|
||||||
|
using NzbDrone.Core.Languages;
|
||||||
|
using NzbDrone.Core.Movies;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.CustomFormats.Specifications.LanguageSpecification
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class SingleLanguageFixture : CoreTest<Core.CustomFormats.LanguageSpecification>
|
||||||
|
{
|
||||||
|
private CustomFormatInput _input;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_input = new CustomFormatInput
|
||||||
|
{
|
||||||
|
MovieInfo = Builder<ParsedMovieInfo>.CreateNew().Build(),
|
||||||
|
Movie = Builder<Movie>.CreateNew().With(m => m.MovieMetadata.Value.OriginalLanguage = Language.English).Build(),
|
||||||
|
Size = 100.Megabytes(),
|
||||||
|
Languages = new List<Language>
|
||||||
|
{
|
||||||
|
Language.French
|
||||||
|
},
|
||||||
|
Filename = "Movie.Title.2024"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_match_same_language()
|
||||||
|
{
|
||||||
|
Subject.Value = Language.French.Id;
|
||||||
|
Subject.Negate = false;
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_input).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_match_different_language()
|
||||||
|
{
|
||||||
|
Subject.Value = Language.Spanish.Id;
|
||||||
|
Subject.Negate = false;
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_input).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_match_negated_same_language()
|
||||||
|
{
|
||||||
|
Subject.Value = Language.French.Id;
|
||||||
|
Subject.Negate = true;
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_input).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_match_negated_different_language()
|
||||||
|
{
|
||||||
|
Subject.Value = Language.Spanish.Id;
|
||||||
|
Subject.Negate = true;
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_input).Should().BeTrue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -20,7 +20,7 @@ public ICustomFormatSpecification Clone()
|
|||||||
|
|
||||||
public abstract NzbDroneValidationResult Validate();
|
public abstract NzbDroneValidationResult Validate();
|
||||||
|
|
||||||
public bool IsSatisfiedBy(CustomFormatInput input)
|
public virtual bool IsSatisfiedBy(CustomFormatInput input)
|
||||||
{
|
{
|
||||||
var match = IsSatisfiedByWithoutNegate(input);
|
var match = IsSatisfiedByWithoutNegate(input);
|
||||||
|
|
||||||
|
@ -30,6 +30,16 @@ public class LanguageSpecification : CustomFormatSpecificationBase
|
|||||||
[FieldDefinition(1, Label = "Language", Type = FieldType.Select, SelectOptions = typeof(LanguageFieldConverter))]
|
[FieldDefinition(1, Label = "Language", Type = FieldType.Select, SelectOptions = typeof(LanguageFieldConverter))]
|
||||||
public int Value { get; set; }
|
public int Value { get; set; }
|
||||||
|
|
||||||
|
public override bool IsSatisfiedBy(CustomFormatInput input)
|
||||||
|
{
|
||||||
|
if (Negate)
|
||||||
|
{
|
||||||
|
return IsSatisfiedByWithNegate(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
return IsSatisfiedByWithoutNegate(input);
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool IsSatisfiedByWithoutNegate(CustomFormatInput input)
|
protected override bool IsSatisfiedByWithoutNegate(CustomFormatInput input)
|
||||||
{
|
{
|
||||||
var comparedLanguage = input.MovieInfo != null && input.Movie != null && Value == Language.Original.Id && input.Movie.MovieMetadata.Value.OriginalLanguage != Language.Unknown
|
var comparedLanguage = input.MovieInfo != null && input.Movie != null && Value == Language.Original.Id && input.Movie.MovieMetadata.Value.OriginalLanguage != Language.Unknown
|
||||||
@ -39,6 +49,15 @@ protected override bool IsSatisfiedByWithoutNegate(CustomFormatInput input)
|
|||||||
return input?.Languages?.Contains(comparedLanguage) ?? false;
|
return input?.Languages?.Contains(comparedLanguage) ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsSatisfiedByWithNegate(CustomFormatInput input)
|
||||||
|
{
|
||||||
|
var comparedLanguage = input.MovieInfo != null && input.Movie != null && Value == Language.Original.Id && input.Movie.MovieMetadata.Value.OriginalLanguage != Language.Unknown
|
||||||
|
? input.Movie.MovieMetadata.Value.OriginalLanguage
|
||||||
|
: (Language)Value;
|
||||||
|
|
||||||
|
return !input.Languages?.Contains(comparedLanguage) ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
public override NzbDroneValidationResult Validate()
|
public override NzbDroneValidationResult Validate()
|
||||||
{
|
{
|
||||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||||
|
Loading…
Reference in New Issue
Block a user