From c69b5fc72aa681b954550d578b6f96f44b708a5f Mon Sep 17 00:00:00 2001 From: Bogdan Date: Wed, 26 Jul 2023 09:28:05 +0300 Subject: [PATCH] New: Add Year specification to Auto Tagging --- .../Specifications/YearSpecification.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/NzbDrone.Core/AutoTagging/Specifications/YearSpecification.cs diff --git a/src/NzbDrone.Core/AutoTagging/Specifications/YearSpecification.cs b/src/NzbDrone.Core/AutoTagging/Specifications/YearSpecification.cs new file mode 100644 index 000000000..2fea8aeb1 --- /dev/null +++ b/src/NzbDrone.Core/AutoTagging/Specifications/YearSpecification.cs @@ -0,0 +1,42 @@ +using FluentValidation; +using NzbDrone.Core.Annotations; +using NzbDrone.Core.Tv; +using NzbDrone.Core.Validation; + +namespace NzbDrone.Core.AutoTagging.Specifications +{ + public class YearSpecificationValidator : AbstractValidator + { + public YearSpecificationValidator() + { + RuleFor(c => c.Min).NotEmpty(); + RuleFor(c => c.Min).GreaterThan(0); + RuleFor(c => c.Max).NotEmpty(); + RuleFor(c => c.Max).GreaterThan(c => c.Min); + } + } + + public class YearSpecification : AutoTaggingSpecificationBase + { + private static readonly YearSpecificationValidator Validator = new (); + + public override int Order => 1; + public override string ImplementationName => "Year"; + + [FieldDefinition(1, Label = "Minimum Year", Type = FieldType.Number)] + public int Min { get; set; } + + [FieldDefinition(2, Label = "Maximum Year", Type = FieldType.Number)] + public int Max { get; set; } + + protected override bool IsSatisfiedByWithoutNegate(Series series) + { + return series.Year >= Min && series.Year <= Max; + } + + public override NzbDroneValidationResult Validate() + { + return new NzbDroneValidationResult(Validator.Validate(this)); + } + } +}