diff --git a/src/NzbDrone.Core/ImportLists/TMDb/List/TMDbListParser.cs b/src/NzbDrone.Core/ImportLists/TMDb/List/TMDbListParser.cs index 4d4f834ee..7a280d407 100644 --- a/src/NzbDrone.Core/ImportLists/TMDb/List/TMDbListParser.cs +++ b/src/NzbDrone.Core/ImportLists/TMDb/List/TMDbListParser.cs @@ -24,8 +24,14 @@ namespace NzbDrone.Core.ImportLists.TMDb.List return movies; } - foreach (var movie in jsonResponse.Items) + foreach (var movie in jsonResponse.Results) { + //Media Type is not Movie + if (movie.MediaType != "movie") + { + continue; + } + // Movies with no Year Fix if (string.IsNullOrWhiteSpace(movie.ReleaseDate)) { diff --git a/src/NzbDrone.Core/ImportLists/TMDb/List/TMDbListRequestGenerator.cs b/src/NzbDrone.Core/ImportLists/TMDb/List/TMDbListRequestGenerator.cs index aac6bd5f8..65b96c5fd 100644 --- a/src/NzbDrone.Core/ImportLists/TMDb/List/TMDbListRequestGenerator.cs +++ b/src/NzbDrone.Core/ImportLists/TMDb/List/TMDbListRequestGenerator.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Newtonsoft.Json; using NLog; using NzbDrone.Common.Http; @@ -10,6 +11,7 @@ namespace NzbDrone.Core.ImportLists.TMDb.List public IHttpClient HttpClient { get; set; } public IHttpRequestBuilderFactory RequestBuilder { get; set; } public Logger Logger { get; set; } + public int MaxPages { get; set; } public TMDbListRequestGenerator() { @@ -29,13 +31,27 @@ namespace NzbDrone.Core.ImportLists.TMDb.List Logger.Info($"Importing TMDb movies from list: {Settings.ListId}"); var requestBuilder = RequestBuilder.Create() - .SetSegment("api", "3") + .SetSegment("api", "4") .SetSegment("route", "list") .SetSegment("id", Settings.ListId) .SetSegment("secondaryRoute", ""); - yield return new ImportListRequest(requestBuilder.Accept(HttpAccept.Json) - .Build()); + Logger.Debug($"Getting total pages that TMDb List: {Settings.ListId} consists of"); + + var jsonResponse = JsonConvert.DeserializeObject(HttpClient.Execute(requestBuilder.Build()).Content); + + MaxPages = jsonResponse.TotalPages; + + for (var pageNumber = 1; pageNumber <= MaxPages; pageNumber++) + { + requestBuilder.AddQueryParam("page", pageNumber, true); + + var request = requestBuilder.Build(); + + Logger.Debug($"Importing TMDb movies from: {request.Url}"); + + yield return new ImportListRequest(request); + } } } } diff --git a/src/NzbDrone.Core/ImportLists/TMDb/TMDBResources.cs b/src/NzbDrone.Core/ImportLists/TMDb/TMDBResources.cs index 10f1c9f25..9a913149f 100644 --- a/src/NzbDrone.Core/ImportLists/TMDb/TMDBResources.cs +++ b/src/NzbDrone.Core/ImportLists/TMDb/TMDBResources.cs @@ -86,17 +86,20 @@ namespace NzbDrone.Core.ImportLists.TMDb public class ListResponseResource { public string Id { get; set; } - public ListItemResource[] Items { get; set; } + public ListItemResource[] Results { get; set; } - [JsonProperty("item_count")] - public int ItemCount { get; set; } + [JsonProperty("total_results")] + public int TotalResults { get; set; } + + [JsonProperty("total_pages")] + public int TotalPages { get; set; } [JsonProperty("iso_639_1")] public string Iso639 { get; set; } public string Name { get; set; } [JsonProperty("poster_path")] - public object PosterPath { get; set; } + public string PosterPath { get; set; } } public class CollectionResponseResource