2017-06-12 12:47:05 +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 ( )
{
2017-06-12 12:47:05 +00:00
RuleFor ( c = > c . BaseUrl ) . ValidRootUrl ( ) ;
2015-03-15 11:37:29 +00:00
2017-06-12 12:47:05 +00:00
RuleFor ( c = > c . BaseUrl ) . Matches ( @"/rss\?.+$" ) ;
2015-03-15 11:37:29 +00:00
2017-06-12 12:47:05 +00:00
RuleFor ( c = > c . BaseUrl ) . Matches ( @"/rss\?.+;download(?:;|$)" )
2016-10-10 20:42:12 +00:00
. WithMessage ( "Use Direct Download Url (;download)" )
2017-06-12 12:47:05 +00:00
. When ( v = > v . BaseUrl . IsNotNullOrWhiteSpace ( ) & & Regex . IsMatch ( v . BaseUrl , @"/rss\?.+$" ) ) ;
2014-05-13 17:57:46 +00:00
}
}
2017-06-12 12:47:05 +00:00
public class IPTorrentsSettings : ITorrentIndexerSettings
2014-05-13 17:57:46 +00:00
{
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 ( )
{
2017-06-12 12:47:05 +00:00
BaseUrl = string . Empty ;
MinimumSeeders = IndexerDefaults . MINIMUM_SEEDERS ;
2014-05-13 17:57:46 +00:00
}
[FieldDefinition(0, Label = "Feed URL", HelpText = "The full RSS feed url generated by IPTorrents, using only the categories you selected (HD, SD, x264, etc ...)")]
2017-06-12 12:47:05 +00:00
public string BaseUrl { get ; set ; }
[FieldDefinition(1, Type = FieldType.Textbox, Label = "Minimum Seeders", HelpText = "Minimum number of seeders required.", Advanced = true)]
public int MinimumSeeders { 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
}