Patch/updates (#887)

* Update HDBits internal logic

* TMDb List validation

* Add Trakt validation, update rest to implement IProviderConfig

* Update wording
pull/893/head
Devin Buhl 8 years ago committed by GitHub
parent dbd1080f5c
commit 4d745d3600

@ -20,7 +20,7 @@ namespace NzbDrone.Core.Indexers.HDBits
public int[] Medium { get; set; } public int[] Medium { get; set; }
public int Origin { get; set; } public int? Origin { get; set; }
[JsonProperty(PropertyName = "imdb")] [JsonProperty(PropertyName = "imdb")]
public ImdbInfo ImdbInfo { get; set; } public ImdbInfo ImdbInfo { get; set; }

@ -51,6 +51,8 @@ namespace NzbDrone.Core.Indexers.HDBits
foreach (var result in queryResults) foreach (var result in queryResults)
{ {
var id = result.Id; var id = result.Id;
var internalRelease = (result.TypeOrigin == 1 ? true : false);
torrentInfos.Add(new HDBitsInfo() torrentInfos.Add(new HDBitsInfo()
{ {
Guid = string.Format("HDBits-{0}", id), Guid = string.Format("HDBits-{0}", id),
@ -62,7 +64,7 @@ namespace NzbDrone.Core.Indexers.HDBits
Seeders = result.Seeders, Seeders = result.Seeders,
Peers = result.Leechers + result.Seeders, Peers = result.Leechers + result.Seeders,
PublishDate = result.Added.ToUniversalTime(), PublishDate = result.Added.ToUniversalTime(),
Internal = (result.TypeOrigin == 1 ? true : false) Internal = internalRelease
}); });
} }
@ -75,11 +77,7 @@ namespace NzbDrone.Core.Indexers.HDBits
.ToArray(); .ToArray();
} }
// order by date return torrentInfos.ToArray();
return
torrentInfos
.OrderByDescending(o => o.PublishDate)
.ToArray();
} }
private string GetDownloadUrl(string torrentId) private string GetDownloadUrl(string torrentId)

@ -1,5 +1,6 @@
using FluentValidation; using FluentValidation;
using NzbDrone.Core.Annotations; using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation; using NzbDrone.Core.Validation;
namespace NzbDrone.Core.NetImport.CouchPotato namespace NzbDrone.Core.NetImport.CouchPotato
@ -15,8 +16,10 @@ namespace NzbDrone.Core.NetImport.CouchPotato
} }
} }
public class CouchPotatoSettings : NetImportBaseSettings public class CouchPotatoSettings : IProviderConfig
{ {
private static readonly CouchPotatoSettingsValidator Validator = new CouchPotatoSettingsValidator();
public CouchPotatoSettings() public CouchPotatoSettings()
{ {
Link = "http://localhost"; Link = "http://localhost";
@ -26,7 +29,7 @@ namespace NzbDrone.Core.NetImport.CouchPotato
} }
[FieldDefinition(0, Label = "CouchPotato URL", HelpText = "Link to your CoouchPootato.")] [FieldDefinition(0, Label = "CouchPotato URL", HelpText = "Link to your CoouchPootato.")]
public new string Link { get; set; } public string Link { get; set; }
[FieldDefinition(1, Label = "CouchPotato Port", HelpText = "Port your CoouchPootato uses.")] [FieldDefinition(1, Label = "CouchPotato Port", HelpText = "Port your CoouchPootato uses.")]
public int Port { get; set; } public int Port { get; set; }
@ -41,6 +44,10 @@ namespace NzbDrone.Core.NetImport.CouchPotato
[FieldDefinition(4, Label = "Only Wanted", HelpText = "Only add wanted movies.", Type = FieldType.Checkbox)] [FieldDefinition(4, Label = "Only Wanted", HelpText = "Only add wanted movies.", Type = FieldType.Checkbox)]
public bool OnlyActive { get; set; } public bool OnlyActive { get; set; }
public NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
} }
} }

