New: Auto tag series based on Original Language

Closes #5908
This commit is contained in:
Mark McDowall 2023-08-13 00:26:37 -07:00
parent c1442535b0
commit 2a7964bc16
2 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,37 @@
using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.Languages;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.AutoTagging.Specifications
{
public class OriginalLanguageSpecificationValidator : AbstractValidator<OriginalLanguageSpecification>
{
public OriginalLanguageSpecificationValidator()
{
RuleFor(c => c.Value).GreaterThanOrEqualTo(0);
}
}
public class OriginalLanguageSpecification : AutoTaggingSpecificationBase
{
private static readonly OriginalLanguageSpecificationValidator Validator = new ();
public override int Order => 1;
public override string ImplementationName => "Original Language";
[FieldDefinition(1, Label = "Language", Type = FieldType.Select, SelectOptions = typeof(OriginalLanguageFieldConverter))]
public int Value { get; set; }
protected override bool IsSatisfiedByWithoutNegate(Series series)
{
return Value == series.OriginalLanguage.Id;
}
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
}
}

View File

@ -0,0 +1,18 @@
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Core.Annotations;
namespace NzbDrone.Core.Languages
{
public class OriginalLanguageFieldConverter : ISelectOptionsConverter
{
public List<SelectOption> GetSelectOptions()
{
return Language.All
.Where(l => l.Id >= 0)
.OrderBy(l => l.Id > 0).ThenBy(l => l.Name)
.ToList()
.ConvertAll(v => new SelectOption { Value = v.Id, Name = v.Name });
}
}
}