New: TMDb Lists using V4 api

This commit is contained in:
Robin Dadswell 2021-03-20 21:08:45 +00:00 committed by GitHub
parent 31770cd889
commit bfc969c45c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 8 deletions

View File

@ -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))
{

View File

@ -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<MovieSearchResource>(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);
}
}
}
}

View File

@ -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