2020-02-18 21:03:05 +00:00
|
|
|
using System.Collections.Generic;
|
2022-07-10 17:25:42 +00:00
|
|
|
using FluentValidation;
|
2020-02-18 21:03:05 +00:00
|
|
|
using NzbDrone.Core.Annotations;
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2022-07-10 17:25:42 +00:00
|
|
|
using NzbDrone.Core.Validation;
|
2020-02-18 21:03:05 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.CustomFormats
|
|
|
|
{
|
2022-07-10 17:25:42 +00:00
|
|
|
public class SizeSpecificationValidator : AbstractValidator<SizeSpecification>
|
|
|
|
{
|
|
|
|
public SizeSpecificationValidator()
|
|
|
|
{
|
2022-08-14 21:19:28 +00:00
|
|
|
RuleFor(c => c.Min).GreaterThanOrEqualTo(0);
|
2022-07-10 17:25:42 +00:00
|
|
|
RuleFor(c => c.Max).GreaterThan(c => c.Min);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-18 21:03:05 +00:00
|
|
|
public class SizeSpecification : CustomFormatSpecificationBase
|
|
|
|
{
|
2022-07-10 17:25:42 +00:00
|
|
|
private static readonly SizeSpecificationValidator Validator = new SizeSpecificationValidator();
|
|
|
|
|
2020-02-18 21:03:05 +00:00
|
|
|
public override int Order => 8;
|
|
|
|
public override string ImplementationName => "Size";
|
|
|
|
|
2020-07-01 20:05:49 +00:00
|
|
|
[FieldDefinition(1, Label = "Minimum Size", HelpText = "Release must be greater than this size", Unit = "GB", Type = FieldType.Number)]
|
2020-02-18 21:03:05 +00:00
|
|
|
public double Min { get; set; }
|
|
|
|
|
2020-07-01 20:05:49 +00:00
|
|
|
[FieldDefinition(1, Label = "Maximum Size", HelpText = "Release must be less than or equal to this size", Unit = "GB", Type = FieldType.Number)]
|
2020-02-18 21:03:05 +00:00
|
|
|
public double Max { get; set; }
|
|
|
|
|
|
|
|
protected override bool IsSatisfiedByWithoutNegate(ParsedMovieInfo movieInfo)
|
|
|
|
{
|
|
|
|
var size = (movieInfo?.ExtraInfo?.GetValueOrDefault("Size", 0.0) as long?) ?? 0;
|
|
|
|
|
2020-07-01 20:05:49 +00:00
|
|
|
return size > Min.Gigabytes() && size <= Max.Gigabytes();
|
2020-02-18 21:03:05 +00:00
|
|
|
}
|
2022-07-10 17:25:42 +00:00
|
|
|
|
|
|
|
public override NzbDroneValidationResult Validate()
|
|
|
|
{
|
|
|
|
return new NzbDroneValidationResult(Validator.Validate(this));
|
|
|
|
}
|
2020-02-18 21:03:05 +00:00
|
|
|
}
|
|
|
|
}
|