diff --git a/src/Ombi.Core/Engine/Interfaces/ITvSearchEngineV2.cs b/src/Ombi.Core/Engine/Interfaces/ITvSearchEngineV2.cs index 3e2d859c8..25a3c2621 100644 --- a/src/Ombi.Core/Engine/Interfaces/ITvSearchEngineV2.cs +++ b/src/Ombi.Core/Engine/Interfaces/ITvSearchEngineV2.cs @@ -14,5 +14,6 @@ namespace Ombi.Core Task> Popular(int currentlyLoaded, int amountToLoad, string langCustomCode = null); Task> Anticipated(int currentlyLoaded, int amountToLoad); Task> Trending(int currentlyLoaded, int amountToLoad); + Task> RecentlyRequestedShows(int currentlyLoaded, int toLoad, CancellationToken cancellationToken); } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs index b29171eaf..4ff99225a 100644 --- a/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs +++ b/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs @@ -200,7 +200,7 @@ namespace Ombi.Core.Engine.V2 var result = await _client.GetAsync("https://raw.githubusercontent.com/Ombi-app/Ombi.News/main/Seasonal.md"); var keyWordIds = await result.Content.ReadAsStringAsync(); - if (string.IsNullOrEmpty(keyWordIds)) + if (string.IsNullOrEmpty(keyWordIds) || keyWordIds.Equals("\n")) { return new List(); } diff --git a/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs index 865693244..6bb67debd 100644 --- a/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs +++ b/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs @@ -23,6 +23,8 @@ using System.Threading; using Ombi.Api.TheMovieDb; using Ombi.Api.TheMovieDb.Models; using System.Diagnostics; +using Ombi.Core.Engine.Interfaces; +using Ombi.Core.Models.UI; namespace Ombi.Core.Engine.V2 { @@ -33,10 +35,11 @@ namespace Ombi.Core.Engine.V2 private readonly ITraktApi _traktApi; private readonly IMovieDbApi _movieApi; private readonly ISettingsService _customization; + private readonly ITvRequestEngine _requestEngine; public TvSearchEngineV2(IPrincipal identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper, ITraktApi trakt, IRuleEvaluator r, OmbiUserManager um, ICacheService memCache, ISettingsService s, - IRepository sub, IMovieDbApi movieApi, ISettingsService customization) + IRepository sub, IMovieDbApi movieApi, ISettingsService customization, ITvRequestEngine requestEngine) : base(identity, service, r, um, memCache, s, sub) { _tvMaze = tvMaze; @@ -44,6 +47,7 @@ namespace Ombi.Core.Engine.V2 _traktApi = trakt; _movieApi = movieApi; _customization = customization; + _requestEngine = requestEngine; } @@ -164,6 +168,43 @@ namespace Ombi.Core.Engine.V2 return data; } + + public async Task> RecentlyRequestedShows(int currentlyLoaded, int toLoad, CancellationToken cancellationToken) + { + var langCode = await DefaultLanguageCode(null); + + var results = new List(); + + var requestResult = await Cache.GetOrAdd(nameof(RecentlyRequestedShows) + "Requests" + toLoad + langCode, + async () => + { + return await _requestEngine.GetRequests(toLoad, currentlyLoaded, new Models.UI.OrderFilterModel + { + OrderType = OrderType.RequestedDateDesc + }); + }, DateTime.Now.AddMinutes(15), cancellationToken); + + var movieDBResults = await Cache.GetOrAdd(nameof(RecentlyRequestedShows) + toLoad + langCode, + async () => + { + var responses = new List(); + foreach (var movie in requestResult.Collection) + { + responses.Add(await _movieApi.GetTVInfo(movie.ExternalProviderId.ToString())); + } + return responses; + }, DateTime.Now.AddHours(12), cancellationToken); + + var mapped = _mapper.Map>(movieDBResults); + + foreach(var map in mapped) + { + var processed = await ProcessResult(map); + results.Add(processed); + } + return results; + } + private async Task> ProcessResults(List items) { var retVal = new List(); 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 b45f0ccbb..3ab5bbe17 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 @@ -223,8 +223,10 @@ export class CarouselListComponent implements OnInit { break case DiscoverType.RecentlyRequested: this.movies = await this.searchService.recentlyRequestedMoviesByPage(this.currentlyLoaded, this.amountToLoad); + break; case DiscoverType.Seasonal: this.movies = await this.searchService.seasonalMoviesByPage(this.currentlyLoaded, this.amountToLoad); + break; } this.movieCount.emit(this.movies.length); this.currentlyLoaded += this.amountToLoad; @@ -241,6 +243,9 @@ export class CarouselListComponent implements OnInit { case DiscoverType.Upcoming: this.tvShows = await this.searchService.anticipatedTvByPage(this.currentlyLoaded, this.amountToLoad); break + case DiscoverType.RecentlyRequested: + // this.tvShows = await this.searchService.recentlyRequestedMoviesByPage(this.currentlyLoaded, this.amountToLoad); // TODO need to do some more mapping + break; } 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 ece4a26c9..99e5afb39 100644 --- a/src/Ombi/ClientApp/src/app/services/searchV2.service.ts +++ b/src/Ombi/ClientApp/src/app/services/searchV2.service.ts @@ -63,6 +63,10 @@ export class SearchV2Service extends ServiceHelpers { return this.http.get(`${this.url}/Movie/requested/${currentlyLoaded}/${toLoad}`).toPromise(); } + public recentlyRequestedTvByPage(currentlyLoaded: number, toLoad: number): Promise { + return this.http.get(`${this.url}/tv/requested/${currentlyLoaded}/${toLoad}`).toPromise(); + } + public seasonalMoviesByPage(currentlyLoaded: number, toLoad: number): Promise { return this.http.get(`${this.url}/Movie/seasonal/${currentlyLoaded}/${toLoad}`).toPromise(); } diff --git a/src/Ombi/Controllers/V2/SearchController.cs b/src/Ombi/Controllers/V2/SearchController.cs index 6d911ec71..d59bf8fcd 100644 --- a/src/Ombi/Controllers/V2/SearchController.cs +++ b/src/Ombi/Controllers/V2/SearchController.cs @@ -189,6 +189,18 @@ namespace Ombi.Controllers.V2 { return await _movieEngineV2.RecentlyRequestedMovies(currentPosition, amountToLoad, Request.HttpContext.RequestAborted); } + /// + /// Returns Recently Requested Tv using Paging + /// + /// We use TheMovieDb as the Movie Provider + /// + [HttpGet("tv/requested/{currentPosition}/{amountToLoad}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesDefaultResponseType] + public async Task> RecentlyRequestedTv(int currentPosition, int amountToLoad) + { + return await _tvEngineV2.RecentlyRequestedShows(currentPosition, amountToLoad, Request.HttpContext.RequestAborted); + } /// /// Returns Now Playing Movies