1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-20 01:42:35 +01:00

New: Runtime for auto tagging

This commit is contained in:
Bogdan 2024-08-16 23:45:55 +03:00
parent 9442f1fb04
commit e8bb3df68e

View File

@ -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<RuntimeSpecification>
{
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));
}
}
}