2019-04-13 03:25:58 +00:00
using FluentValidation ;
2022-04-22 03:49:09 +00:00
using NzbDrone.Common.Extensions ;
2013-05-19 23:17:32 +00:00
using NzbDrone.Core.Annotations ;
2013-09-21 06:39:26 +00:00
using NzbDrone.Core.ThingiProvider ;
2015-03-17 04:33:34 +00:00
using NzbDrone.Core.Validation ;
2013-05-19 23:17:32 +00:00
2019-04-13 03:25:58 +00:00
namespace NzbDrone.Core.Notifications.Plex.Server
2013-05-19 23:17:32 +00:00
{
2013-10-12 18:44:40 +00:00
public class PlexServerSettingsValidator : AbstractValidator < PlexServerSettings >
{
public PlexServerSettingsValidator ( )
{
2015-03-31 21:52:27 +00:00
RuleFor ( c = > c . Host ) . ValidHost ( ) ;
2017-01-27 06:35:16 +00:00
RuleFor ( c = > c . Port ) . InclusiveBetween ( 1 , 65535 ) ;
2022-04-22 03:49:09 +00:00
RuleFor ( c = > c . MapFrom ) . NotEmpty ( ) . Unless ( c = > c . MapTo . IsNullOrWhiteSpace ( ) ) ;
RuleFor ( c = > c . MapTo ) . NotEmpty ( ) . Unless ( c = > c . MapFrom . IsNullOrWhiteSpace ( ) ) ;
2013-10-12 18:44:40 +00:00
}
}
2013-09-21 06:39:26 +00:00
public class PlexServerSettings : IProviderConfig
2013-05-19 23:17:32 +00:00
{
2013-10-12 18:44:40 +00:00
private static readonly PlexServerSettingsValidator Validator = new PlexServerSettingsValidator ( ) ;
2013-08-09 06:22:26 +00:00
public PlexServerSettings ( )
{
Port = 32400 ;
2016-02-26 03:19:31 +00:00
UpdateLibrary = true ;
2019-04-13 03:25:58 +00:00
SignIn = "startOAuth" ;
2013-08-09 06:22:26 +00:00
}
2013-06-28 01:55:45 +00:00
[FieldDefinition(0, Label = "Host")]
2015-10-03 17:45:26 +00:00
public string Host { get ; set ; }
2013-05-19 23:17:32 +00:00
2013-06-13 06:41:26 +00:00
[FieldDefinition(1, Label = "Port")]
2015-10-03 17:45:26 +00:00
public int Port { get ; set ; }
2013-06-13 06:41:26 +00:00
2019-04-13 03:25:58 +00:00
[FieldDefinition(2, Label = "Use SSL", Type = FieldType.Checkbox, HelpText = "Connect to Plex over HTTPS instead of HTTP")]
public bool UseSsl { get ; set ; }
2014-04-07 02:44:04 +00:00
2020-10-17 03:27:01 +00:00
[FieldDefinition(3, Label = "Auth Token", Type = FieldType.Textbox, Privacy = PrivacyLevel.ApiKey, Advanced = true)]
2019-04-13 03:25:58 +00:00
public string AuthToken { get ; set ; }
2014-04-07 02:44:04 +00:00
2019-04-13 03:25:58 +00:00
[FieldDefinition(4, Label = "Authenticate with Plex.tv", Type = FieldType.OAuth)]
public string SignIn { get ; set ; }
2013-05-19 23:17:32 +00:00
2019-04-13 03:25:58 +00:00
[FieldDefinition(5, Label = "Update Library", Type = FieldType.Checkbox)]
public bool UpdateLibrary { get ; set ; }
2015-06-04 21:10:38 +00:00
2022-04-22 03:49:09 +00:00
[FieldDefinition(6, Label = "Map Paths From", Type = FieldType.Textbox, Advanced = true, HelpText = "Radarr Path, Used to modify movie paths when Plex sees library path location differently from Radarr")]
public string MapFrom { get ; set ; }
[FieldDefinition(7, Label = "Map Paths To", Type = FieldType.Textbox, Advanced = true, HelpText = "Plex Path, Used to modify movie paths when Plex sees library path location differently from Radarr")]
public string MapTo { get ; set ; }
2016-12-09 06:54:15 +00:00
public bool IsValid = > ! string . IsNullOrWhiteSpace ( Host ) ;
2013-09-21 07:09:26 +00:00
2015-03-17 04:33:34 +00:00
public NzbDroneValidationResult Validate ( )
2013-09-21 07:09:26 +00:00
{
2015-03-17 04:33:34 +00:00
return new NzbDroneValidationResult ( Validator . Validate ( this ) ) ;
2013-09-21 07:09:26 +00:00
}
2013-05-19 23:17:32 +00:00
}
}