1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-21 23:32:27 +00:00

New: Auto tag series based on Original Language

(cherry picked from commit 2a7964bc16fa32bc0000bb7326795d02cc41bfed)
This commit is contained in:
Mark McDowall 2023-08-13 00:26:37 -07:00 committed by servarr
parent 98ae377aff
commit e76974a0b3
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 });
}
}
}