TMDb Filtering Options: Rating, Min Votes, Min Vote Ave, Original Language, TMDb Genre Ids (CSV), (#765)

pull/605/merge
Devin Buhl 8 years ago committed by GitHub
parent f393a95501
commit 50891e5dd7

@ -42,8 +42,6 @@ namespace NzbDrone.Core.NetImport.TMDb
} }
foreach (var movie in jsonResponse.results) foreach (var movie in jsonResponse.results)
{
if (movie.vote_average >= double.Parse(_settings.MinVoteAverage))
{ {
movies.AddIfNotNull(new Tv.Movie() movies.AddIfNotNull(new Tv.Movie()
{ {
@ -54,7 +52,6 @@ namespace NzbDrone.Core.NetImport.TMDb
}); });
} }
} }
}
else else
{ {
var jsonResponse = JsonConvert.DeserializeObject<ListResponseRoot>(_importResponse.Content); var jsonResponse = JsonConvert.DeserializeObject<ListResponseRoot>(_importResponse.Content);
@ -73,8 +70,6 @@ namespace NzbDrone.Core.NetImport.TMDb
continue; continue;
} }
if (movie.vote_average >= double.Parse(_settings.MinVoteAverage))
{
movies.AddIfNotNull(new Tv.Movie() movies.AddIfNotNull(new Tv.Movie()
{ {
Title = movie.title, Title = movie.title,
@ -84,7 +79,6 @@ namespace NzbDrone.Core.NetImport.TMDb
}); });
} }
} }
}
return movies; return movies;

