Cleanup TMDB Resources

pull/2/head
Qstick 4 years ago
parent 50f84101e0
commit d3d3117bf3

@ -60,9 +60,9 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
request.AllowAutoRedirect = true; request.AllowAutoRedirect = true;
request.SuppressHttpError = true; request.SuppressHttpError = true;
var response = _httpClient.Get<MovieSearchRoot>(request); var response = _httpClient.Get<MovieSearchResource>(request);
return new HashSet<int>(response.Resource.Results.Select(c => c.id)); return new HashSet<int>(response.Resource.Results.Select(c => c.Id));
} }
public async Task<Tuple<Movie, List<Credit>>> GetMovieInfoAsync(int tmdbId) public async Task<Tuple<Movie, List<Credit>>> GetMovieInfoAsync(int tmdbId)

@ -24,7 +24,7 @@ namespace NzbDrone.Core.NetImport.RadarrList
return movies; return movies;
} }
var jsonResponse = JsonConvert.DeserializeObject<List<MovieResult>>(importResponse.Content); var jsonResponse = JsonConvert.DeserializeObject<List<MovieResultResource>>(importResponse.Content);
// no movies were return // no movies were return
if (jsonResponse == null) if (jsonResponse == null)
@ -32,7 +32,7 @@ namespace NzbDrone.Core.NetImport.RadarrList
return movies; return movies;
} }
return jsonResponse.SelectList(m => new Movie { TmdbId = m.id }); return jsonResponse.SelectList(m => new Movie { TmdbId = m.Id });
} }
protected virtual bool PreProcess(NetImportResponse netImportResponse) protected virtual bool PreProcess(NetImportResponse netImportResponse)

@ -17,7 +17,7 @@ namespace NzbDrone.Core.NetImport.TMDb.Collection
return movies; return movies;
} }
var jsonResponse = JsonConvert.DeserializeObject<CollectionResponseRoot>(importResponse.Content); var jsonResponse = JsonConvert.DeserializeObject<CollectionResponseResource>(importResponse.Content);
// no movies were return // no movies were return
if (jsonResponse == null) if (jsonResponse == null)
@ -25,10 +25,10 @@ namespace NzbDrone.Core.NetImport.TMDb.Collection
return movies; return movies;
} }
foreach (var movie in jsonResponse.parts) foreach (var movie in jsonResponse.Parts)
{ {
// Movies with no Year Fix // Movies with no Year Fix
if (string.IsNullOrWhiteSpace(movie.release_date)) if (string.IsNullOrWhiteSpace(movie.ReleaseDate))
{ {
continue; continue;
} }

@ -17,7 +17,7 @@ namespace NzbDrone.Core.NetImport.TMDb.List
return movies; return movies;
} }
var jsonResponse = JsonConvert.DeserializeObject<ListResponseRoot>(importResponse.Content); var jsonResponse = JsonConvert.DeserializeObject<ListResponseResource>(importResponse.Content);
// no movies were return // no movies were return
if (jsonResponse == null) if (jsonResponse == null)
@ -25,10 +25,10 @@ namespace NzbDrone.Core.NetImport.TMDb.List
return movies; return movies;
} }
foreach (var movie in jsonResponse.items) foreach (var movie in jsonResponse.Items)
{ {
// Movies with no Year Fix // Movies with no Year Fix
if (string.IsNullOrWhiteSpace(movie.release_date)) if (string.IsNullOrWhiteSpace(movie.ReleaseDate))
{ {
continue; continue;
} }

@ -24,7 +24,7 @@ namespace NzbDrone.Core.NetImport.TMDb.Person
return movies; return movies;
} }
var jsonResponse = JsonConvert.DeserializeObject<PersonCreditsRoot>(importResponse.Content); var jsonResponse = JsonConvert.DeserializeObject<PersonCreditsResource>(importResponse.Content);
// no movies were return // no movies were return
if (jsonResponse == null) if (jsonResponse == null)
@ -36,31 +36,31 @@ namespace NzbDrone.Core.NetImport.TMDb.Person
if (_settings.PersonCast) if (_settings.PersonCast)
{ {
foreach (var movie in jsonResponse.cast) foreach (var movie in jsonResponse.Cast)
{ {
// Movies with no Year Fix // Movies with no Year Fix
if (string.IsNullOrWhiteSpace(movie.release_date)) if (string.IsNullOrWhiteSpace(movie.ReleaseDate))
{ {
continue; continue;
} }
movies.AddIfNotNull(new Movie { TmdbId = movie.id }); movies.AddIfNotNull(new Movie { TmdbId = movie.Id });
} }
} }
if (crewTypes.Count > 0) if (crewTypes.Count > 0)
{ {
foreach (var movie in jsonResponse.crew) foreach (var movie in jsonResponse.Crew)
{ {
// Movies with no Year Fix // Movies with no Year Fix
if (string.IsNullOrWhiteSpace(movie.release_date)) if (string.IsNullOrWhiteSpace(movie.ReleaseDate))
{ {
continue; continue;
} }
if (crewTypes.Contains(movie.department)) if (crewTypes.Contains(movie.Department))
{ {
movies.AddIfNotNull(new Movie { TmdbId = movie.id }); movies.AddIfNotNull(new Movie { TmdbId = movie.Id });
} }
} }
} }

