diff --git a/src/Ombi.Core/Engine/Interfaces/IMovieEngineV2.cs b/src/Ombi.Core/Engine/Interfaces/IMovieEngineV2.cs index fc65b53d2..20b5db148 100644 --- a/src/Ombi.Core/Engine/Interfaces/IMovieEngineV2.cs +++ b/src/Ombi.Core/Engine/Interfaces/IMovieEngineV2.cs @@ -13,9 +13,12 @@ namespace Ombi.Core.Engine.Interfaces Task> TopRatedMovies(); Task> UpcomingMovies(); Task> NowPlayingMovies(); + Task> NowPlayingMovies(int currentPosition, int amountToLoad); Task GetCollection(int collectionId, string langCode = null); Task GetTvDbId(int theMovieDbId); Task> PopularMovies(int currentlyLoaded, int toLoad); + Task> TopRatedMovies(int currentlyLoaded, int toLoad); + Task> UpcomingMovies(int currentlyLoaded, int toLoad); int ResultLimit { get; set; } } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs b/src/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs index 8e9148b4e..501197fb9 100644 --- a/src/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/ITvSearchEngine.cs @@ -11,8 +11,11 @@ namespace Ombi.Core.Engine.Interfaces Task> Popular(); Task> Popular(int currentlyLoaded, int amountToLoad); Task> Anticipated(); + Task> Anticipated(int currentlyLoaded, int amountToLoad); Task> MostWatches(); Task> Trending(); + Task> MostWatches(int currentlyLoaded, int amountToLoad); + Task> Trending(int currentlyLoaded, int amountToLoad); int ResultLimit { get; set; } } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/TvSearchEngine.cs b/src/Ombi.Core/Engine/TvSearchEngine.cs index 16f951f10..93e451f1d 100644 --- a/src/Ombi.Core/Engine/TvSearchEngine.cs +++ b/src/Ombi.Core/Engine/TvSearchEngine.cs @@ -22,6 +22,7 @@ using Ombi.Helpers; using Ombi.Settings.Settings.Models; using Ombi.Store.Entities; using TraktApiSharp.Objects.Get.Shows; +using TraktApiSharp.Objects.Get.Shows.Common; namespace Ombi.Core.Engine { @@ -149,6 +150,19 @@ namespace Ombi.Core.Engine return processed; } + public async Task> Anticipated(int currentlyLoaded, int amountToLoad) + { + var pages = PaginationHelper.GetNextPages(currentlyLoaded, amountToLoad, ResultLimit); + var results = new List(); + foreach (var pagesToLoad in pages) + { + var apiResult = await TraktApi.GetAnticipatedShows(pagesToLoad.Page, ResultLimit); + results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take)); + } + var processed = ProcessResults(results); + return processed; + } + public async Task> MostWatches() { var result = await Cache.GetOrAdd(CacheKeys.MostWatchesTv, async () => await TraktApi.GetMostWatchesShows(null, ResultLimit), DateTime.Now.AddHours(12)); @@ -163,6 +177,32 @@ namespace Ombi.Core.Engine return processed; } + public async Task> MostWatches(int currentlyLoaded, int amountToLoad) + { + var pages = PaginationHelper.GetNextPages(currentlyLoaded, amountToLoad, ResultLimit); + var results = new List(); + foreach (var pagesToLoad in pages) + { + var apiResult = await TraktApi.GetMostWatchesShows(null, pagesToLoad.Page, ResultLimit); + results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take)); + } + var processed = ProcessResults(results); + return processed; + } + + public async Task> Trending(int currentlyLoaded, int amountToLoad) + { + var pages = PaginationHelper.GetNextPages(currentlyLoaded, amountToLoad, ResultLimit); + var results = new List(); + foreach (var pagesToLoad in pages) + { + var apiResult = await TraktApi.GetTrendingShows(pagesToLoad.Page, ResultLimit); + results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take)); + } + var processed = ProcessResults(results); + return processed; + } + protected IEnumerable ProcessResults(IEnumerable items) { var retVal = new List(); diff --git a/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs index 893679e9b..cb3162900 100644 --- a/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs +++ b/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs @@ -138,6 +138,37 @@ namespace Ombi.Core.Engine.V2 return null; } + public async Task> TopRatedMovies(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 MovieApi.TopRated(langCode, pagesToLoad.Page); + results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take)); + } + return await TransformMovieResultsToResponse(results); + } + + public async Task> NowPlayingMovies(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 MovieApi.NowPlaying(langCode, pagesToLoad.Page); + results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take)); + } + return await TransformMovieResultsToResponse(results); + } + + /// /// Gets upcoming movies. /// @@ -157,6 +188,21 @@ namespace Ombi.Core.Engine.V2 return null; } + public async Task> UpcomingMovies(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 MovieApi.Upcoming(langCode, pagesToLoad.Page); + results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take)); + } + return await TransformMovieResultsToResponse(results); + } + /// /// Gets now playing movies. /// diff --git a/src/Ombi.TheMovieDbApi/IMovieDbApi.cs b/src/Ombi.TheMovieDbApi/IMovieDbApi.cs index c54129a18..c04d4c58a 100644 --- a/src/Ombi.TheMovieDbApi/IMovieDbApi.cs +++ b/src/Ombi.TheMovieDbApi/IMovieDbApi.cs @@ -9,12 +9,12 @@ namespace Ombi.Api.TheMovieDb { Task GetMovieInformation(int movieId); Task GetMovieInformationWithExtraInfo(int movieId, string langCode = "en"); - Task> NowPlaying(string languageCode); - Task> PopularMovies(string languageCode); + Task> NowPlaying(string languageCode, int? page = null); + Task> PopularMovies(string languageCode, int? page = null); Task> SearchMovie(string searchTerm, int? year, string languageCode); Task> SearchTv(string searchTerm); - Task> TopRated(string languageCode); - Task> Upcoming(string languageCode); + Task> TopRated(string languageCode, int? page = null); + Task> Upcoming(string languageCode, int? page = null); Task> SimilarMovies(int movieId, string langCode); Task Find(string externalId, ExternalSource source); Task GetTvExternals(int theMovieDbId); @@ -25,6 +25,5 @@ namespace Ombi.Api.TheMovieDb Task GetFullMovieInfo(int movieId, string langCode); Task> DiscoverMovies(string langCode, int keywordId); Task GetCollection(string langCode, int collectionId); - Task> PopularMovies(string langageCode, int page); } } \ No newline at end of file diff --git a/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs b/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs index c5aafca7a..53cf5a05f 100644 --- a/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs +++ b/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs @@ -156,52 +156,57 @@ namespace Ombi.Api.TheMovieDb return Mapper.Map>(result.results); } - public async Task> PopularMovies(string langageCode) + public async Task> PopularMovies(string langageCode, int? page = null) { var request = new Request($"movie/popular", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); request.FullUri = request.FullUri.AddQueryParameter("language", langageCode); + if (page != null) + { + request.FullUri = request.FullUri.AddQueryParameter("page", page.ToString()); + } AddRetry(request); var result = await Api.Request>(request); return Mapper.Map>(result.results); } - public async Task> PopularMovies(string langageCode, int page) - { - var request = new Request($"movie/popular", BaseUri, HttpMethod.Get); - request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); - request.FullUri = request.FullUri.AddQueryParameter("language", langageCode); - request.FullUri = request.FullUri.AddQueryParameter("page", page.ToString()); - AddRetry(request); - var result = await Api.Request>(request); - return Mapper.Map>(result.results); - } - - public async Task> TopRated(string langageCode) + public async Task> TopRated(string langageCode, int? page = null) { var request = new Request($"movie/top_rated", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); request.FullUri = request.FullUri.AddQueryParameter("language", langageCode); + if (page != null) + { + request.FullUri = request.FullUri.AddQueryParameter("page", page.ToString()); + } AddRetry(request); var result = await Api.Request>(request); return Mapper.Map>(result.results); } - public async Task> Upcoming(string langageCode) + public async Task> Upcoming(string langageCode, int? page = null) { var request = new Request($"movie/upcoming", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); request.FullUri = request.FullUri.AddQueryParameter("language", langageCode); + if (page != null) + { + request.FullUri = request.FullUri.AddQueryParameter("page", page.ToString()); + } AddRetry(request); var result = await Api.Request>(request); return Mapper.Map>(result.results); } - public async Task> NowPlaying(string langageCode) + public async Task> NowPlaying(string langageCode, int? page = null) { var request = new Request($"movie/now_playing", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); request.FullUri = request.FullUri.AddQueryParameter("language", langageCode); + if (page != null) + { + request.FullUri = request.FullUri.AddQueryParameter("page", page.ToString()); + } AddRetry(request); var result = await Api.Request>(request); return Mapper.Map>(result.results); diff --git a/src/Ombi/ClientApp/src/app/discover/discover.component.html b/src/Ombi/ClientApp/src/app/discover/discover.component.html index 8919cf202..8d1984d8f 100644 --- a/src/Ombi/ClientApp/src/app/discover/discover.component.html +++ b/src/Ombi/ClientApp/src/app/discover/discover.component.html @@ -16,8 +16,9 @@
diff --git a/src/Ombi/ClientApp/src/app/discover/discover.component.ts b/src/Ombi/ClientApp/src/app/discover/discover.component.ts index 5be78f404..e1935f2f4 100644 --- a/src/Ombi/ClientApp/src/app/discover/discover.component.ts +++ b/src/Ombi/ClientApp/src/app/discover/discover.component.ts @@ -29,6 +29,7 @@ export class DiscoverComponent implements OnInit { public upcomingActive: boolean; public loadingFlag: boolean; + public scrollDisabled: boolean; private contentLoaded: number; private isScrolling: boolean = false; @@ -37,14 +38,14 @@ export class DiscoverComponent implements OnInit { public async ngOnInit() { this.loading() - - this.movies = await this.searchService.popularMoviesByPage(0,12).toPromise(); + this.scrollDisabled = true; + this.movies = await this.searchService.popularMoviesByPage(0,12); this.tvShows = await this.searchService.popularTvByPage(0,12); this.contentLoaded = 12; this.createInitialModel(); - + this.scrollDisabled = false; } public async onScroll() { @@ -57,10 +58,18 @@ export class DiscoverComponent implements OnInit { console.log("SCROLLED!") this.loading(); if (this.popularActive) { - this.movies = await this.searchService.popularMoviesByPage(this.contentLoaded, 12).toPromise(); + this.movies = await this.searchService.popularMoviesByPage(this.contentLoaded, 12); this.tvShows = await this.searchService.popularTvByPage(this.contentLoaded, 12); - this.contentLoaded += 12; } + if(this.trendingActive) { + this.movies = await this.searchService.nowPlayingMoviesByPage(this.contentLoaded, 12); + this.tvShows = await this.searchService.trendingTvByPage(this.contentLoaded, 12); + } + if(this.upcomingActive) { + this.movies = await this.searchService.upcomingMoviesByPage(this.contentLoaded, 12); + this.tvShows = await this.searchService.anticipatedTvByPage(this.contentLoaded, 12); + } + this.contentLoaded += 12; this.createModel(); this.isScrolling = false; @@ -69,44 +78,51 @@ export class DiscoverComponent implements OnInit { public async popular() { this.clear(); - + this.scrollDisabled = true; + this.isScrolling = false; this.contentLoaded = 12; this.loading() this.popularActive = true; this.trendingActive = false; this.upcomingActive = false; - this.movies = await this.searchService.popularMoviesByPage(0, 12).toPromise(); + this.movies = await this.searchService.popularMoviesByPage(0, 12); this.tvShows = await this.searchService.popularTvByPage(0, 12); - this.createModel(); + this.scrollDisabled = false; } public async trending() { this.clear(); + this.scrollDisabled = true; + this.isScrolling = false; this.contentLoaded = 12; this.loading() this.popularActive = false; this.trendingActive = true; this.upcomingActive = false; - this.movies = await this.searchService.nowPlayingMovies().toPromise(); - this.tvShows = await this.searchService.trendingTv().toPromise(); + this.movies = await this.searchService.nowPlayingMoviesByPage(0, 12); + this.tvShows = await this.searchService.trendingTvByPage(0, 12); this.createModel(); + this.scrollDisabled = false; } public async upcoming() { this.clear(); + this.scrollDisabled = true; + this.isScrolling = false; this.contentLoaded = 12; this.loading() this.popularActive = false; this.trendingActive = false; this.upcomingActive = true; - this.movies = await this.searchService.upcomingMovies().toPromise(); - this.tvShows = await this.searchService.anticipatedTv().toPromise(); + this.movies = await this.searchService.upcomingMoviesByPage(0, 12); + this.tvShows = await this.searchService.anticipatedTvByPage(0, 12); this.createModel(); + this.scrollDisabled = false; } private createModel() { diff --git a/src/Ombi/ClientApp/src/app/services/searchV2.service.ts b/src/Ombi/ClientApp/src/app/services/searchV2.service.ts index 7e720a31f..61ae3a471 100644 --- a/src/Ombi/ClientApp/src/app/services/searchV2.service.ts +++ b/src/Ombi/ClientApp/src/app/services/searchV2.service.ts @@ -34,17 +34,24 @@ export class SearchV2Service extends ServiceHelpers { return this.http.get(`${this.url}/Movie/Popular`); } - public popularMoviesByPage(currentlyLoaded: number, toLoad: number): Observable { - return this.http.get(`${this.url}/Movie/Popular/${currentlyLoaded}/${toLoad}`); + public popularMoviesByPage(currentlyLoaded: number, toLoad: number): Promise { + return this.http.get(`${this.url}/Movie/Popular/${currentlyLoaded}/${toLoad}`).toPromise(); } public upcomingMovies(): Observable { return this.http.get(`${this.url}/Movie/upcoming`); } + public upcomingMoviesByPage(currentlyLoaded: number, toLoad: number): Promise { + return this.http.get(`${this.url}/Movie/upcoming/${currentlyLoaded}/${toLoad}`).toPromise(); + } + public nowPlayingMovies(): Observable { return this.http.get(`${this.url}/Movie/nowplaying`); } + public nowPlayingMoviesByPage(currentlyLoaded: number, toLoad: number): Promise { + return this.http.get(`${this.url}/Movie/nowplaying/${currentlyLoaded}/${toLoad}`).toPromise(); + } public topRatedMovies(): Observable { return this.http.get(`${this.url}/Movie/toprated`); @@ -64,10 +71,17 @@ export class SearchV2Service extends ServiceHelpers { public anticipatedTv(): Observable { return this.http.get(`${this.url}/Tv/anticipated`, { headers: this.headers }); } + public anticipatedTvByPage(currentlyLoaded: number, toLoad: number): Promise { + return this.http.get(`${this.url}/Tv/anticipated/${currentlyLoaded}/${toLoad}`, { headers: this.headers }).toPromise(); + } public trendingTv(): Observable { return this.http.get(`${this.url}/Tv/trending`, { headers: this.headers }); } + + public trendingTvByPage(currentlyLoaded: number, toLoad: number): Promise { + return this.http.get(`${this.url}/Tv/trending/${currentlyLoaded}/${toLoad}`, { headers: this.headers }).toPromise(); + } public getTvInfo(tvdbid: number): Promise { return this.http.get(`${this.url}/Tv/${tvdbid}`, { headers: this.headers }).toPromise(); diff --git a/src/Ombi/Controllers/V2/SearchController.cs b/src/Ombi/Controllers/V2/SearchController.cs index c29e2365d..b898f98c2 100644 --- a/src/Ombi/Controllers/V2/SearchController.cs +++ b/src/Ombi/Controllers/V2/SearchController.cs @@ -148,6 +148,19 @@ namespace Ombi.Controllers.V2 return await _movieEngineV2.NowPlayingMovies(); } + /// + /// Returns Now Playing Movies by page + /// + /// We use TheMovieDb as the Movie Provider + /// + [HttpGet("movie/nowplaying/{currentPosition}/{amountToLoad}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] + public async Task> NowPlayingMovies(int currentPosition, int amountToLoad) + { + return await _movieEngineV2.NowPlayingMovies(currentPosition, amountToLoad); + } + /// /// Returns top rated movies. /// @@ -161,6 +174,19 @@ namespace Ombi.Controllers.V2 return await _movieEngineV2.TopRatedMovies(); } + /// + /// Returns top rated movies by page. + /// + /// + /// We use TheMovieDb as the Movie Provider + [HttpGet("movie/toprated/{currentPosition}/{amountToLoad}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] + public async Task> TopRatedMovies(int currentPosition, int amountToLoad) + { + return await _movieEngineV2.TopRatedMovies(currentPosition, amountToLoad); + } + /// /// Returns Upcoming movies. /// @@ -174,6 +200,19 @@ namespace Ombi.Controllers.V2 return await _movieEngineV2.UpcomingMovies(); } + /// + /// Returns Upcoming movies by page. + /// + /// We use TheMovieDb as the Movie Provider + /// + [HttpGet("movie/upcoming/{currentPosition}/{amountToLoad}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] + public async Task> UpcomingMovies(int currentPosition, int amountToLoad) + { + return await _movieEngineV2.UpcomingMovies(currentPosition, amountToLoad); + } + /// /// Returns Popular Tv Shows /// @@ -201,7 +240,7 @@ namespace Ombi.Controllers.V2 } /// - /// Returns most Anticiplateds tv shows. + /// Returns most Anticipated tv shows. /// /// We use Trakt.tv as the Provider /// @@ -213,6 +252,19 @@ namespace Ombi.Controllers.V2 return await _tvSearchEngine.Anticipated(); } + /// + /// Returns most Anticipated tv shows by page. + /// + /// We use Trakt.tv as the Provider + /// + [HttpGet("tv/anticipated/{currentPosition}/{amountToLoad}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] + public async Task> AnticipatedTv(int currentPosition, int amountToLoad) + { + return await _tvSearchEngine.Anticipated(currentPosition, amountToLoad); + } + /// /// Returns Most watched shows. @@ -227,6 +279,19 @@ namespace Ombi.Controllers.V2 return await _tvSearchEngine.MostWatches(); } + /// + /// Returns Most watched shows by page. + /// + /// We use Trakt.tv as the Provider + /// + [HttpGet("tv/mostwatched/{currentPosition}/{amountToLoad}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] + public async Task> MostWatched(int currentPosition, int amountToLoad) + { + return await _tvSearchEngine.MostWatches(currentPosition, amountToLoad); + } + /// /// Returns trending shows /// @@ -239,5 +304,18 @@ namespace Ombi.Controllers.V2 { return await _tvSearchEngine.Trending(); } + + /// + /// Returns trending shows by page + /// + /// We use Trakt.tv as the Provider + /// + [HttpGet("tv/trending/{currentPosition}/{amountToLoad}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] + public async Task> Trending(int currentPosition, int amountToLoad) + { + return await _tvSearchEngine.Trending(currentPosition, amountToLoad); + } } } \ No newline at end of file