Add genre filtering function; Add genre filter to discovery

pull/4199/head
first last 4 years ago
parent 53523b35db
commit 2c94f982c6

@ -202,6 +202,7 @@ namespace Ombi.Api.TheMovieDb
request.AddQueryString("page", page.ToString());
}
await AddDiscoverSettings(request);
await AddGenreFilter(request, type);
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request, cancellationToken);
return Mapper.Map<List<MovieDbSearchResult>>(result.results);
@ -237,6 +238,7 @@ namespace Ombi.Api.TheMovieDb
request.AddQueryString("vote_count.gte", "250");
await AddDiscoverSettings(request);
await AddGenreFilter(request, type);
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieDbSearchResult>>(result.results);
@ -273,6 +275,7 @@ namespace Ombi.Api.TheMovieDb
request.AddQueryString("page", page.ToString());
}
await AddDiscoverSettings(request);
await AddGenreFilter(request, type);
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieDbSearchResult>>(result.results);
@ -301,6 +304,7 @@ namespace Ombi.Api.TheMovieDb
}
await AddDiscoverSettings(request);
await AddGenreFilter(request, "movie");
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieDbSearchResult>>(result.results);
@ -394,6 +398,28 @@ namespace Ombi.Api.TheMovieDb
}
}
private async Task AddGenreFilter(Request request, string media_type)
{
var settings = await Settings;
List<int> excludedGenres;
switch (media_type) {
case "tv":
excludedGenres = settings.ExcludedTvGenreIds;
break;
case "movie":
excludedGenres = settings.ExcludedMovieGenreIds;
break;
default:
return;
}
if (excludedGenres?.Any() == true)
{
request.AddQueryString("without_genres", string.Join(",", excludedGenres));
}
}
private static void AddRetry(Request request)
{
request.Retry = true;

Loading…
Cancel
Save