@ -2,6 +2,7 @@
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
using System.Collections.Generic; using System.Collections.Generic;
using NLog; using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Serializer; using NzbDrone.Common.Serializer;
using NzbDrone.Core.MetadataSource.SkyHook.Resource; using NzbDrone.Core.MetadataSource.SkyHook.Resource;
@ -13,33 +14,50 @@ namespace NzbDrone.Core.NetImport.TMDb
public IHttpClient HttpClient { get; set; } public IHttpClient HttpClient { get; set; }
public Logger Logger { get; set; } public Logger Logger { get; set; }
//public string TMDbApiUrl { get; set; }
public int MaxPages { get; set; } public int MaxPages { get; set; }
public TMDbRequestGenerator() public TMDbRequestGenerator()
{ {
MaxPages = 3; MaxPages = 3;
// TMDbApiUrl = "https://api.themoviedb.org";
} }
public virtual NetImportPageableRequestChain GetMovies() public virtual NetImportPageableRequestChain GetMovies()
{ {
var searchType = ""; var minVoteCount = Settings.MinVotes;
var minVoteAverage = Settings.MinVoteAverage;
var ceritification = Settings.Ceritification;
var includeGenreIds = Settings.IncludeGenreIds;
var excludeGenreIds = Settings.ExcludeGenreIds;
var languageCode = (TMDbLanguageCodes)Settings.LanguageCode;
var todaysDate = DateTime.Now.ToString("yyyy-MM-dd");
var threeMonthsAgo = DateTime.Parse(todaysDate).AddMonths(-3).ToString("yyyy-MM-dd");
var threeMonthsFromNow = DateTime.Parse(todaysDate).AddMonths(3).ToString("yyyy-MM-dd");
if (ceritification.IsNotNullOrWhiteSpace())
{
ceritification = $"&certification_country=US&certification={ceritification}";
}
var tmdbParams = "";
switch (Settings.ListType) switch (Settings.ListType)
{ {
case (int)TMDbListType.List: case (int)TMDbListType.List:
searchType = $"/3/list/{Settings.ListId}"; tmdbParams = $"/3/list/{Settings.ListId}/?api_key=1a7373301961d03f97f853a876dd1212";
break; break;
case (int)TMDbListType.Theaters: case (int)TMDbListType.Theaters:
searchType = "/3/movie/now_playing"; tmdbParams = $"/3/discover/movie?api_key=1a7373301961d03f97f853a876dd1212&primary_release_date.gte={threeMonthsAgo}&primary_release_date.lte={todaysDate}&vote_count.gte={minVoteCount}&vote_average.gte={minVoteAverage}{ceritification}&with_genres={includeGenreIds}&without_genres={excludeGenreIds}&with_original_language={languageCode}";
break; break;
case (int)TMDbListType.Popular: case (int)TMDbListType.Popular:
searchType = "/3/movie/popular"; tmdbParams = $"/3/discover/movie?api_key=1a7373301961d03f97f853a876dd1212&sort_by=popularity.desc&vote_count.gte={minVoteCount}&vote_average.gte={minVoteAverage}{ceritification}&with_genres={includeGenreIds}&without_genres={excludeGenreIds}&with_original_language={languageCode}";
break; break;
case (int)TMDbListType.Top: case (int)TMDbListType.Top:
searchType = "/3/movie/top_rated"; tmdbParams = $"/3/discover/movie?api_key=1a7373301961d03f97f853a876dd1212&sort_by=vote_average.desc&vote_count.gte={minVoteCount}&vote_average.gte={minVoteAverage}{ceritification}&with_genres={includeGenreIds}&without_genres={excludeGenreIds}&with_original_language={languageCode}";
break; break;
case (int)TMDbListType.Upcoming: case (int)TMDbListType.Upcoming:
searchType = "/3/movie/upcoming"; tmdbParams = $"/3/discover/movie?api_key=1a7373301961d03f97f853a876dd1212&primary_release_date.gte={todaysDate}&primary_release_date.lte={threeMonthsFromNow}&vote_count.gte={minVoteCount}&vote_average.gte={minVoteAverage}{ceritification}&with_genres={includeGenreIds}&without_genres={excludeGenreIds}&with_original_language={languageCode}";
break; break;
} }
@ -47,16 +65,16 @@ namespace NzbDrone.Core.NetImport.TMDb
if (Settings.ListType != (int)TMDbListType.List) if (Settings.ListType != (int)TMDbListType.List)
{ {
// First query to get the total_Pages // First query to get the total_Pages
var requestBuilder = new HttpRequestBuilder($"{Settings.Link.Trim()}") var requestBuilder = new HttpRequestBuilder($"{Settings.Link.TrimEnd("/")}")
{ {
LogResponseContent = true LogResponseContent = true
}; };
requestBuilder.Method = HttpMethod.GET; requestBuilder.Method = HttpMethod.GET;
requestBuilder.Resource(searchType); requestBuilder.Resource(tmdbParams);
var request = requestBuilder var request = requestBuilder
.AddQueryParam("api_key", "1a7373301961d03f97f853a876dd1212") // .AddQueryParam("api_key", "1a7373301961d03f97f853a876dd1212")
.Accept(HttpAccept.Json) .Accept(HttpAccept.Json)
.Build(); .Build();
@ -64,19 +82,17 @@ namespace NzbDrone.Core.NetImport.TMDb
var result = Json.Deserialize<MovieSearchRoot>(response.Content); var result = Json.Deserialize<MovieSearchRoot>(response.Content);
// @TODO Prolly some error handling to do here // @TODO Prolly some error handling to do here
pageableRequests.Add(GetPagedRequests(searchType, result.total_pages)); pageableRequests.Add(GetPagedRequests(tmdbParams, result.total_pages));
return pageableRequests; return pageableRequests;
} }
else
{ pageableRequests.Add(GetPagedRequests(tmdbParams, 0));
pageableRequests.Add(GetPagedRequests(searchType, 0));
return pageableRequests; return pageableRequests;
} }
}
private IEnumerable<NetImportRequest> GetPagedRequests(string searchType, int totalPages) private IEnumerable<NetImportRequest> GetPagedRequests(string tmdbParams, int totalPages)
{ {
var baseUrl = $"{Settings.Link.Trim()}{searchType}?api_key=1a7373301961d03f97f853a876dd1212"; var baseUrl = $"{Settings.Link.TrimEnd("/")}{tmdbParams}";
if (Settings.ListType != (int)TMDbListType.List) if (Settings.ListType != (int)TMDbListType.List)
{ {
for (var pageNumber = 1; pageNumber <= totalPages; pageNumber++) for (var pageNumber = 1; pageNumber <= totalPages; pageNumber++)
@ -89,13 +105,13 @@ namespace NzbDrone.Core.NetImport.TMDb
break; break;
} }
Logger.Trace($"Importing TMDb movies from: {baseUrl}&page={pageNumber}"); Logger.Info($"Importing TMDb movies from: {baseUrl}&page={pageNumber}");
yield return new NetImportRequest($"{baseUrl}&page={pageNumber}", HttpAccept.Json); yield return new NetImportRequest($"{baseUrl}&page={pageNumber}", HttpAccept.Json);
} }
} }
else else
{ {
Logger.Trace($"Importing TMDb movies from: {baseUrl}"); Logger.Info($"Importing TMDb movies from: {baseUrl}");
yield return new NetImportRequest($"{baseUrl}", HttpAccept.Json); yield return new NetImportRequest($"{baseUrl}", HttpAccept.Json);
} }

