2015-03-15 11:37:29 +00:00
using System.Text.RegularExpressions ;
2014-05-13 17:57:46 +00:00
using FluentValidation ;
2015-03-15 11:37:29 +00:00
using NzbDrone.Common.Extensions ;
2014-05-13 17:57:46 +00:00
using NzbDrone.Core.Annotations ;
using NzbDrone.Core.ThingiProvider ;
using NzbDrone.Core.Validation ;
namespace NzbDrone.Core.Indexers.IPTorrents
{
public class IPTorrentsSettingsValidator : AbstractValidator < IPTorrentsSettings >
{
public IPTorrentsSettingsValidator ( )
{
RuleFor ( c = > c . Url ) . ValidRootUrl ( ) ;
2015-03-15 11:37:29 +00:00
RuleFor ( c = > c . Url ) . Matches ( @"/rss\?.+$" ) ;
2016-10-10 20:42:12 +00:00
RuleFor ( c = > c . Url ) . Matches ( @"/rss\?.+;download(?:;|$)" )
. WithMessage ( "Use Direct Download Url (;download)" )
2015-03-15 11:37:29 +00:00
. When ( v = > v . Url . IsNotNullOrWhiteSpace ( ) & & Regex . IsMatch ( v . Url , @"/rss\?.+$" ) ) ;
2014-05-13 17:57:46 +00:00
}
}
public class IPTorrentsSettings : IProviderConfig
{
2015-03-17 04:33:34 +00:00
private static readonly IPTorrentsSettingsValidator Validator = new IPTorrentsSettingsValidator ( ) ;
2014-05-13 17:57:46 +00:00
public IPTorrentsSettings ( )
{
}
[FieldDefinition(0, Label = "Feed URL", HelpText = "The full RSS feed url generated by IPTorrents, using only the categories you selected (HD, SD, x264, etc ...)")]
2015-10-03 17:45:26 +00:00
public string Url { get ; set ; }
2014-05-13 17:57:46 +00:00
2015-03-17 04:33:34 +00:00
public NzbDroneValidationResult Validate ( )
2014-05-13 17:57:46 +00:00
{
2015-03-17 04:33:34 +00:00
return new NzbDroneValidationResult ( Validator . Validate ( this ) ) ;
2014-05-13 17:57:46 +00:00
}
}
2016-10-10 20:42:12 +00:00
}