diff --git a/src/NzbDrone.Core/NetImport/Trakt/TraktAPI.cs b/src/NzbDrone.Core/NetImport/Trakt/TraktAPI.cs index e09ce89be..4240e5241 100644 --- a/src/NzbDrone.Core/NetImport/Trakt/TraktAPI.cs +++ b/src/NzbDrone.Core/NetImport/Trakt/TraktAPI.cs @@ -21,9 +21,18 @@ namespace NzbDrone.Core.NetImport.Trakt public class TraktResponse { - public int rank { get; set; } + public int? rank { get; set; } public string listed_at { get; set; } public string type { get; set; } + + public int? watchers { get; set; } + + public long? revenue { get; set; } + + public long? watcher_count { get; set; } + public long? play_count { get; set; } + public long? collected_count { get; set; } + public Movie movie { get; set; } } } diff --git a/src/NzbDrone.Core/NetImport/Trakt/TraktListType.cs b/src/NzbDrone.Core/NetImport/Trakt/TraktListType.cs index bf818d06a..ac867aa0b 100644 --- a/src/NzbDrone.Core/NetImport/Trakt/TraktListType.cs +++ b/src/NzbDrone.Core/NetImport/Trakt/TraktListType.cs @@ -1,9 +1,32 @@ -namespace NzbDrone.Core.NetImport.Trakt +using System.Runtime.Serialization; + +namespace NzbDrone.Core.NetImport.Trakt { public enum TraktListType { - WatchList = 0, - Watched = 1, - CustomList = 2 + [EnumMember(Value = "User Watch List")] + UserWatchList = 0, + [EnumMember(Value = "User Watched List")] + UserWatchedList = 1, + [EnumMember(Value = "User Custom List")] + UserCustomList = 2, + + [EnumMember(Value = "Trending Movies")] + TrendingMovies = 3, + [EnumMember(Value = "Popular Movies")] + PopularMovies = 4, + [EnumMember(Value = "Top Anticipated Movies")] + AnticipatedMovies = 5, + [EnumMember(Value = "Top Box Office Movies")] + BoxOfficeMovies = 6, + + [EnumMember(Value = "Top Watched Movies By Week")] + TopWatchedByWeek = 7, + [EnumMember(Value = "Top Watched Movies By Month")] + TopWatchedByMonth = 8, + [EnumMember(Value = "Top Watched Movies By Year")] + TopWatchedByYear = 9, + [EnumMember(Value = "Top Watched Movies Of All Time")] + TopWatchedByAllTime = 10 } } diff --git a/src/NzbDrone.Core/NetImport/Trakt/TraktParser.cs b/src/NzbDrone.Core/NetImport/Trakt/TraktParser.cs index f6e80bad2..b40567763 100644 --- a/src/NzbDrone.Core/NetImport/Trakt/TraktParser.cs +++ b/src/NzbDrone.Core/NetImport/Trakt/TraktParser.cs @@ -42,26 +42,45 @@ namespace NzbDrone.Core.NetImport.Trakt return movies; } - var jsonResponse = JsonConvert.DeserializeObject>(_importResponse.Content); - - // no movies were return - if (jsonResponse == null) + if (_settings.ListType == (int) TraktListType.PopularMovies) { - return movies; - } + var jsonResponse = JsonConvert.DeserializeObject>(_importResponse.Content); - foreach (var movie in jsonResponse) + foreach (var movie in jsonResponse) + { + movies.AddIfNotNull(new Tv.Movie() + { + Title = movie.title, + ImdbId = movie.ids.imdb, + TmdbId = movie.ids.tmdb, + Year = (movie.year ?? 0) + }); + } + } + else { - movies.AddIfNotNull(new Tv.Movie() + var jsonResponse = JsonConvert.DeserializeObject>(_importResponse.Content); + + // no movies were return + if (jsonResponse == null) + { + return movies; + } + + foreach (var movie in jsonResponse) { - Title = movie.movie.title, - ImdbId = movie.movie.ids.imdb, - TmdbId = movie.movie.ids.tmdb, - Year = (movie.movie.year ?? 0) - }); + movies.AddIfNotNull(new Tv.Movie() + { + Title = movie.movie.title, + ImdbId = movie.movie.ids.imdb, + TmdbId = movie.movie.ids.tmdb, + Year = (movie.movie.year ?? 0) + }); + } } - + return movies; + } protected virtual bool PreProcess(NetImportResponse indexerResponse) diff --git a/src/NzbDrone.Core/NetImport/Trakt/TraktRequestGenerator.cs b/src/NzbDrone.Core/NetImport/Trakt/TraktRequestGenerator.cs index 61166f8b3..69ddbb574 100644 --- a/src/NzbDrone.Core/NetImport/Trakt/TraktRequestGenerator.cs +++ b/src/NzbDrone.Core/NetImport/Trakt/TraktRequestGenerator.cs @@ -21,18 +21,42 @@ namespace NzbDrone.Core.NetImport.Trakt private IEnumerable GetMovies(string searchParameters) { - var link = $"{Settings.Link.Trim()}{Settings.Username.Trim()}"; + var link = Settings.Link.Trim(); switch (Settings.ListType) { - case (int)TraktListType.CustomList: - link = link + $"/lists/{Settings.Listname.Trim()}/items/movies"; + case (int)TraktListType.UserCustomList: + link = link + $"/users/{Settings.Username.Trim()}/lists/{Settings.Listname.Trim()}/items/movies"; break; - case (int)TraktListType.WatchList: - link = link + "/watchlist/movies"; + case (int)TraktListType.UserWatchList: + link = link + $"/users/{Settings.Username.Trim()}/watchlist/movies"; break; - case (int)TraktListType.Watched: - link = link + "/watched/movies"; + case (int)TraktListType.UserWatchedList: + link = link + $"/users/{Settings.Username.Trim()}/watched/movies"; + break; + case (int)TraktListType.TrendingMovies: + link = link + "/movies/trending"; + break; + case (int)TraktListType.PopularMovies: + link = link + "/movies/popular"; + break; + case (int)TraktListType.AnticipatedMovies: + link = link + "/movies/anticipated"; + break; + case (int)TraktListType.BoxOfficeMovies: + link = link + "/movies/boxoffice"; + break; + case (int)TraktListType.TopWatchedByWeek: + link = link + "/movies/watched/weekly"; + break; + case (int)TraktListType.TopWatchedByMonth: + link = link + "/movies/watched/monthly"; + break; + case (int)TraktListType.TopWatchedByYear: + link = link + "/movies/watched/yearly"; + break; + case (int)TraktListType.TopWatchedByAllTime: + link = link + "/movies/watched/all"; break; } diff --git a/src/NzbDrone.Core/NetImport/Trakt/TraktSettings.cs b/src/NzbDrone.Core/NetImport/Trakt/TraktSettings.cs index 8af9bd25f..8e47886c5 100644 --- a/src/NzbDrone.Core/NetImport/Trakt/TraktSettings.cs +++ b/src/NzbDrone.Core/NetImport/Trakt/TraktSettings.cs @@ -1,7 +1,5 @@ using FluentValidation; using NzbDrone.Core.Annotations; -using NzbDrone.Core.Profiles; -using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Validation; namespace NzbDrone.Core.NetImport.Trakt @@ -20,7 +18,7 @@ namespace NzbDrone.Core.NetImport.Trakt { public TraktSettings() { - Link = "https://api.trakt.tv/users/"; + Link = "https://api.trakt.tv"; Username = ""; Listname = ""; } @@ -31,7 +29,7 @@ namespace NzbDrone.Core.NetImport.Trakt [FieldDefinition(1, Label = "Trakt List Type", Type = FieldType.Select, SelectOptions = typeof(TraktListType), HelpText = "Trakt list type, custom or watchlist")] public int ListType { get; set; } - [FieldDefinition(2, Label = "Trakt Username", HelpText = "Trakt Username the list belongs to.")] + [FieldDefinition(2, Label = "Trakt Username", HelpText = "Required for User List")] public string Username { get; set; } [FieldDefinition(3, Label = "Trakt List Name", HelpText = "Required for Custom List")] @@ -39,4 +37,6 @@ namespace NzbDrone.Core.NetImport.Trakt } + + } diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 895393ffe..031b6a03a 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -99,6 +99,7 @@ +