@ -1,86 +1,133 @@
using Newtonsoft.Json;
namespace NzbDrone.Core.NetImport.TMDb namespace NzbDrone.Core.NetImport.TMDb
{ {
public class MovieSearchRoot public class MovieSearchResource
{ {
public int Page { get; set; } public int Page { get; set; }
public MovieResult[] Results { get; set; } public MovieResultResource[] Results { get; set; }
public int total_results { get; set; }
public int total_pages { get; set; } [JsonProperty("total_results")]
public int TotalResults { get; set; }
[JsonProperty("total_pages")]
public int TotalPages { get; set; }
} }
public class AuthRefreshTokenResponse public class AuthRefreshTokenResource
{ {
public string request_token { get; set; } [JsonProperty("request_token")]
public string RequestToken { get; set; }
} }
public class AuthAccessTokenResponse public class AuthAccessTokenResource
{ {
public string access_token { get; set; } [JsonProperty("access_token")]
public string account_id { get; set; } public string AccessToken { get; set; }
[JsonProperty("account_id")]
public string AccountId { get; set; }
} }
public class MovieResult public class MovieResultResource
{ {
public string poster_path { get; set; } [JsonProperty("poster_path")]
public bool adult { get; set; } public string PosterPath { get; set; }
public string overview { get; set; } public bool Adult { get; set; }
public string release_date { get; set; } public string Overview { get; set; }
public int?[] genre_ids { get; set; }
public int id { get; set; } [JsonProperty("release_date")]
public string original_title { get; set; } public string ReleaseDate { get; set; }
public string original_language { get; set; }
public string title { get; set; } [JsonProperty("genre_ids")]
public string backdrop_path { get; set; } public int?[] GenreIds { get; set; }
public float popularity { get; set; } public int Id { get; set; }
public int vote_count { get; set; }
public bool video { get; set; } [JsonProperty("original_title")]
public float vote_average { get; set; } public string OriginalTitle { get; set; }
public string trailer_key { get; set; }
public string trailer_site { get; set; } [JsonProperty("original_language")]
public string physical_release { get; set; } public string OriginalLanguage { get; set; }
public string physical_release_note { get; set; } public string Title { get; set; }
[JsonProperty("backdrop_path")]
public string BackdropPath { get; set; }
public float Popularity { get; set; }
[JsonProperty("vote_count")]
public int VoteCount { get; set; }
public bool Video { get; set; }
[JsonProperty("vote_average")]
public float VoteAverage { get; set; }
[JsonProperty("trailer_key")]
public string TrailerKey { get; set; }
[JsonProperty("trailer_site")]
public string TrailerSite { get; set; }
[JsonProperty("physical_release")]
public string PhysicalRelease { get; set; }
[JsonProperty("physical_release_note")]
public string PhysicalReleaseNote { get; set; }
} }
public class CreditsResult : MovieResult public class CreditsResultResource : MovieResultResource
{ {
public string department { get; set; } public string Department { get; set; }
public string job { get; set; } public string Job { get; set; }
public string credit_id { get; set; }
[JsonProperty("credit_id")]
public string CreditId { get; set; }
} }
public class ListResponseRoot public class ListResponseResource
{ {
public string id { get; set; } public string Id { get; set; }
public Item[] items { get; set; } public ListItemResource[] Items { get; set; }
public int item_count { get; set; }
public string iso_639_1 { get; set; } [JsonProperty("item_count")]
public string name { get; set; } public int ItemCount { get; set; }
public object poster_path { 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 class CollectionResponseRoot public class CollectionResponseResource
{ {
public int id { get; set; } public int Id { get; set; }
public string name { get; set; } public string Name { get; set; }
public string overview { get; set; } public string Overview { get; set; }
public string poster_path { get; set; }
public string backdrop_path { get; set; } [JsonProperty("poster_path")]
public MovieResult[] parts { get; set; } public string PosterPath { get; set; }
[JsonProperty("backdrop_path")]
public string BackdropPath { get; set; }
public MovieResultResource[] Parts { get; set; }
} }
public class PersonCreditsRoot public class PersonCreditsResource
{ {
public CreditsResult[] cast { get; set; } public CreditsResultResource[] Cast { get; set; }
public CreditsResult[] crew { get; set; } public CreditsResultResource[] Crew { get; set; }
public int id { get; set; } public int Id { get; set; }
} }
public class Item : MovieResult public class ListItemResource : MovieResultResource
{ {
public string media_type { get; set; } [JsonProperty("media_type")]
public string first_air_date { get; set; } public string MediaType { get; set; }
public string[] origin_country { get; set; } [JsonProperty("origin_country")]
public string name { get; set; } public string[] OriginCountry { get; set; }
public string original_name { get; set; } public string Name { get; set; }
[JsonProperty("original_name")]
public string OriginalName { get; set; }
} }
} }

@ -22,7 +22,7 @@ namespace NzbDrone.Core.NetImport.TMDb
return movies; return movies;
} }
var jsonResponse = JsonConvert.DeserializeObject<MovieSearchRoot>(importResponse.Content); var jsonResponse = JsonConvert.DeserializeObject<MovieSearchResource>(importResponse.Content);
// no movies were return // no movies were return
if (jsonResponse == null) if (jsonResponse == null)
@ -33,24 +33,24 @@ namespace NzbDrone.Core.NetImport.TMDb
return jsonResponse.Results.SelectList(MapListMovie); return jsonResponse.Results.SelectList(MapListMovie);
} }
protected Movie MapListMovie(MovieResult movieResult) protected Movie MapListMovie(MovieResultResource movieResult)
{ {
var movie = new Movie var movie = new Movie
{ {
TmdbId = movieResult.id, TmdbId = movieResult.Id,
Overview = movieResult.overview, Overview = movieResult.Overview,
Title = movieResult.original_title, Title = movieResult.OriginalTitle,
SortTitle = Parser.Parser.NormalizeTitle(movieResult.original_title), SortTitle = Parser.Parser.NormalizeTitle(movieResult.OriginalTitle),
Images = new List<MediaCover.MediaCover>() Images = new List<MediaCover.MediaCover>()
}; };
if (movieResult.release_date.IsNotNullOrWhiteSpace()) if (movieResult.ReleaseDate.IsNotNullOrWhiteSpace())
{ {
DateTime.TryParse(movieResult.release_date, out var releaseDate); DateTime.TryParse(movieResult.ReleaseDate, out var releaseDate);
movie.Year = releaseDate.Year; movie.Year = releaseDate.Year;
} }
movie.Images.AddIfNotNull(MapPosterImage(movieResult.poster_path)); movie.Images.AddIfNotNull(MapPosterImage(movieResult.PosterPath));
return movie; return movie;
} }