@ -1,6 +1,4 @@
using System.Collections.Generic; using FluentValidation;
using System.Globalization;
using FluentValidation;
using NzbDrone.Core.Annotations; using NzbDrone.Core.Annotations;
using NzbDrone.Core.Validation; using NzbDrone.Core.Validation;
@ -12,7 +10,8 @@ namespace NzbDrone.Core.NetImport.TMDb
public TMDbSettingsValidator() public TMDbSettingsValidator()
{ {
RuleFor(c => c.Link).ValidRootUrl(); RuleFor(c => c.Link).ValidRootUrl();
RuleFor(c => double.Parse(c.MinVoteAverage)).ExclusiveBetween(0, 10); RuleFor(c => double.Parse(c.MinVoteAverage)).InclusiveBetween(0, 10);
RuleFor(c => c.MinVotes).GreaterThan(0);
} }
} }
@ -24,7 +23,8 @@ namespace NzbDrone.Core.NetImport.TMDb
{ {
Link = "https://api.themoviedb.org"; Link = "https://api.themoviedb.org";
MinVoteAverage = "5.5"; MinVoteAverage = "5.5";
// Language = (int) TMDbLanguageCodes.en; MinVotes = 1000;
LanguageCode = (int)TMDbLanguageCodes.en;
} }
[FieldDefinition(0, Label = "TMDb API URL", HelpText = "Link to to TMDb API URL, do not change unless you know what you are doing.")] [FieldDefinition(0, Label = "TMDb API URL", HelpText = "Link to to TMDb API URL, do not change unless you know what you are doing.")]
@ -33,14 +33,26 @@ namespace NzbDrone.Core.NetImport.TMDb
[FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(TMDbListType), HelpText = "Type of list your seeking to import from")] [FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(TMDbListType), HelpText = "Type of list your seeking to import from")]
public int ListType { get; set; } public int ListType { get; set; }
//[FieldDefinition(2, Label = "Language", Type = FieldType.Select, SelectOptions = typeof(TMDbLanguageCodes), HelpText = "Filter movies by Language")] [FieldDefinition(2, Label = "Public List ID", HelpText = "Required for List (Ignores Filtering Options)")]
//public int Language { get; set; } public string ListId { get; set; }
[FieldDefinition(2, Label = "Minimum Vote Average", HelpText = "Filter movies by rating (0.0-10.0)")] [FieldDefinition(3, Label = "Minimum Vote Average", HelpText = "Filter movies by votes (0.0-10.0)")]
public string MinVoteAverage { get; set; } public string MinVoteAverage { get; set; }
[FieldDefinition(3, Label = "Public List ID", HelpText = "Required for List")] [FieldDefinition(4, Label = "Minimum Number of Votes", HelpText = "Filter movies by number of votes")]
public string ListId { get; set; } public int MinVotes { get; set; }
[FieldDefinition(5, Label = "Rating", HelpText = "Filter movies by a rating (NR,G,PG,PG-13,R,NC-17)")]
public string Ceritification { get; set; }
[FieldDefinition(6, Label = "Include Genre Ids", HelpText = "Filter movies by TMDb Genre Ids (Comma Separated)")]
public string IncludeGenreIds { get; set; }
[FieldDefinition(7, Label = "Exclude Genre Ids", HelpText = "Filter movies by TMDb Genre Ids (Comma Separated)")]
public string ExcludeGenreIds { get; set; }
[FieldDefinition(8, Label = "Original Language", Type = FieldType.Select, SelectOptions = typeof(TMDbLanguageCodes), HelpText = "Filter by Language")]
public int LanguageCode { get; set; }
public new NzbDroneValidationResult Validate() public new NzbDroneValidationResult Validate()
{ {
@ -48,8 +60,4 @@ namespace NzbDrone.Core.NetImport.TMDb
} }
} }
} }
Loading…
Cancel
Save