From 1a0823ca80559417c67323aaeaa1ef5243e98031 Mon Sep 17 00:00:00 2001 From: sephrat <34862846+sephrat@users.noreply.github.com> Date: Mon, 25 Apr 2022 18:53:44 +0200 Subject: [PATCH 1/6] feat(discover): Add new trending source experimental feature --- .../Engine/Interfaces/IMovieEngineV2.cs | 1 + .../Engine/V2/MovieSearchEngineV2.cs | 16 +++++++++++ src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs | 14 +++++++--- .../Settings/Models/FeatureSettings.cs | 1 + src/Ombi.TheMovieDbApi/IMovieDbApi.cs | 2 ++ src/Ombi.TheMovieDbApi/TheMovieDbApi.cs | 27 +++++++++++++++++++ .../carousel-list/carousel-list.component.ts | 4 +++ .../src/app/services/searchV2.service.ts | 4 +++ .../src/app/state/features/features.facade.ts | 4 ++- .../app/state/features/features.selectors.ts | 7 ++++- src/Ombi/Controllers/V2/SearchController.cs | 21 ++++++++++++--- 11 files changed, 93 insertions(+), 8 deletions(-) diff --git a/src/Ombi.Core/Engine/Interfaces/IMovieEngineV2.cs b/src/Ombi.Core/Engine/Interfaces/IMovieEngineV2.cs index 2d86443d1..f70c34c1e 100644 --- a/src/Ombi.Core/Engine/Interfaces/IMovieEngineV2.cs +++ b/src/Ombi.Core/Engine/Interfaces/IMovieEngineV2.cs @@ -17,6 +17,7 @@ namespace Ombi.Core.Engine.Interfaces Task> UpcomingMovies(); Task> NowPlayingMovies(); Task> NowPlayingMovies(int currentPosition, int amountToLoad); + Task> TrendingMovies(int currentPosition, int amountToLoad); Task GetCollection(int collectionId, CancellationToken cancellationToken, string langCode = null); Task GetTvDbId(int theMovieDbId); Task> PopularMovies(int currentlyLoaded, int toLoad, CancellationToken cancellationToken, string langCustomCode = null); diff --git a/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs index 3acd7d1f0..74a49930c 100644 --- a/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs +++ b/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs @@ -208,6 +208,22 @@ namespace Ombi.Core.Engine.V2 } return await TransformMovieResultsToResponse(results); } + + public async Task> TrendingMovies(int currentPosition, int amountToLoad) + { + var langCode = await DefaultLanguageCode(null); + + var pages = PaginationHelper.GetNextPages(currentPosition, amountToLoad, _theMovieDbMaxPageItems); + + var results = new List(); + 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> SeasonalList(int currentPosition, int amountToLoad, CancellationToken cancellationToken) { diff --git a/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs index 344ced813..6de747964 100644 --- a/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs +++ b/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs @@ -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 _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 s, - IRepository sub, IMovieDbApi movieApi, ISettingsService customization, ITvRequestEngine requestEngine) + IRepository sub, IMovieDbApi movieApi, ISettingsService 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; } @@ -132,15 +136,19 @@ namespace Ombi.Core.Engine.V2 } public async Task> 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(); 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)); } diff --git a/src/Ombi.Settings/Settings/Models/FeatureSettings.cs b/src/Ombi.Settings/Settings/Models/FeatureSettings.cs index 6a285d422..b4301b328 100644 --- a/src/Ombi.Settings/Settings/Models/FeatureSettings.cs +++ b/src/Ombi.Settings/Settings/Models/FeatureSettings.cs @@ -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); } } diff --git a/src/Ombi.TheMovieDbApi/IMovieDbApi.cs b/src/Ombi.TheMovieDbApi/IMovieDbApi.cs index 51da958b6..4f3885ef0 100644 --- a/src/Ombi.TheMovieDbApi/IMovieDbApi.cs +++ b/src/Ombi.TheMovieDbApi/IMovieDbApi.cs @@ -15,6 +15,7 @@ namespace Ombi.Api.TheMovieDb Task GetMovieInformation(int movieId); Task GetMovieInformationWithExtraInfo(int movieId, string langCode = "en"); Task> NowPlaying(string languageCode, int? page = null); + Task> TrendingMovies(string languageCode, int? page = null); Task> PopularMovies(string languageCode, int? page = null, CancellationToken cancellationToken = default(CancellationToken)); Task> PopularTv(string langCode, int? page = null, CancellationToken cancellationToken = default(CancellationToken)); Task> SearchMovie(string searchTerm, int? year, string languageCode); @@ -23,6 +24,7 @@ namespace Ombi.Api.TheMovieDb Task> TopRated(string languageCode, int? page = null); Task> Upcoming(string languageCode, int? page = null); Task> TopRatedTv(string languageCode, int? page = null); + Task> TrendingTv(string languageCode, int? page = null); Task> UpcomingTv(string languageCode, int? page = null); Task> SimilarMovies(int movieId, string langCode); Task Find(string externalId, ExternalSource source); diff --git a/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs b/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs index 02862fb7d..ba61ccfcf 100644 --- a/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs +++ b/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs @@ -281,6 +281,33 @@ namespace Ombi.Api.TheMovieDb var result = await Api.Request>(request); return Mapper.Map>(result.results); } + + public Task> TrendingMovies(string langCode, int? page = null) + { + return Trending("movie", langCode, page); + } + + public Task> TrendingTv(string langCode, int? page = null) + { + return Trending("tv", langCode, page); + } + private async Task> 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>(request); + return Mapper.Map>(result.results); + } public Task> Upcoming(string langCode, int? page = null) { diff --git a/src/Ombi/ClientApp/src/app/discover/components/carousel-list/carousel-list.component.ts b/src/Ombi/ClientApp/src/app/discover/components/carousel-list/carousel-list.component.ts index 9617c993e..92896a877 100644 --- a/src/Ombi/ClientApp/src/app/discover/components/carousel-list/carousel-list.component.ts +++ b/src/Ombi/ClientApp/src/app/discover/components/carousel-list/carousel-list.component.ts @@ -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); diff --git a/src/Ombi/ClientApp/src/app/services/searchV2.service.ts b/src/Ombi/ClientApp/src/app/services/searchV2.service.ts index 56b1057c6..fd43044f5 100644 --- a/src/Ombi/ClientApp/src/app/services/searchV2.service.ts +++ b/src/Ombi/ClientApp/src/app/services/searchV2.service.ts @@ -91,6 +91,10 @@ export class SearchV2Service extends ServiceHelpers { return this.http.get(`${this.url}/Movie/nowplaying/${currentlyLoaded}/${toLoad}`).toPromise(); } + public trendingMoviesByPage(currentlyLoaded: number, toLoad: number): Promise { + return this.http.get(`${this.url}/Movie/trending/${currentlyLoaded}/${toLoad}`).toPromise(); + } + public topRatedMovies(): Observable { return this.http.get(`${this.url}/Movie/toprated`); } diff --git a/src/Ombi/ClientApp/src/app/state/features/features.facade.ts b/src/Ombi/ClientApp/src/app/state/features/features.facade.ts index 10e229eba..4dd74d3f9 100644 --- a/src/Ombi/ClientApp/src/app/state/features/features.facade.ts +++ b/src/Ombi/ClientApp/src/app/state/features/features.facade.ts @@ -23,4 +23,6 @@ export class FeaturesFacade { public is4kEnabled = (): boolean => this.store.selectSnapshot(FeaturesSelectors.is4kEnabled); -} \ No newline at end of file + public isNewTrendingSourceEnabled = (): boolean => this.store.selectSnapshot(FeaturesSelectors.isNewTrendingSourceEnabled); + +} diff --git a/src/Ombi/ClientApp/src/app/state/features/features.selectors.ts b/src/Ombi/ClientApp/src/app/state/features/features.selectors.ts index 143dfb875..cda4921a7 100644 --- a/src/Ombi/ClientApp/src/app/state/features/features.selectors.ts +++ b/src/Ombi/ClientApp/src/app/state/features/features.selectors.ts @@ -15,4 +15,9 @@ export class FeaturesSelectors { return features.filter(x => x.name === "Movie4KRequests")[0].enabled; } -} \ No newline at end of file + @Selector([FeaturesSelectors.features]) + public static isNewTrendingSourceEnabled(features: IFeatureEnablement[]): boolean { + return features.filter(x => x.name === "NewTrendingSource")[0].enabled; + } + +} diff --git a/src/Ombi/Controllers/V2/SearchController.cs b/src/Ombi/Controllers/V2/SearchController.cs index 5227f06ec..c487fc4c2 100644 --- a/src/Ombi/Controllers/V2/SearchController.cs +++ b/src/Ombi/Controllers/V2/SearchController.cs @@ -285,6 +285,21 @@ namespace Ombi.Controllers.V2 () => _movieEngineV2.NowPlayingMovies(currentPosition, amountToLoad), DateTimeOffset.Now.AddHours(12)); } + + /// + /// Returns trending movies by page + /// + /// We use TheMovieDb as the Provider + /// + [HttpGet("movie/trending/{currentPosition}/{amountToLoad}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] + public Task> TrendingMovies(int currentPosition, int amountToLoad) + { + return _mediaCacheService.GetOrAddAsync(nameof(TrendingMovies) + currentPosition + amountToLoad, + () => _movieEngineV2.TrendingMovies(currentPosition, amountToLoad), + DateTimeOffset.Now.AddHours(12)); + } /// /// Returns top rated movies. @@ -392,14 +407,14 @@ namespace Ombi.Controllers.V2 /// /// Returns trending shows by page /// - /// We use Trakt.tv as the Provider + /// We use TheMovieDb as the Provider /// [HttpGet("tv/trending/{currentPosition}/{amountToLoad}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesDefaultResponseType] - public Task> Trending(int currentPosition, int amountToLoad) + public Task> 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)); } From a373359ae8e6bad42b558a6e01a8ff2840d3bbaa Mon Sep 17 00:00:00 2001 From: sephrat <34862846+sephrat@users.noreply.github.com> Date: Mon, 25 Apr 2022 18:54:29 +0200 Subject: [PATCH 2/6] fix(settings): Allow toggling features when there are more than one --- .../src/app/settings/features/features.component.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ombi/ClientApp/src/app/settings/features/features.component.html b/src/Ombi/ClientApp/src/app/settings/features/features.component.html index 4eb975cfe..37de15a4c 100644 --- a/src/Ombi/ClientApp/src/app/settings/features/features.component.html +++ b/src/Ombi/ClientApp/src/app/settings/features/features.component.html @@ -8,7 +8,7 @@
- +

