From 97ee66465dc9ce517cce35a3846cb30a59879333 Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Wed, 22 Feb 2017 16:12:42 -0500 Subject: [PATCH] Patch/filter trakt (#838) * Update wording for Certification * Add Filter Options for Trakt --- .../NetImport/TMDb/TMDbSettings.cs | 2 +- .../NetImport/Trakt/TraktRequestGenerator.cs | 18 ++++++----- .../NetImport/Trakt/TraktSettings.cs | 30 ++++++++++++++++--- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/NzbDrone.Core/NetImport/TMDb/TMDbSettings.cs b/src/NzbDrone.Core/NetImport/TMDb/TMDbSettings.cs index c1f9326d0..505af060a 100644 --- a/src/NzbDrone.Core/NetImport/TMDb/TMDbSettings.cs +++ b/src/NzbDrone.Core/NetImport/TMDb/TMDbSettings.cs @@ -42,7 +42,7 @@ namespace NzbDrone.Core.NetImport.TMDb [FieldDefinition(4, Label = "Minimum Number of Votes", HelpText = "Filter movies by number of votes")] public int MinVotes { get; set; } - [FieldDefinition(5, Label = "Rating", HelpText = "Filter movies by a rating (NR,G,PG,PG-13,R,NC-17)")] + [FieldDefinition(5, Label = "Ceritification", HelpText = "Filter movies by a ceritification (NR,G,PG,PG-13,R,NC-17)")] public string Ceritification { get; set; } [FieldDefinition(6, Label = "Include Genre Ids", HelpText = "Filter movies by TMDb Genre Ids (Comma Separated)")] diff --git a/src/NzbDrone.Core/NetImport/Trakt/TraktRequestGenerator.cs b/src/NzbDrone.Core/NetImport/Trakt/TraktRequestGenerator.cs index 50b2b2f6a..50f9e2e2f 100644 --- a/src/NzbDrone.Core/NetImport/Trakt/TraktRequestGenerator.cs +++ b/src/NzbDrone.Core/NetImport/Trakt/TraktRequestGenerator.cs @@ -20,6 +20,8 @@ namespace NzbDrone.Core.NetImport.Trakt { var link = Settings.Link.Trim(); + var filters = $"?years={Settings.Years}&genres={Settings.Genres.ToLower()}&ratings={Settings.Rating}&certifications={Settings.Ceritification.ToLower()}"; + switch (Settings.ListType) { case (int)TraktListType.UserCustomList: @@ -32,28 +34,28 @@ namespace NzbDrone.Core.NetImport.Trakt link = link + $"/users/{Settings.Username.Trim()}/watched/movies"; break; case (int)TraktListType.Trending: - link = link + "/movies/trending"; + link = link + "/movies/trending" + filters; break; case (int)TraktListType.Popular: - link = link + "/movies/popular"; + link = link + "/movies/popular" + filters; break; case (int)TraktListType.Anticipated: - link = link + "/movies/anticipated"; + link = link + "/movies/anticipated" + filters; break; case (int)TraktListType.BoxOffice: - link = link + "/movies/boxoffice"; + link = link + "/movies/boxoffice" + filters; break; case (int)TraktListType.TopWatchedByWeek: - link = link + "/movies/watched/weekly"; + link = link + "/movies/watched/weekly" + filters; break; case (int)TraktListType.TopWatchedByMonth: - link = link + "/movies/watched/monthly"; + link = link + "/movies/watched/monthly" + filters; break; case (int)TraktListType.TopWatchedByYear: - link = link + "/movies/watched/yearly"; + link = link + "/movies/watched/yearly" + filters; break; case (int)TraktListType.TopWatchedByAllTime: - link = link + "/movies/watched/all"; + link = link + "/movies/watched/all" + filters; break; } diff --git a/src/NzbDrone.Core/NetImport/Trakt/TraktSettings.cs b/src/NzbDrone.Core/NetImport/Trakt/TraktSettings.cs index c2de86563..677bbd36d 100644 --- a/src/NzbDrone.Core/NetImport/Trakt/TraktSettings.cs +++ b/src/NzbDrone.Core/NetImport/Trakt/TraktSettings.cs @@ -10,31 +10,53 @@ namespace NzbDrone.Core.NetImport.Trakt public TraktSettingsValidator() { RuleFor(c => c.Link).ValidRootUrl(); - RuleFor(c => c.Username).NotEmpty(); } } public class TraktSettings : NetImportBaseSettings { + + private static readonly TraktSettingsValidator Validator = new TraktSettingsValidator(); public TraktSettings() { Link = "https://api.trakt.tv"; Username = ""; Listname = ""; + Rating = "0-100"; + Ceritification = "NR,G,PG,PG-13,R,NC-17"; + Genres = ""; + Years = "2011-2017"; } [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; } - [FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(TraktListType), HelpText = "Trakt list type, custom or watchlist")] + [FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(TraktListType), HelpText = "Trakt list type")] public int ListType { get; set; } - [FieldDefinition(2, Label = "Username", HelpText = "Required for User List")] + [FieldDefinition(2, Label = "Username", HelpText = "Required for User List (Ignores Filtering Options)")] public string Username { get; set; } - [FieldDefinition(3, Label = "List Name", HelpText = "Required for Custom List")] + [FieldDefinition(3, Label = "List Name", HelpText = "Required for Custom List (Ignores Filtering Options)")] public string Listname { get; set; } + [FieldDefinition(4, Label = "Rating", HelpText = "Filter movies by rating range (0-100)")] + public string Rating { get; set; } + + [FieldDefinition(5, Label = "Ceritification", HelpText = "Filter movies by a ceritification (NR,G,PG,PG-13,R,NC-17), (Comma Separated)")] + public string Ceritification { get; set; } + + [FieldDefinition(6, Label = "Genres", HelpText = "Filter movies by Trakt Genre Slug (Comma Separated)")] + public string Genres { get; set; } + + [FieldDefinition(7, Label = "Years", HelpText = "Filter movies by year or year range")] + public string Years { get; set; } + + + public new NzbDroneValidationResult Validate() + { + return new NzbDroneValidationResult(Validator.Validate(this)); + } }