@ -17,10 +17,11 @@ namespace NzbDrone.Core.NetImport
protected readonly Logger _logger; protected readonly Logger _logger;
public abstract string Name { get; } public abstract string Name { get; }
public abstract bool Enabled { get; } public abstract bool Enabled { get; }
public abstract bool EnableAuto { get; } public abstract bool EnableAuto { get; }
public abstract IList<Movie> Fetch();
public NetImportBase(IConfigService configService, IParsingService parsingService, Logger logger) public NetImportBase(IConfigService configService, IParsingService parsingService, Logger logger)
{ {
_configService = configService; _configService = configService;
@ -31,7 +32,6 @@ namespace NzbDrone.Core.NetImport
public Type ConfigContract => typeof(TSettings); public Type ConfigContract => typeof(TSettings);
public virtual ProviderMessage Message => null; public virtual ProviderMessage Message => null;
public virtual IEnumerable<ProviderDefinition> DefaultDefinitions public virtual IEnumerable<ProviderDefinition> DefaultDefinitions
{ {
get get
@ -44,7 +44,7 @@ namespace NzbDrone.Core.NetImport
Enabled = config.Validate().IsValid && Enabled, Enabled = config.Validate().IsValid && Enabled,
EnableAuto = true, EnableAuto = true,
ProfileId = 1, ProfileId = 1,
MinimumAvailability = MovieStatusType.PreDB, MinimumAvailability = MovieStatusType.Announced,
Implementation = GetType().Name, Implementation = GetType().Name,
Settings = config Settings = config
}; };
@ -57,8 +57,6 @@ namespace NzbDrone.Core.NetImport
protected TSettings Settings => (TSettings)Definition.Settings; protected TSettings Settings => (TSettings)Definition.Settings;
public abstract IList<Movie> Fetch();
public ValidationResult Test() public ValidationResult Test()
{ {
var failures = new List<ValidationFailure>(); var failures = new List<ValidationFailure>();

@ -1,11 +1,21 @@
using NzbDrone.Core.Annotations; using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.NetImport.RSSImport namespace NzbDrone.Core.NetImport.RSSImport
{ {
public class RSSImportSettingsValidator : AbstractValidator<RSSImportSettings>
{
public RSSImportSettingsValidator()
{
RuleFor(c => c.Link).ValidRootUrl();
}
}
public class RSSImportSettings : NetImportBaseSettings public class RSSImportSettings : IProviderConfig
{ {
//private const string helpLink = "https://imdb.com"; private static readonly RSSImportSettingsValidator Validator = new RSSImportSettingsValidator();
public RSSImportSettings() public RSSImportSettings()
{ {
@ -13,6 +23,11 @@ namespace NzbDrone.Core.NetImport.RSSImport
} }
[FieldDefinition(0, Label = "RSS Link", HelpText = "Link to the rss feed of movies.")] [FieldDefinition(0, Label = "RSS Link", HelpText = "Link to the rss feed of movies.")]
public new string Link { get; set; } public string Link { get; set; }
public NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
} }
} }

@ -1,17 +1,35 @@
using NzbDrone.Core.Annotations; using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.NetImport.StevenLu namespace NzbDrone.Core.NetImport.StevenLu
{ {
public class StevenLuSettings : NetImportBaseSettings public class StevenLuSettingsValidator : AbstractValidator<StevenLuSettings>
{ {
public StevenLuSettingsValidator()
{
RuleFor(c => c.Link).ValidRootUrl();
}
}
public class StevenLuSettings : IProviderConfig
{
private static readonly StevenLuSettingsValidator Validator = new StevenLuSettingsValidator();
public StevenLuSettings() public StevenLuSettings()
{ {
Link = "https://s3.amazonaws.com/popular-movies/movies.json"; Link = "https://s3.amazonaws.com/popular-movies/movies.json";
} }
[FieldDefinition(0, Label = "URL", HelpText = "Don't change this unless you know what you are doing.")] [FieldDefinition(0, Label = "URL", HelpText = "Don't change this unless you know what you are doing.")]
public new string Link { get; set; } public string Link { get; set; }
public NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
} }

@ -1,6 +1,9 @@
using FluentValidation; using FluentValidation;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Annotations; using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation; using NzbDrone.Core.Validation;
using System.Text.RegularExpressions;
namespace NzbDrone.Core.NetImport.TMDb namespace NzbDrone.Core.NetImport.TMDb
{ {
@ -10,25 +13,61 @@ namespace NzbDrone.Core.NetImport.TMDb
public TMDbSettingsValidator() public TMDbSettingsValidator()
{ {
RuleFor(c => c.Link).ValidRootUrl(); RuleFor(c => c.Link).ValidRootUrl();
RuleFor(c => double.Parse(c.MinVoteAverage)).InclusiveBetween(0, 10);
RuleFor(c => c.MinVotes).GreaterThan(0); // Greater than 0
RuleFor(c => c.ListId)
.Matches(@"^[1-9][0-9]*$", RegexOptions.IgnoreCase)
.When(c => c.ListType == (int)TMDbListType.List)
.WithMessage("List Id is required when using TMDb Lists");
// Range 0.0 - 10.0
RuleFor(c => c.MinVoteAverage)
.Matches(@"^(?!0\d)\d*(\.\d{1})?$", RegexOptions.IgnoreCase)
.When(c => c.MinVoteAverage.IsNotNullOrWhiteSpace())
.WithMessage("Minimum vote average must be between 0 and 10");
// Greater than 0
RuleFor(c => c.MinVotes)
.Matches(@"^[1-9][0-9]*$", RegexOptions.IgnoreCase)
.When(c => c.MinVotes.IsNotNullOrWhiteSpace())
.WithMessage("Minimum votes must be greater than 0");
// Any valid certification
RuleFor(c => c.Ceritification)
.Matches(@"^\bNR\b|\bG\b|\bPG\b|\bPG\-13\b|\bR\b|\bNC\-17\b$", RegexOptions.IgnoreCase)
.When(c => c.Ceritification.IsNotNullOrWhiteSpace())
.WithMessage("Not a valid cerification");
// CSV of numbers
RuleFor(c => c.IncludeGenreIds)
.Matches(@"^\d+([,]\d+)*$", RegexOptions.IgnoreCase)
.When(c => c.IncludeGenreIds.IsNotNullOrWhiteSpace())
.WithMessage("Genre Ids must be comma separated number ids");
// CSV of numbers
RuleFor(c => c.ExcludeGenreIds)
.Matches(@"^\d+([,]\d+)*$", RegexOptions.IgnoreCase)
.When(c => c.ExcludeGenreIds.IsNotNullOrWhiteSpace())
.WithMessage("Genre Ids must be comma separated number ids");
} }
} }
public class TMDbSettings : NetImportBaseSettings public class TMDbSettings : IProviderConfig
{ {
private static readonly TMDbSettingsValidator Validator = new TMDbSettingsValidator(); private static readonly TMDbSettingsValidator Validator = new TMDbSettingsValidator();
public TMDbSettings() public TMDbSettings()
{ {
Link = "https://api.themoviedb.org"; Link = "https://api.themoviedb.org";
ListType = (int)TMDbListType.Popular;
MinVoteAverage = "5"; MinVoteAverage = "5";
MinVotes = 1; MinVotes = "1";
LanguageCode = (int)TMDbLanguageCodes.en; LanguageCode = (int)TMDbLanguageCodes.en;
} }
[FieldDefinition(0, Label = "TMDb API URL", HelpText = "Link to to TMDb API URL, do not change unless you know what you are doing.")] [FieldDefinition(0, Label = "TMDb API URL", HelpText = "Link to to TMDb API URL, do not change unless you know what you are doing.")]
public new string Link { get; set; } public string Link { get; set; }
[FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(TMDbListType), HelpText = "Type of list your seeking to import from")] [FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(TMDbListType), HelpText = "Type of list your seeking to import from")]
public int ListType { get; set; } public int ListType { get; set; }
@ -40,9 +79,9 @@ namespace NzbDrone.Core.NetImport.TMDb
public string MinVoteAverage { get; set; } public string MinVoteAverage { get; set; }
[FieldDefinition(4, Label = "Minimum Number of Votes", HelpText = "Filter movies by number of votes")] [FieldDefinition(4, Label = "Minimum Number of Votes", HelpText = "Filter movies by number of votes")]
public int MinVotes { get; set; } public string MinVotes { get; set; }
[FieldDefinition(5, Label = "Ceritification", HelpText = "Filter movies by a ceritification (NR,G,PG,PG-13,R,NC-17)")] [FieldDefinition(5, Label = "Ceritification", HelpText = "Filter movies by a single ceritification (NR,G,PG,PG-13,R,NC-17)")]
public string Ceritification { get; set; } public string Ceritification { get; set; }
[FieldDefinition(6, Label = "Include Genre Ids", HelpText = "Filter movies by TMDb Genre Ids (Comma Separated)")] [FieldDefinition(6, Label = "Include Genre Ids", HelpText = "Filter movies by TMDb Genre Ids (Comma Separated)")]
@ -54,7 +93,7 @@ namespace NzbDrone.Core.NetImport.TMDb
[FieldDefinition(8, Label = "Original Language", Type = FieldType.Select, SelectOptions = typeof(TMDbLanguageCodes), HelpText = "Filter by Language")] [FieldDefinition(8, Label = "Original Language", Type = FieldType.Select, SelectOptions = typeof(TMDbLanguageCodes), HelpText = "Filter by Language")]
public int LanguageCode { get; set; } public int LanguageCode { get; set; }
public new NzbDroneValidationResult Validate() public NzbDroneValidationResult Validate()
{ {
return new NzbDroneValidationResult(Validator.Validate(this)); return new NzbDroneValidationResult(Validator.Validate(this));
} }

@ -1,6 +1,9 @@
using FluentValidation; using FluentValidation;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Annotations; using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation; using NzbDrone.Core.Validation;
using System.Text.RegularExpressions;
namespace NzbDrone.Core.NetImport.Trakt namespace NzbDrone.Core.NetImport.Trakt
{ {
@ -10,26 +13,57 @@ namespace NzbDrone.Core.NetImport.Trakt
public TraktSettingsValidator() public TraktSettingsValidator()
{ {
RuleFor(c => c.Link).ValidRootUrl(); RuleFor(c => c.Link).ValidRootUrl();
// List name required for UserCustomList
RuleFor(c => c.Listname)
.Matches(@"^[A-Za-z0-9\-_]+$", RegexOptions.IgnoreCase)
.When(c => c.ListType == (int)TraktListType.UserCustomList)
.WithMessage("List name is required when using Custom Trakt Lists");
// Username required for UserWatchedList/UserWatchList
RuleFor(c => c.Username)
.Matches(@"^[A-Za-z0-9\-_]+$", RegexOptions.IgnoreCase)
.When(c => c.ListType == (int)TraktListType.UserWatchedList || c.ListType == (int)TraktListType.UserWatchList)
.WithMessage("Username is required when using User Trakt Lists");
// 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
RuleFor(c => c.Ceritification)
.Matches(@"^\bNR\b|\bG\b|\bPG\b|\bPG\-13\b|\bR\b|\bNC\-17\b$", RegexOptions.IgnoreCase)
.When(c => c.Ceritification.IsNotNullOrWhiteSpace())
.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");
} }
} }
public class TraktSettings : NetImportBaseSettings public class TraktSettings : IProviderConfig
{ {
private static readonly TraktSettingsValidator Validator = new TraktSettingsValidator(); private static readonly TraktSettingsValidator Validator = new TraktSettingsValidator();
public TraktSettings() public TraktSettings()
{ {
Link = "https://api.trakt.tv"; Link = "https://api.trakt.tv";
ListType = (int)TraktListType.Popular;
Username = ""; Username = "";
Listname = ""; Listname = "";
Rating = "0-100"; Rating = "0-100";
Ceritification = "NR,G,PG,PG-13,R,NC-17"; Ceritification = "NR,G,PG,PG-13,R,NC-17";
Genres = ""; Genres = "";
Years = "2011-2017"; Years = "";
} }
[FieldDefinition(0, Label = "Trakt API URL", HelpText = "Link to to Trakt API URL, do not change unless you know what you are doing.")] [FieldDefinition(0, Label = "Trakt API URL", HelpText = "Link to to Trakt API URL, do not change unless you know what you are doing.")]
public new string Link { get; set; } public string Link { get; set; }
[FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(TraktListType), HelpText = "Trakt list type")] [FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(TraktListType), HelpText = "Trakt list type")]
public int ListType { get; set; } public int ListType { get; set; }
@ -53,7 +87,7 @@ namespace NzbDrone.Core.NetImport.Trakt
public string Years { get; set; } public string Years { get; set; }
public new NzbDroneValidationResult Validate() public NzbDroneValidationResult Validate()
{ {
return new NzbDroneValidationResult(Validator.Validate(this)); return new NzbDroneValidationResult(Validator.Validate(this));
} }

Loading…
Cancel
Save