{{feature.name}}

@@ -17,4 +17,4 @@
- \ No newline at end of file + From 6794b887f6544fb41528bdd9728b7824b65e47ee Mon Sep 17 00:00:00 2001 From: sephrat <34862846+sephrat@users.noreply.github.com> Date: Mon, 25 Apr 2022 19:16:26 +0200 Subject: [PATCH 3/6] fix(discover): Fix new trending feature detection --- .../components/carousel-list/carousel-list.component.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Ombi/ClientApp/src/app/discover/components/carousel-list/carousel-list.component.ts b/src/Ombi/ClientApp/src/app/discover/components/carousel-list/carousel-list.component.ts index 92896a877..dee44fff9 100644 --- a/src/Ombi/ClientApp/src/app/discover/components/carousel-list/carousel-list.component.ts +++ b/src/Ombi/ClientApp/src/app/discover/components/carousel-list/carousel-list.component.ts @@ -38,6 +38,7 @@ export class CarouselListComponent implements OnInit { public loadingFlag: boolean; public DiscoverType = DiscoverType; public is4kEnabled = false; + public isNewTrendingSourceEnabled = false; get mediaTypeStorageKey() { return "DiscoverOptions" + this.discoverType.toString(); @@ -139,6 +140,7 @@ export class CarouselListComponent implements OnInit { public async ngOnInit() { this.is4kEnabled = this.featureFacade.is4kEnabled(); + this.isNewTrendingSourceEnabled = this.featureFacade.isNewTrendingSourceEnabled(); this.currentlyLoaded = 0; const localDiscoverOptions = +this.storageService.get(this.mediaTypeStorageKey); if (localDiscoverOptions) { @@ -224,7 +226,7 @@ export class CarouselListComponent implements OnInit { this.movies = await this.searchService.popularMoviesByPage(this.currentlyLoaded, this.amountToLoad); break; case DiscoverType.Trending: - if(this.featureFacade.isNewTrendingSourceEnabled) { + if(this.isNewTrendingSourceEnabled) { this.movies = await this.searchService.trendingMoviesByPage(this.currentlyLoaded, this.amountToLoad); } else { this.movies = await this.searchService.nowPlayingMoviesByPage(this.currentlyLoaded, this.amountToLoad); From 03d94220c7eaafb50c6c80a6ed1150794b873ac3 Mon Sep 17 00:00:00 2001 From: sephrat <34862846+sephrat@users.noreply.github.com> Date: Mon, 25 Apr 2022 19:16:47 +0200 Subject: [PATCH 4/6] fix(discover): Fix cache mix up --- src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs index 74a49930c..1a353cb55 100644 --- a/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs +++ b/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs @@ -218,7 +218,7 @@ namespace Ombi.Core.Engine.V2 var results = new List(); foreach (var pagesToLoad in pages) { - var apiResult = await Cache.GetOrAddAsync(nameof(NowPlayingMovies) + pagesToLoad.Page + langCode, + var apiResult = await Cache.GetOrAddAsync(nameof(TrendingMovies) + pagesToLoad.Page + langCode, () => MovieApi.TrendingMovies(langCode, pagesToLoad.Page), DateTimeOffset.Now.AddHours(12)); results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take)); } From 70a6a8f953e5bc0d42b371df8cf43a7d18994253 Mon Sep 17 00:00:00 2001 From: sephrat <34862846+sephrat@users.noreply.github.com> Date: Tue, 26 Apr 2022 12:56:02 +0200 Subject: [PATCH 5/6] refactor(discover): Move movie trending feature toggle to backend --- .../Engine/Interfaces/IMovieEngineV2.cs | 1 - .../Engine/V2/MovieSearchEngineV2.cs | 29 +++++++------------ .../carousel-list/carousel-list.component.ts | 6 ---- .../src/app/services/searchV2.service.ts | 4 --- .../src/app/state/features/features.facade.ts | 4 +-- .../app/state/features/features.selectors.ts | 7 +---- src/Ombi/Controllers/V2/SearchController.cs | 15 ---------- 7 files changed, 13 insertions(+), 53 deletions(-) diff --git a/src/Ombi.Core/Engine/Interfaces/IMovieEngineV2.cs b/src/Ombi.Core/Engine/Interfaces/IMovieEngineV2.cs index f70c34c1e..2d86443d1 100644 --- a/src/Ombi.Core/Engine/Interfaces/IMovieEngineV2.cs +++ b/src/Ombi.Core/Engine/Interfaces/IMovieEngineV2.cs @@ -17,7 +17,6 @@ namespace Ombi.Core.Engine.Interfaces Task> UpcomingMovies(); Task> NowPlayingMovies(); Task> NowPlayingMovies(int currentPosition, int amountToLoad); - Task> TrendingMovies(int currentPosition, int amountToLoad); Task GetCollection(int collectionId, CancellationToken cancellationToken, string langCode = null); Task GetTvDbId(int theMovieDbId); Task> PopularMovies(int currentlyLoaded, int toLoad, CancellationToken cancellationToken, string langCustomCode = null); diff --git a/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs index 1a353cb55..d4aede4f6 100644 --- a/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs +++ b/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs @@ -11,6 +11,7 @@ using Ombi.Core.Models.Search; using Ombi.Core.Models.Search.V2; using Ombi.Core.Models.UI; using Ombi.Core.Rule.Interfaces; +using Ombi.Core.Services; using Ombi.Core.Settings; using Ombi.Helpers; using Ombi.Settings.Settings.Models; @@ -31,7 +32,8 @@ namespace Ombi.Core.Engine.V2 { public MovieSearchEngineV2(ICurrentUser identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper, ILogger logger, IRuleEvaluator r, OmbiUserManager um, ICacheService mem, ISettingsService s, IRepository sub, - ISettingsService customizationSettings, IMovieRequestEngine movieRequestEngine, IHttpClientFactory httpClientFactory) + ISettingsService customizationSettings, IMovieRequestEngine movieRequestEngine, IHttpClientFactory httpClientFactory, + IFeatureService feature) : base(identity, service, r, um, mem, s, sub) { MovieApi = movApi; @@ -40,6 +42,7 @@ namespace Ombi.Core.Engine.V2 _customizationSettings = customizationSettings; _movieRequestEngine = movieRequestEngine; _client = httpClientFactory.CreateClient(); + _feature = feature; } private IMovieDbApi MovieApi { get; } @@ -48,6 +51,7 @@ namespace Ombi.Core.Engine.V2 private readonly ISettingsService _customizationSettings; private readonly IMovieRequestEngine _movieRequestEngine; private readonly HttpClient _client; + private readonly IFeatureService _feature; public async Task GetFullMovieInformation(int theMovieDbId, CancellationToken cancellationToken, string langCode = null) { @@ -196,30 +200,19 @@ namespace Ombi.Core.Engine.V2 public async Task> NowPlayingMovies(int currentPosition, int amountToLoad) { var langCode = await DefaultLanguageCode(null); + var isNewTrendingSourceEnabled = await _feature.FeatureEnabled(FeatureNames.NewTrendingSource); var pages = PaginationHelper.GetNextPages(currentPosition, amountToLoad, _theMovieDbMaxPageItems); var results = new List(); foreach (var pagesToLoad in pages) { + var search = () => (isNewTrendingSourceEnabled) ? + MovieApi.TrendingMovies(langCode, pagesToLoad.Page) + : MovieApi.NowPlaying(langCode, pagesToLoad.Page); + var apiResult = await Cache.GetOrAddAsync(nameof(NowPlayingMovies) + pagesToLoad.Page + langCode, - () => MovieApi.NowPlaying(langCode, pagesToLoad.Page), DateTimeOffset.Now.AddHours(12)); - results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take)); - } - return await TransformMovieResultsToResponse(results); - } - - public async Task> TrendingMovies(int currentPosition, int amountToLoad) - { - var langCode = await DefaultLanguageCode(null); - - var pages = PaginationHelper.GetNextPages(currentPosition, amountToLoad, _theMovieDbMaxPageItems); - - var results = new List(); - foreach (var pagesToLoad in pages) - { - var apiResult = await Cache.GetOrAddAsync(nameof(TrendingMovies) + pagesToLoad.Page + langCode, - () => MovieApi.TrendingMovies(langCode, pagesToLoad.Page), DateTimeOffset.Now.AddHours(12)); + search, DateTimeOffset.Now.AddHours(12)); results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take)); } return await TransformMovieResultsToResponse(results); diff --git a/src/Ombi/ClientApp/src/app/discover/components/carousel-list/carousel-list.component.ts b/src/Ombi/ClientApp/src/app/discover/components/carousel-list/carousel-list.component.ts index dee44fff9..9617c993e 100644 --- a/src/Ombi/ClientApp/src/app/discover/components/carousel-list/carousel-list.component.ts +++ b/src/Ombi/ClientApp/src/app/discover/components/carousel-list/carousel-list.component.ts @@ -38,7 +38,6 @@ export class CarouselListComponent implements OnInit { public loadingFlag: boolean; public DiscoverType = DiscoverType; public is4kEnabled = false; - public isNewTrendingSourceEnabled = false; get mediaTypeStorageKey() { return "DiscoverOptions" + this.discoverType.toString(); @@ -140,7 +139,6 @@ export class CarouselListComponent implements OnInit { public async ngOnInit() { this.is4kEnabled = this.featureFacade.is4kEnabled(); - this.isNewTrendingSourceEnabled = this.featureFacade.isNewTrendingSourceEnabled(); this.currentlyLoaded = 0; const localDiscoverOptions = +this.storageService.get(this.mediaTypeStorageKey); if (localDiscoverOptions) { @@ -226,11 +224,7 @@ export class CarouselListComponent implements OnInit { this.movies = await this.searchService.popularMoviesByPage(this.currentlyLoaded, this.amountToLoad); break; case DiscoverType.Trending: - if(this.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); diff --git a/src/Ombi/ClientApp/src/app/services/searchV2.service.ts b/src/Ombi/ClientApp/src/app/services/searchV2.service.ts index fd43044f5..56b1057c6 100644 --- a/src/Ombi/ClientApp/src/app/services/searchV2.service.ts +++ b/src/Ombi/ClientApp/src/app/services/searchV2.service.ts @@ -91,10 +91,6 @@ export class SearchV2Service extends ServiceHelpers { return this.http.get(`${this.url}/Movie/nowplaying/${currentlyLoaded}/${toLoad}`).toPromise(); } - public trendingMoviesByPage(currentlyLoaded: number, toLoad: number): Promise { - return this.http.get(`${this.url}/Movie/trending/${currentlyLoaded}/${toLoad}`).toPromise(); - } - public topRatedMovies(): Observable { return this.http.get(`${this.url}/Movie/toprated`); } diff --git a/src/Ombi/ClientApp/src/app/state/features/features.facade.ts b/src/Ombi/ClientApp/src/app/state/features/features.facade.ts index 4dd74d3f9..10e229eba 100644 --- a/src/Ombi/ClientApp/src/app/state/features/features.facade.ts +++ b/src/Ombi/ClientApp/src/app/state/features/features.facade.ts @@ -23,6 +23,4 @@ export class FeaturesFacade { public is4kEnabled = (): boolean => this.store.selectSnapshot(FeaturesSelectors.is4kEnabled); - public isNewTrendingSourceEnabled = (): boolean => this.store.selectSnapshot(FeaturesSelectors.isNewTrendingSourceEnabled); - -} +} \ No newline at end of file diff --git a/src/Ombi/ClientApp/src/app/state/features/features.selectors.ts b/src/Ombi/ClientApp/src/app/state/features/features.selectors.ts index cda4921a7..143dfb875 100644 --- a/src/Ombi/ClientApp/src/app/state/features/features.selectors.ts +++ b/src/Ombi/ClientApp/src/app/state/features/features.selectors.ts @@ -15,9 +15,4 @@ 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; - } - -} +} \ No newline at end of file diff --git a/src/Ombi/Controllers/V2/SearchController.cs b/src/Ombi/Controllers/V2/SearchController.cs index c487fc4c2..429add7c8 100644 --- a/src/Ombi/Controllers/V2/SearchController.cs +++ b/src/Ombi/Controllers/V2/SearchController.cs @@ -285,21 +285,6 @@ namespace Ombi.Controllers.V2 () => _movieEngineV2.NowPlayingMovies(currentPosition, amountToLoad), DateTimeOffset.Now.AddHours(12)); } - - /// - /// Returns trending movies by page - /// - /// We use TheMovieDb as the Provider - /// - [HttpGet("movie/trending/{currentPosition}/{amountToLoad}")] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesDefaultResponseType] - public Task> TrendingMovies(int currentPosition, int amountToLoad) - { - return _mediaCacheService.GetOrAddAsync(nameof(TrendingMovies) + currentPosition + amountToLoad, - () => _movieEngineV2.TrendingMovies(currentPosition, amountToLoad), - DateTimeOffset.Now.AddHours(12)); - } /// /// Returns top rated movies. From 4f12939e22020a67a5ee75e2907923faea136e8d Mon Sep 17 00:00:00 2001 From: sephrat <34862846+sephrat@users.noreply.github.com> Date: Tue, 26 Apr 2022 12:58:21 +0200 Subject: [PATCH 6/6] feat(discover): Default trending source to new logic --- src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs | 8 ++++---- src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs | 8 ++++---- src/Ombi.Settings/Settings/Models/FeatureSettings.cs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs index d4aede4f6..3423bc139 100644 --- a/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs +++ b/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs @@ -200,16 +200,16 @@ namespace Ombi.Core.Engine.V2 public async Task> NowPlayingMovies(int currentPosition, int amountToLoad) { var langCode = await DefaultLanguageCode(null); - var isNewTrendingSourceEnabled = await _feature.FeatureEnabled(FeatureNames.NewTrendingSource); + var isOldTrendingSourceEnabled = await _feature.FeatureEnabled(FeatureNames.OldTrendingSource); var pages = PaginationHelper.GetNextPages(currentPosition, amountToLoad, _theMovieDbMaxPageItems); var results = new List(); foreach (var pagesToLoad in pages) { - var search = () => (isNewTrendingSourceEnabled) ? - MovieApi.TrendingMovies(langCode, pagesToLoad.Page) - : MovieApi.NowPlaying(langCode, pagesToLoad.Page); + var search = () => (isOldTrendingSourceEnabled) ? + MovieApi.NowPlaying(langCode, pagesToLoad.Page) + : MovieApi.TrendingMovies(langCode, pagesToLoad.Page); var apiResult = await Cache.GetOrAddAsync(nameof(NowPlayingMovies) + pagesToLoad.Page + langCode, search, DateTimeOffset.Now.AddHours(12)); diff --git a/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs index 6de747964..21035567a 100644 --- a/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs +++ b/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs @@ -138,15 +138,15 @@ namespace Ombi.Core.Engine.V2 public async Task> Trending(int currentlyLoaded, int amountToLoad) { var langCode = await DefaultLanguageCode(null); - var isNewTrendingSourceEnabled = await _feature.FeatureEnabled(FeatureNames.NewTrendingSource); + var isOldTrendingSourceEnabled = await _feature.FeatureEnabled(FeatureNames.OldTrendingSource); var pages = PaginationHelper.GetNextPages(currentlyLoaded, amountToLoad, ResultLimit); var results = new List(); foreach (var pagesToLoad in pages) { - var search = ( async () => (isNewTrendingSourceEnabled) ? - await _movieApi.TrendingTv(langCode, pagesToLoad.Page) - : await _movieApi.TopRatedTv(langCode, pagesToLoad.Page)); + var search = ( async () => (isOldTrendingSourceEnabled) ? + await _movieApi.TopRatedTv(langCode, pagesToLoad.Page) + : await _movieApi.TrendingTv(langCode, pagesToLoad.Page)); var apiResult = await Cache.GetOrAddAsync(nameof(Trending) + langCode + pagesToLoad.Page, search, DateTimeOffset.Now.AddHours(12)); results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take)); diff --git a/src/Ombi.Settings/Settings/Models/FeatureSettings.cs b/src/Ombi.Settings/Settings/Models/FeatureSettings.cs index b4301b328..9d0149e5d 100644 --- a/src/Ombi.Settings/Settings/Models/FeatureSettings.cs +++ b/src/Ombi.Settings/Settings/Models/FeatureSettings.cs @@ -20,6 +20,6 @@ namespace Ombi.Settings.Settings.Models public static class FeatureNames { public const string Movie4KRequests = nameof(Movie4KRequests); - public const string NewTrendingSource = nameof(NewTrendingSource); + public const string OldTrendingSource = nameof(OldTrendingSource); } }