1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Cleanup TMDB Resources

This commit is contained in:
Qstick 2020-05-19 21:17:39 -04:00
parent 50f84101e0
commit d3d3117bf3
8 changed files with 136 additions and 89 deletions

View File

@ -60,9 +60,9 @@ public HashSet<int> GetChangedMovies(DateTime startTime)
request.AllowAutoRedirect = 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)

View File

@ -24,7 +24,7 @@ public IList<Movie> ParseResponse(NetImportResponse netMovieImporterResponse)
return movies;
}
var jsonResponse = JsonConvert.DeserializeObject<List<MovieResult>>(importResponse.Content);
var jsonResponse = JsonConvert.DeserializeObject<List<MovieResultResource>>(importResponse.Content);
// no movies were return
if (jsonResponse == null)
@ -32,7 +32,7 @@ public IList<Movie> ParseResponse(NetImportResponse netMovieImporterResponse)
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)

View File

@ -17,7 +17,7 @@ public override IList<Movie> ParseResponse(NetImportResponse importResponse)
return movies;
}
var jsonResponse = JsonConvert.DeserializeObject<CollectionResponseRoot>(importResponse.Content);
var jsonResponse = JsonConvert.DeserializeObject<CollectionResponseResource>(importResponse.Content);
// no movies were return
if (jsonResponse == null)
@ -25,10 +25,10 @@ public override IList<Movie> ParseResponse(NetImportResponse importResponse)
return movies;
}
foreach (var movie in jsonResponse.parts)
foreach (var movie in jsonResponse.Parts)
{
// Movies with no Year Fix
if (string.IsNullOrWhiteSpace(movie.release_date))
if (string.IsNullOrWhiteSpace(movie.ReleaseDate))
{
continue;
}

View File

@ -17,7 +17,7 @@ public override IList<Movie> ParseResponse(NetImportResponse importResponse)
return movies;
}
var jsonResponse = JsonConvert.DeserializeObject<ListResponseRoot>(importResponse.Content);
var jsonResponse = JsonConvert.DeserializeObject<ListResponseResource>(importResponse.Content);
// no movies were return
if (jsonResponse == null)
@ -25,10 +25,10 @@ public override IList<Movie> ParseResponse(NetImportResponse importResponse)
return movies;
}
foreach (var movie in jsonResponse.items)
foreach (var movie in jsonResponse.Items)
{
// Movies with no Year Fix
if (string.IsNullOrWhiteSpace(movie.release_date))
if (string.IsNullOrWhiteSpace(movie.ReleaseDate))
{
continue;
}

View File

@ -24,7 +24,7 @@ public override IList<Movie> ParseResponse(NetImportResponse importResponse)
return movies;
}
var jsonResponse = JsonConvert.DeserializeObject<PersonCreditsRoot>(importResponse.Content);
var jsonResponse = JsonConvert.DeserializeObject<PersonCreditsResource>(importResponse.Content);
// no movies were return
if (jsonResponse == null)
@ -36,31 +36,31 @@ public override IList<Movie> ParseResponse(NetImportResponse importResponse)
if (_settings.PersonCast)
{
foreach (var movie in jsonResponse.cast)
foreach (var movie in jsonResponse.Cast)
{
// Movies with no Year Fix
if (string.IsNullOrWhiteSpace(movie.release_date))
if (string.IsNullOrWhiteSpace(movie.ReleaseDate))
{
continue;
}
movies.AddIfNotNull(new Movie { TmdbId = movie.id });
movies.AddIfNotNull(new Movie { TmdbId = movie.Id });
}
}
if (crewTypes.Count > 0)
{
foreach (var movie in jsonResponse.crew)
foreach (var movie in jsonResponse.Crew)
{
// Movies with no Year Fix
if (string.IsNullOrWhiteSpace(movie.release_date))
if (string.IsNullOrWhiteSpace(movie.ReleaseDate))
{
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 });
}
}
}

View File

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

View File

@ -22,7 +22,7 @@ public virtual IList<Movie> ParseResponse(NetImportResponse importResponse)
return movies;
}
var jsonResponse = JsonConvert.DeserializeObject<MovieSearchRoot>(importResponse.Content);
var jsonResponse = JsonConvert.DeserializeObject<MovieSearchResource>(importResponse.Content);
// no movies were return
if (jsonResponse == null)
@ -33,24 +33,24 @@ public virtual IList<Movie> ParseResponse(NetImportResponse importResponse)
return jsonResponse.Results.SelectList(MapListMovie);
}
protected Movie MapListMovie(MovieResult movieResult)
protected Movie MapListMovie(MovieResultResource movieResult)
{
var movie = new Movie
{
TmdbId = movieResult.id,
Overview = movieResult.overview,
Title = movieResult.original_title,
SortTitle = Parser.Parser.NormalizeTitle(movieResult.original_title),
TmdbId = movieResult.Id,
Overview = movieResult.Overview,
Title = movieResult.OriginalTitle,
SortTitle = Parser.Parser.NormalizeTitle(movieResult.OriginalTitle),
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.Images.AddIfNotNull(MapPosterImage(movieResult.poster_path));
movie.Images.AddIfNotNull(MapPosterImage(movieResult.PosterPath));
return movie;
}

View File

@ -56,16 +56,16 @@ public override object RequestAction(string action, IDictionary<string, string>
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)
.AddQueryParam("request_token", response.request_token)
.AddQueryParam("request_token", response.RequestToken)
.Build();
return new
{
OauthUrl = oAuthRequest.Url.ToString(),
RequestToken = response.request_token
RequestToken = response.RequestToken
};
}
else if (action == "getOAuthToken")
@ -81,12 +81,12 @@ public override object RequestAction(string action, IDictionary<string, string>
var request = requestBuilder.Build();
var response = Json.Deserialize<AuthAccessTokenResponse>(_httpClient.Execute(request).Content);
var response = Json.Deserialize<AuthAccessTokenResource>(_httpClient.Execute(request).Content);
return new
{
accountId = response.account_id,
accessToken = response.access_token,
accountId = response.AccountId,
accessToken = response.AccessToken,
};
}