@ -56,16 +56,16 @@ namespace NzbDrone.Core.NetImport.TMDb.User
var request = requestBuilder.Build(); var request = requestBuilder.Build();
var response = Json.Deserialize<AuthRefreshTokenResponse>(_httpClient.Execute(request).Content); var response = Json.Deserialize<AuthRefreshTokenResource>(_httpClient.Execute(request).Content);
var oAuthRequest = new HttpRequestBuilder(Settings.OAuthUrl) var oAuthRequest = new HttpRequestBuilder(Settings.OAuthUrl)
.AddQueryParam("request_token", response.request_token) .AddQueryParam("request_token", response.RequestToken)
.Build(); .Build();
return new return new
{ {
OauthUrl = oAuthRequest.Url.ToString(), OauthUrl = oAuthRequest.Url.ToString(),
RequestToken = response.request_token RequestToken = response.RequestToken
}; };
} }
else if (action == "getOAuthToken") else if (action == "getOAuthToken")
@ -81,12 +81,12 @@ namespace NzbDrone.Core.NetImport.TMDb.User
var request = requestBuilder.Build(); var request = requestBuilder.Build();
var response = Json.Deserialize<AuthAccessTokenResponse>(_httpClient.Execute(request).Content); var response = Json.Deserialize<AuthAccessTokenResource>(_httpClient.Execute(request).Content);
return new return new
{ {
accountId = response.account_id, accountId = response.AccountId,
accessToken = response.access_token, accessToken = response.AccessToken,
}; };
} }

Loading…
Cancel
Save