mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
feat(discover): Add new trending source experimental feature
This commit is contained in:
parent
e0a23313c1
commit
1a0823ca80
11 changed files with 93 additions and 8 deletions
|
@ -17,6 +17,7 @@ namespace Ombi.Core.Engine.Interfaces
|
|||
Task<IEnumerable<SearchMovieViewModel>> UpcomingMovies();
|
||||
Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies();
|
||||
Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies(int currentPosition, int amountToLoad);
|
||||
Task<IEnumerable<SearchMovieViewModel>> TrendingMovies(int currentPosition, int amountToLoad);
|
||||
Task<MovieCollectionsViewModel> GetCollection(int collectionId, CancellationToken cancellationToken, string langCode = null);
|
||||
Task<int> GetTvDbId(int theMovieDbId);
|
||||
Task<IEnumerable<SearchMovieViewModel>> PopularMovies(int currentlyLoaded, int toLoad, CancellationToken cancellationToken, string langCustomCode = null);
|
||||
|
|
|
@ -209,6 +209,22 @@ namespace Ombi.Core.Engine.V2
|
|||
return await TransformMovieResultsToResponse(results);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<SearchMovieViewModel>> TrendingMovies(int currentPosition, int amountToLoad)
|
||||
{
|
||||
var langCode = await DefaultLanguageCode(null);
|
||||
|
||||
var pages = PaginationHelper.GetNextPages(currentPosition, amountToLoad, _theMovieDbMaxPageItems);
|
||||
|
||||
var results = new List<MovieDbSearchResult>();
|
||||
foreach (var pagesToLoad in pages)
|
||||
{
|
||||
var apiResult = await Cache.GetOrAddAsync(nameof(NowPlayingMovies) + pagesToLoad.Page + langCode,
|
||||
() => MovieApi.TrendingMovies(langCode, pagesToLoad.Page), DateTimeOffset.Now.AddHours(12));
|
||||
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
|
||||
}
|
||||
return await TransformMovieResultsToResponse(results);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<SearchMovieViewModel>> SeasonalList(int currentPosition, int amountToLoad, CancellationToken cancellationToken)
|
||||
{
|
||||
var langCode = await DefaultLanguageCode(null);
|
||||
|
|
|
@ -26,6 +26,7 @@ using System.Diagnostics;
|
|||
using Ombi.Core.Engine.Interfaces;
|
||||
using Ombi.Core.Models.UI;
|
||||
using Ombi.Core.Helpers;
|
||||
using Ombi.Core.Services;
|
||||
|
||||
namespace Ombi.Core.Engine.V2
|
||||
{
|
||||
|
@ -37,10 +38,12 @@ namespace Ombi.Core.Engine.V2
|
|||
private readonly IMovieDbApi _movieApi;
|
||||
private readonly ISettingsService<CustomizationSettings> _customization;
|
||||
private readonly ITvRequestEngine _requestEngine;
|
||||
private readonly IFeatureService _feature;
|
||||
|
||||
public TvSearchEngineV2(ICurrentUser identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper,
|
||||
ITraktApi trakt, IRuleEvaluator r, OmbiUserManager um, ICacheService memCache, ISettingsService<OmbiSettings> s,
|
||||
IRepository<RequestSubscription> sub, IMovieDbApi movieApi, ISettingsService<CustomizationSettings> customization, ITvRequestEngine requestEngine)
|
||||
IRepository<RequestSubscription> sub, IMovieDbApi movieApi, ISettingsService<CustomizationSettings> customization, ITvRequestEngine requestEngine,
|
||||
IFeatureService feature)
|
||||
: base(identity, service, r, um, memCache, s, sub)
|
||||
{
|
||||
_tvMaze = tvMaze;
|
||||
|
@ -49,6 +52,7 @@ namespace Ombi.Core.Engine.V2
|
|||
_movieApi = movieApi;
|
||||
_customization = customization;
|
||||
_requestEngine = requestEngine;
|
||||
_feature = feature;
|
||||
}
|
||||
|
||||
|
||||
|
@ -134,13 +138,17 @@ namespace Ombi.Core.Engine.V2
|
|||
public async Task<IEnumerable<SearchTvShowViewModel>> Trending(int currentlyLoaded, int amountToLoad)
|
||||
{
|
||||
var langCode = await DefaultLanguageCode(null);
|
||||
var isNewTrendingSourceEnabled = await _feature.FeatureEnabled(FeatureNames.NewTrendingSource);
|
||||
|
||||
var pages = PaginationHelper.GetNextPages(currentlyLoaded, amountToLoad, ResultLimit);
|
||||
var results = new List<MovieDbSearchResult>();
|
||||
foreach (var pagesToLoad in pages)
|
||||
{
|
||||
var search = ( async () => (isNewTrendingSourceEnabled) ?
|
||||
await _movieApi.TrendingTv(langCode, pagesToLoad.Page)
|
||||
: await _movieApi.TopRatedTv(langCode, pagesToLoad.Page));
|
||||
var apiResult = await Cache.GetOrAddAsync(nameof(Trending) + langCode + pagesToLoad.Page,
|
||||
async () => await _movieApi.TopRatedTv(langCode, pagesToLoad.Page), DateTimeOffset.Now.AddHours(12));
|
||||
search, DateTimeOffset.Now.AddHours(12));
|
||||
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
|
||||
}
|
||||
|
||||
|
|
|
@ -20,5 +20,6 @@ namespace Ombi.Settings.Settings.Models
|
|||
public static class FeatureNames
|
||||
{
|
||||
public const string Movie4KRequests = nameof(Movie4KRequests);
|
||||
public const string NewTrendingSource = nameof(NewTrendingSource);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace Ombi.Api.TheMovieDb
|
|||
Task<MovieResponseDto> GetMovieInformation(int movieId);
|
||||
Task<MovieResponseDto> GetMovieInformationWithExtraInfo(int movieId, string langCode = "en");
|
||||
Task<List<MovieDbSearchResult>> NowPlaying(string languageCode, int? page = null);
|
||||
Task<List<MovieDbSearchResult>> TrendingMovies(string languageCode, int? page = null);
|
||||
Task<List<MovieDbSearchResult>> PopularMovies(string languageCode, int? page = null, CancellationToken cancellationToken = default(CancellationToken));
|
||||
Task<List<MovieDbSearchResult>> PopularTv(string langCode, int? page = null, CancellationToken cancellationToken = default(CancellationToken));
|
||||
Task<List<MovieDbSearchResult>> SearchMovie(string searchTerm, int? year, string languageCode);
|
||||
|
@ -23,6 +24,7 @@ namespace Ombi.Api.TheMovieDb
|
|||
Task<List<MovieDbSearchResult>> TopRated(string languageCode, int? page = null);
|
||||
Task<List<MovieDbSearchResult>> Upcoming(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>> UpcomingTv(string languageCode, int? page = null);
|
||||
Task<List<MovieDbSearchResult>> SimilarMovies(int movieId, string langCode);
|
||||
Task<FindResult> Find(string externalId, ExternalSource source);
|
||||
|
|
|
@ -282,6 +282,33 @@ namespace Ombi.Api.TheMovieDb
|
|||
return Mapper.Map<List<MovieDbSearchResult>>(result.results);
|
||||
}
|
||||
|
||||
public Task<List<MovieDbSearchResult>> TrendingMovies(string langCode, int? page = null)
|
||||
{
|
||||
return Trending("movie", langCode, page);
|
||||
}
|
||||
|
||||
public Task<List<MovieDbSearchResult>> TrendingTv(string langCode, int? page = null)
|
||||
{
|
||||
return Trending("tv", langCode, page);
|
||||
}
|
||||
private async Task<List<MovieDbSearchResult>> Trending(string type, string langCode, int? page = null)
|
||||
{
|
||||
// https://developers.themoviedb.org/3/trending/get-trending
|
||||
var timeWindow = "week"; // another option can be 'day'
|
||||
var request = new Request($"trending/{type}/{timeWindow}", BaseUri, HttpMethod.Get);
|
||||
request.AddQueryString("api_key", ApiToken);
|
||||
request.AddQueryString("language", langCode);
|
||||
|
||||
if (page != null)
|
||||
{
|
||||
request.AddQueryString("page", page.ToString());
|
||||
}
|
||||
|
||||
AddRetry(request);
|
||||
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
|
||||
return Mapper.Map<List<MovieDbSearchResult>>(result.results);
|
||||
}
|
||||
|
||||
public Task<List<MovieDbSearchResult>> Upcoming(string langCode, int? page = null)
|
||||
{
|
||||
return Upcoming("movie", langCode, page);
|
||||
|
|
|
@ -224,7 +224,11 @@ export class CarouselListComponent implements OnInit {
|
|||
this.movies = await this.searchService.popularMoviesByPage(this.currentlyLoaded, this.amountToLoad);
|
||||
break;
|
||||
case DiscoverType.Trending:
|
||||
if(this.featureFacade.isNewTrendingSourceEnabled) {
|
||||
this.movies = await this.searchService.trendingMoviesByPage(this.currentlyLoaded, this.amountToLoad);
|
||||
} else {
|
||||
this.movies = await this.searchService.nowPlayingMoviesByPage(this.currentlyLoaded, this.amountToLoad);
|
||||
}
|
||||
break;
|
||||
case DiscoverType.Upcoming:
|
||||
this.movies = await this.searchService.upcomingMoviesByPage(this.currentlyLoaded, this.amountToLoad);
|
||||
|
|
|
@ -91,6 +91,10 @@ export class SearchV2Service extends ServiceHelpers {
|
|||
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/nowplaying/${currentlyLoaded}/${toLoad}`).toPromise();
|
||||
}
|
||||
|
||||
public trendingMoviesByPage(currentlyLoaded: number, toLoad: number): Promise<ISearchMovieResult[]> {
|
||||
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/trending/${currentlyLoaded}/${toLoad}`).toPromise();
|
||||
}
|
||||
|
||||
public topRatedMovies(): Observable<ISearchMovieResult[]> {
|
||||
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/toprated`);
|
||||
}
|
||||
|
|
|
@ -23,4 +23,6 @@ export class FeaturesFacade {
|
|||
|
||||
public is4kEnabled = (): boolean => this.store.selectSnapshot(FeaturesSelectors.is4kEnabled);
|
||||
|
||||
public isNewTrendingSourceEnabled = (): boolean => this.store.selectSnapshot(FeaturesSelectors.isNewTrendingSourceEnabled);
|
||||
|
||||
}
|
|
@ -15,4 +15,9 @@ export class FeaturesSelectors {
|
|||
return features.filter(x => x.name === "Movie4KRequests")[0].enabled;
|
||||
}
|
||||
|
||||
@Selector([FeaturesSelectors.features])
|
||||
public static isNewTrendingSourceEnabled(features: IFeatureEnablement[]): boolean {
|
||||
return features.filter(x => x.name === "NewTrendingSource")[0].enabled;
|
||||
}
|
||||
|
||||
}
|
|
@ -286,6 +286,21 @@ namespace Ombi.Controllers.V2
|
|||
DateTimeOffset.Now.AddHours(12));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns trending movies by page
|
||||
/// </summary>
|
||||
/// <remarks>We use TheMovieDb as the Provider</remarks>
|
||||
/// <returns></returns>
|
||||
[HttpGet("movie/trending/{currentPosition}/{amountToLoad}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesDefaultResponseType]
|
||||
public Task<IEnumerable<SearchMovieViewModel>> TrendingMovies(int currentPosition, int amountToLoad)
|
||||
{
|
||||
return _mediaCacheService.GetOrAddAsync(nameof(TrendingMovies) + currentPosition + amountToLoad,
|
||||
() => _movieEngineV2.TrendingMovies(currentPosition, amountToLoad),
|
||||
DateTimeOffset.Now.AddHours(12));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns top rated movies.
|
||||
/// </summary>
|
||||
|
@ -392,14 +407,14 @@ namespace Ombi.Controllers.V2
|
|||
/// <summary>
|
||||
/// Returns trending shows by page
|
||||
/// </summary>
|
||||
/// <remarks>We use Trakt.tv as the Provider</remarks>
|
||||
/// <remarks>We use TheMovieDb as the Provider</remarks>
|
||||
/// <returns></returns>
|
||||
[HttpGet("tv/trending/{currentPosition}/{amountToLoad}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesDefaultResponseType]
|
||||
public Task<IEnumerable<SearchTvShowViewModel>> Trending(int currentPosition, int amountToLoad)
|
||||
public Task<IEnumerable<SearchTvShowViewModel>> TrendingTv(int currentPosition, int amountToLoad)
|
||||
{
|
||||
return _mediaCacheService.GetOrAddAsync(nameof(Trending) + currentPosition + amountToLoad,
|
||||
return _mediaCacheService.GetOrAddAsync(nameof(TrendingTv) + currentPosition + amountToLoad,
|
||||
() => _tvEngineV2.Trending(currentPosition, amountToLoad),
|
||||
DateTimeOffset.Now.AddHours(12));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue