mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-05 18:42:42 +01:00
TMDb Filtering Options: Rating, Min Votes, Min Vote Ave, Original Language, TMDb Genre Ids (CSV), (#765)
This commit is contained in:
parent
f393a95501
commit
50891e5dd7
@ -31,7 +31,7 @@ public TMDbParser(TMDbSettings settings)
|
||||
return movies;
|
||||
}
|
||||
|
||||
if (_settings.ListType != (int) TMDbListType.List)
|
||||
if (_settings.ListType != (int)TMDbListType.List)
|
||||
{
|
||||
var jsonResponse = JsonConvert.DeserializeObject<MovieSearchRoot>(_importResponse.Content);
|
||||
|
||||
@ -43,16 +43,13 @@ public TMDbParser(TMDbSettings settings)
|
||||
|
||||
foreach (var movie in jsonResponse.results)
|
||||
{
|
||||
if (movie.vote_average >= double.Parse(_settings.MinVoteAverage))
|
||||
movies.AddIfNotNull(new Tv.Movie()
|
||||
{
|
||||
movies.AddIfNotNull(new Tv.Movie()
|
||||
{
|
||||
Title = movie.title,
|
||||
TmdbId = movie.id,
|
||||
ImdbId = null,
|
||||
Year = DateTime.Parse(movie.release_date).Year
|
||||
});
|
||||
}
|
||||
Title = movie.title,
|
||||
TmdbId = movie.id,
|
||||
ImdbId = null,
|
||||
Year = DateTime.Parse(movie.release_date).Year
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -73,16 +70,13 @@ public TMDbParser(TMDbSettings settings)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (movie.vote_average >= double.Parse(_settings.MinVoteAverage))
|
||||
movies.AddIfNotNull(new Tv.Movie()
|
||||
{
|
||||
movies.AddIfNotNull(new Tv.Movie()
|
||||
{
|
||||
Title = movie.title,
|
||||
TmdbId = movie.id,
|
||||
ImdbId = null,
|
||||
Year = DateTime.Parse(movie.release_date).Year
|
||||
});
|
||||
}
|
||||
Title = movie.title,
|
||||
TmdbId = movie.id,
|
||||
ImdbId = null,
|
||||
Year = DateTime.Parse(movie.release_date).Year
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,4 +101,4 @@ protected virtual bool PreProcess(NetImportResponse indexerResponse)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using NzbDrone.Common.Http;
|
||||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
|
||||
|
||||
@ -13,50 +14,67 @@ public class TMDbRequestGenerator : INetImportRequestGenerator
|
||||
public IHttpClient HttpClient { get; set; }
|
||||
public Logger Logger { get; set; }
|
||||
|
||||
//public string TMDbApiUrl { get; set; }
|
||||
public int MaxPages { get; set; }
|
||||
|
||||
public TMDbRequestGenerator()
|
||||
{
|
||||
MaxPages = 3;
|
||||
// TMDbApiUrl = "https://api.themoviedb.org";
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
case (int)TMDbListType.List:
|
||||
searchType = $"/3/list/{Settings.ListId}";
|
||||
tmdbParams = $"/3/list/{Settings.ListId}/?api_key=1a7373301961d03f97f853a876dd1212";
|
||||
break;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
var pageableRequests = new NetImportPageableRequestChain();
|
||||
if (Settings.ListType != (int) TMDbListType.List)
|
||||
if (Settings.ListType != (int)TMDbListType.List)
|
||||
{
|
||||
// First query to get the total_Pages
|
||||
var requestBuilder = new HttpRequestBuilder($"{Settings.Link.Trim()}")
|
||||
var requestBuilder = new HttpRequestBuilder($"{Settings.Link.TrimEnd("/")}")
|
||||
{
|
||||
LogResponseContent = true
|
||||
};
|
||||
|
||||
requestBuilder.Method = HttpMethod.GET;
|
||||
requestBuilder.Resource(searchType);
|
||||
requestBuilder.Resource(tmdbParams);
|
||||
|
||||
var request = requestBuilder
|
||||
.AddQueryParam("api_key", "1a7373301961d03f97f853a876dd1212")
|
||||
// .AddQueryParam("api_key", "1a7373301961d03f97f853a876dd1212")
|
||||
.Accept(HttpAccept.Json)
|
||||
.Build();
|
||||
|
||||
@ -64,20 +82,18 @@ public virtual NetImportPageableRequestChain GetMovies()
|
||||
var result = Json.Deserialize<MovieSearchRoot>(response.Content);
|
||||
|
||||
// @TODO Prolly some error handling to do here
|
||||
pageableRequests.Add(GetPagedRequests(searchType, result.total_pages));
|
||||
pageableRequests.Add(GetPagedRequests(tmdbParams, result.total_pages));
|
||||
return pageableRequests;
|
||||
}
|
||||
else
|
||||
{
|
||||
pageableRequests.Add(GetPagedRequests(searchType, 0));
|
||||
return pageableRequests;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<NetImportRequest> GetPagedRequests(string searchType, int totalPages)
|
||||
|
||||
pageableRequests.Add(GetPagedRequests(tmdbParams, 0));
|
||||
return pageableRequests;
|
||||
}
|
||||
|
||||
private IEnumerable<NetImportRequest> GetPagedRequests(string tmdbParams, int totalPages)
|
||||
{
|
||||
var baseUrl = $"{Settings.Link.Trim()}{searchType}?api_key=1a7373301961d03f97f853a876dd1212";
|
||||
if (Settings.ListType != (int) TMDbListType.List)
|
||||
var baseUrl = $"{Settings.Link.TrimEnd("/")}{tmdbParams}";
|
||||
if (Settings.ListType != (int)TMDbListType.List)
|
||||
{
|
||||
for (var pageNumber = 1; pageNumber <= totalPages; pageNumber++)
|
||||
{
|
||||
@ -89,16 +105,16 @@ private IEnumerable<NetImportRequest> GetPagedRequests(string searchType, int to
|
||||
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);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Trace($"Importing TMDb movies from: {baseUrl}");
|
||||
Logger.Info($"Importing TMDb movies from: {baseUrl}");
|
||||
yield return new NetImportRequest($"{baseUrl}", HttpAccept.Json);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using FluentValidation;
|
||||
using FluentValidation;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Validation;
|
||||
|
||||
@ -12,7 +10,8 @@ public class TMDbSettingsValidator : AbstractValidator<TMDbSettings>
|
||||
public TMDbSettingsValidator()
|
||||
{
|
||||
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 @@ public TMDbSettings()
|
||||
{
|
||||
Link = "https://api.themoviedb.org";
|
||||
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.")]
|
||||
@ -33,14 +33,26 @@ public TMDbSettings()
|
||||
[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; }
|
||||
|
||||
//[FieldDefinition(2, Label = "Language", Type = FieldType.Select, SelectOptions = typeof(TMDbLanguageCodes), HelpText = "Filter movies by Language")]
|
||||
//public int Language { get; set; }
|
||||
[FieldDefinition(2, Label = "Public List ID", HelpText = "Required for List (Ignores Filtering Options)")]
|
||||
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; }
|
||||
|
||||
[FieldDefinition(3, Label = "Public List ID", HelpText = "Required for List")]
|
||||
public string ListId { get; set; }
|
||||
[FieldDefinition(4, Label = "Minimum Number of Votes", HelpText = "Filter movies by number of votes")]
|
||||
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()
|
||||
{
|
||||
@ -48,8 +60,4 @@ public TMDbSettings()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user