From e8bb3df68efbada42953f9fab1c7f4b21781f1c5 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Fri, 16 Aug 2024 23:45:55 +0300 Subject: [PATCH] New: Runtime for auto tagging --- .../Specifications/RuntimeSpecification.cs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/NzbDrone.Core/AutoTagging/Specifications/RuntimeSpecification.cs diff --git a/src/NzbDrone.Core/AutoTagging/Specifications/RuntimeSpecification.cs b/src/NzbDrone.Core/AutoTagging/Specifications/RuntimeSpecification.cs new file mode 100644 index 000000000..9bf11da62 --- /dev/null +++ b/src/NzbDrone.Core/AutoTagging/Specifications/RuntimeSpecification.cs @@ -0,0 +1,45 @@ +using FluentValidation; +using NzbDrone.Core.Annotations; +using NzbDrone.Core.Movies; +using NzbDrone.Core.Validation; + +namespace NzbDrone.Core.AutoTagging.Specifications +{ + public class RuntimeSpecificationValidator : AbstractValidator + { + public RuntimeSpecificationValidator() + { + RuleFor(c => c.Min).GreaterThanOrEqualTo(0); + + RuleFor(c => c.Max).Cascade(CascadeMode.Stop) + .NotEmpty() + .GreaterThanOrEqualTo(c => c.Min); + } + } + + public class RuntimeSpecification : AutoTaggingSpecificationBase + { + private static readonly RuntimeSpecificationValidator Validator = new (); + + public override int Order => 1; + public override string ImplementationName => "Runtime"; + + [FieldDefinition(1, Label = "Minimum Runtime", Type = FieldType.Number)] + public int Min { get; set; } + + [FieldDefinition(2, Label = "Maximum Runtime", Type = FieldType.Number)] + public int Max { get; set; } + + protected override bool IsSatisfiedByWithoutNegate(Movie movie) + { + return movie?.MovieMetadata?.Value?.Runtime != null && + movie.MovieMetadata.Value.Runtime >= Min && + movie.MovieMetadata.Value.Runtime <= Max; + } + + public override NzbDroneValidationResult Validate() + { + return new NzbDroneValidationResult(Validator.Validate(this)); + } + } +}