You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
4.1 KiB
103 lines
4.1 KiB
4 years ago
|
using System;
|
||
5 years ago
|
using System.Text.RegularExpressions;
|
||
|
using FluentValidation;
|
||
7 years ago
|
using NzbDrone.Common.Extensions;
|
||
8 years ago
|
using NzbDrone.Core.Annotations;
|
||
7 years ago
|
using NzbDrone.Core.ThingiProvider;
|
||
8 years ago
|
using NzbDrone.Core.Validation;
|
||
|
|
||
4 years ago
|
namespace NzbDrone.Core.ImportLists.Trakt
|
||
8 years ago
|
{
|
||
4 years ago
|
public class TraktSettingsBaseValidator<TSettings> : AbstractValidator<TSettings>
|
||
|
where TSettings : TraktSettingsBase<TSettings>
|
||
8 years ago
|
{
|
||
4 years ago
|
public TraktSettingsBaseValidator()
|
||
8 years ago
|
{
|
||
|
RuleFor(c => c.Link).ValidRootUrl();
|
||
5 years ago
|
RuleFor(c => c.AccessToken).NotEmpty();
|
||
|
RuleFor(c => c.RefreshToken).NotEmpty();
|
||
|
RuleFor(c => c.Expires).NotEmpty();
|
||
7 years ago
|
|
||
|
// Loose validation @TODO
|
||
|
RuleFor(c => c.Rating)
|
||
|
.Matches(@"^\d+\-\d+$", RegexOptions.IgnoreCase)
|
||
|
.When(c => c.Rating.IsNotNullOrWhiteSpace())
|
||
|
.WithMessage("Not a valid rating");
|
||
|
|
||
|
// Any valid certification
|
||
5 years ago
|
RuleFor(c => c.Certification)
|
||
7 years ago
|
.Matches(@"^\bNR\b|\bG\b|\bPG\b|\bPG\-13\b|\bR\b|\bNC\-17\b$", RegexOptions.IgnoreCase)
|
||
5 years ago
|
.When(c => c.Certification.IsNotNullOrWhiteSpace())
|
||
7 years ago
|
.WithMessage("Not a valid cerification");
|
||
|
|
||
|
// Loose validation @TODO
|
||
|
RuleFor(c => c.Years)
|
||
|
.Matches(@"^\d+(\-\d+)?$", RegexOptions.IgnoreCase)
|
||
|
.When(c => c.Years.IsNotNullOrWhiteSpace())
|
||
|
.WithMessage("Not a valid year or range of years");
|
||
7 years ago
|
|
||
|
// Limit not smaller than 1 and not larger than 100
|
||
|
RuleFor(c => c.Limit)
|
||
7 years ago
|
.GreaterThan(0)
|
||
|
.WithMessage("Must be integer greater than 0");
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
public class TraktSettingsBase<TSettings> : IProviderConfig
|
||
|
where TSettings : TraktSettingsBase<TSettings>
|
||
8 years ago
|
{
|
||
4 years ago
|
protected virtual AbstractValidator<TSettings> Validator => new TraktSettingsBaseValidator<TSettings>();
|
||
7 years ago
|
|
||
4 years ago
|
public TraktSettingsBase()
|
||
8 years ago
|
{
|
||
5 years ago
|
SignIn = "startOAuth";
|
||
7 years ago
|
Rating = "0-100";
|
||
5 years ago
|
Certification = "NR,G,PG,PG-13,R,NC-17";
|
||
7 years ago
|
Genres = "";
|
||
7 years ago
|
Years = "";
|
||
7 years ago
|
Limit = 100;
|
||
8 years ago
|
}
|
||
|
|
||
4 years ago
|
public string Link => "https://api.trakt.tv";
|
||
5 years ago
|
public virtual string Scope => "";
|
||
|
|
||
|
[FieldDefinition(0, Label = "Access Token", Type = FieldType.Textbox, Hidden = HiddenType.Hidden)]
|
||
|
public string AccessToken { get; set; }
|
||
|
|
||
|
[FieldDefinition(0, Label = "Refresh Token", Type = FieldType.Textbox, Hidden = HiddenType.Hidden)]
|
||
|
public string RefreshToken { get; set; }
|
||
|
|
||
|
[FieldDefinition(0, Label = "Expires", Type = FieldType.Textbox, Hidden = HiddenType.Hidden)]
|
||
|
public DateTime Expires { get; set; }
|
||
|
|
||
4 years ago
|
[FieldDefinition(0, Label = "Auth User", Type = FieldType.Textbox, Hidden = HiddenType.Hidden)]
|
||
|
public string AuthUser { get; set; }
|
||
|
|
||
|
[FieldDefinition(1, Label = "Rating", HelpText = "Filter movies by rating range (0-100)")]
|
||
7 years ago
|
public string Rating { get; set; }
|
||
|
|
||
4 years ago
|
[FieldDefinition(2, Label = "Certification", HelpText = "Filter movies by a certification (NR,G,PG,PG-13,R,NC-17), (Comma Separated)")]
|
||
5 years ago
|
public string Certification { get; set; }
|
||
7 years ago
|
|
||
4 years ago
|
[FieldDefinition(3, Label = "Genres", HelpText = "Filter movies by Trakt Genre Slug (Comma Separated)")]
|
||
7 years ago
|
public string Genres { get; set; }
|
||
|
|
||
4 years ago
|
[FieldDefinition(4, Label = "Years", HelpText = "Filter movies by year or year range")]
|
||
7 years ago
|
public string Years { get; set; }
|
||
|
|
||
4 years ago
|
[FieldDefinition(5, Label = "Limit", HelpText = "Limit the number of movies to get")]
|
||
7 years ago
|
public int Limit { get; set; }
|
||
|
|
||
4 years ago
|
[FieldDefinition(6, Label = "Additional Parameters", HelpText = "Additional Trakt API parameters", Advanced = true)]
|
||
7 years ago
|
public string TraktAdditionalParameters { get; set; }
|
||
|
|
||
5 years ago
|
[FieldDefinition(99, Label = "Authenticate with Trakt", Type = FieldType.OAuth)]
|
||
|
public string SignIn { get; set; }
|
||
|
|
||
7 years ago
|
public NzbDroneValidationResult Validate()
|
||
7 years ago
|
{
|
||
4 years ago
|
return new NzbDroneValidationResult(Validator.Validate((TSettings)this));
|
||
7 years ago
|
}
|
||
8 years ago
|
}
|
||
|
}
|