feat(discover): Show more relevant shows in upcoming TV

pull/4630/head
sephrat 3 years ago
parent b54fba5c99
commit 8357819b53

@ -161,7 +161,7 @@ namespace Ombi.Core.Engine
var result = await Cache.GetOrAddAsync(CacheKeys.UpcomingMovies, async () => var result = await Cache.GetOrAddAsync(CacheKeys.UpcomingMovies, async () =>
{ {
var langCode = await DefaultLanguageCode(null); var langCode = await DefaultLanguageCode(null);
return await MovieApi.Upcoming(langCode); return await MovieApi.UpcomingMovies(langCode);
}, DateTimeOffset.Now.AddHours(12)); }, DateTimeOffset.Now.AddHours(12));
if (result != null) if (result != null)
{ {

@ -287,7 +287,7 @@ namespace Ombi.Core.Engine.V2
var result = await Cache.GetOrAddAsync(CacheKeys.UpcomingMovies, async () => var result = await Cache.GetOrAddAsync(CacheKeys.UpcomingMovies, async () =>
{ {
var langCode = await DefaultLanguageCode(null); var langCode = await DefaultLanguageCode(null);
return await MovieApi.Upcoming(langCode); return await MovieApi.UpcomingMovies(langCode);
}, DateTimeOffset.Now.AddHours(12)); }, DateTimeOffset.Now.AddHours(12));
if (result != null) if (result != null)
{ {
@ -307,7 +307,7 @@ namespace Ombi.Core.Engine.V2
foreach (var pagesToLoad in pages) foreach (var pagesToLoad in pages)
{ {
var apiResult = await Cache.GetOrAddAsync(nameof(UpcomingMovies) + pagesToLoad.Page + langCode, var apiResult = await Cache.GetOrAddAsync(nameof(UpcomingMovies) + pagesToLoad.Page + langCode,
() => MovieApi.Upcoming(langCode, pagesToLoad.Page), DateTimeOffset.Now.AddHours(12)); () => MovieApi.UpcomingMovies(langCode, pagesToLoad.Page), DateTimeOffset.Now.AddHours(12));
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take)); results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
} }
return await TransformMovieResultsToResponse(results); return await TransformMovieResultsToResponse(results);

@ -22,7 +22,7 @@ namespace Ombi.Api.TheMovieDb
Task<List<MovieDbSearchResult>> GetMoviesViaKeywords(string keywordId, string langCode, CancellationToken cancellationToken, int? page = null); Task<List<MovieDbSearchResult>> GetMoviesViaKeywords(string keywordId, string langCode, CancellationToken cancellationToken, int? page = null);
Task<List<TvSearchResult>> SearchTv(string searchTerm, string year = default); Task<List<TvSearchResult>> SearchTv(string searchTerm, string year = default);
Task<List<MovieDbSearchResult>> TopRated(string languageCode, int? page = null); Task<List<MovieDbSearchResult>> TopRated(string languageCode, int? page = null);
Task<List<MovieDbSearchResult>> Upcoming(string languageCode, int? page = null); Task<List<MovieDbSearchResult>> UpcomingMovies(string languageCode, int? page = null);
Task<List<MovieDbSearchResult>> TopRatedTv(string languageCode, int? page = null); Task<List<MovieDbSearchResult>> TopRatedTv(string languageCode, int? page = null);
Task<List<MovieDbSearchResult>> TrendingTv(string languageCode, int? page = null); Task<List<MovieDbSearchResult>> TrendingTv(string languageCode, int? page = null);
Task<List<MovieDbSearchResult>> UpcomingTv(string languageCode, int? page = null); Task<List<MovieDbSearchResult>> UpcomingTv(string languageCode, int? page = null);

@ -308,22 +308,12 @@ namespace Ombi.Api.TheMovieDb
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request); var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieDbSearchResult>>(result.results); return Mapper.Map<List<MovieDbSearchResult>>(result.results);
} }
public Task<List<MovieDbSearchResult>> Upcoming(string langCode, int? page = null)
{
return Upcoming("movie", langCode, page);
}
public Task<List<MovieDbSearchResult>> UpcomingTv(string langCode, int? page = null)
{
return Upcoming("tv", langCode, page);
}
/// <remarks> /// <remarks>
/// Maintains filter parity with <a href="https://developers.themoviedb.org/3/movies/get-upcoming">/movie/upcoming</a>. /// Maintains filter parity with <a href="https://developers.themoviedb.org/3/movies/get-upcoming">/movie/upcoming</a>.
/// </remarks> /// </remarks>
private async Task<List<MovieDbSearchResult>> Upcoming(string type, string langCode, int? page = null) public async Task<List<MovieDbSearchResult>> UpcomingMovies(string langCode, int? page = null)
{ {
var request = new Request($"discover/{type}", BaseUri, HttpMethod.Get); var request = new Request($"discover/movie", BaseUri, HttpMethod.Get);
request.AddQueryString("api_key", ApiToken); request.AddQueryString("api_key", ApiToken);
request.AddQueryString("language", langCode); request.AddQueryString("language", langCode);
@ -340,7 +330,27 @@ namespace Ombi.Api.TheMovieDb
request.AddQueryString("page", page.ToString()); request.AddQueryString("page", page.ToString());
} }
await AddDiscoverSettings(request); await AddDiscoverSettings(request);
await AddGenreFilter(request, type); await AddGenreFilter(request, "movie");
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieDbSearchResult>>(result.results);
}
public async Task<List<MovieDbSearchResult>> UpcomingTv(string langCode, int? page = null)
{
var request = new Request($"discover/tv", BaseUri, HttpMethod.Get);
request.AddQueryString("api_key", ApiToken);
request.AddQueryString("language", langCode);
// Search for shows that will air in the next month
var startDate = DateTime.Today.AddDays(1);
request.AddQueryString($"first_air_date.gte", startDate.ToString("yyyy-MM-dd"));
request.AddQueryString($"first_air_date.lte", startDate.AddDays(30).ToString("yyyy-MM-dd"));
if (page != null)
{
request.AddQueryString("page", page.ToString());
}
await AddDiscoverSettings(request);
await AddGenreFilter(request, "tv");
AddRetry(request); AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request); var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieDbSearchResult>>(result.results); return Mapper.Map<List<MovieDbSearchResult>>(result.results);

Loading…
Cancel
Save