Skip to content

Commit

Permalink
WIP on recently requested
Browse files Browse the repository at this point in the history
  • Loading branch information
tidusjar committed Jul 5, 2021
1 parent bc59a50 commit d417526
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Ombi.Core/Engine/Interfaces/ITvSearchEngineV2.cs
Expand Up @@ -14,5 +14,6 @@ public interface ITVSearchEngineV2
Task<IEnumerable<SearchTvShowViewModel>> Popular(int currentlyLoaded, int amountToLoad, string langCustomCode = null);
Task<IEnumerable<SearchTvShowViewModel>> Anticipated(int currentlyLoaded, int amountToLoad);
Task<IEnumerable<SearchTvShowViewModel>> Trending(int currentlyLoaded, int amountToLoad);
Task<IEnumerable<SearchFullInfoTvShowViewModel>> RecentlyRequestedShows(int currentlyLoaded, int toLoad, CancellationToken cancellationToken);
}
}
2 changes: 1 addition & 1 deletion src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs
Expand Up @@ -200,7 +200,7 @@ public async Task<IEnumerable<SearchMovieViewModel>> SeasonalList(int currentPos
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<SearchMovieViewModel>();
}
Expand Down
43 changes: 42 additions & 1 deletion src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs
Expand Up @@ -23,6 +23,8 @@
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
{
Expand All @@ -33,17 +35,19 @@ public class TvSearchEngineV2 : BaseMediaEngine, ITVSearchEngineV2
private readonly ITraktApi _traktApi;
private readonly IMovieDbApi _movieApi;
private readonly ISettingsService<CustomizationSettings> _customization;
private readonly ITvRequestEngine _requestEngine;

public TvSearchEngineV2(IPrincipal 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)
IRepository<RequestSubscription> sub, IMovieDbApi movieApi, ISettingsService<CustomizationSettings> customization, ITvRequestEngine requestEngine)
: base(identity, service, r, um, memCache, s, sub)
{
_tvMaze = tvMaze;
_mapper = mapper;
_traktApi = trakt;
_movieApi = movieApi;
_customization = customization;
_requestEngine = requestEngine;
}


Expand Down Expand Up @@ -164,6 +168,43 @@ public async Task<IEnumerable<StreamingData>> GetStreamInformation(int movieDbId
return data;
}


public async Task<IEnumerable<SearchFullInfoTvShowViewModel>> RecentlyRequestedShows(int currentlyLoaded, int toLoad, CancellationToken cancellationToken)
{
var langCode = await DefaultLanguageCode(null);

var results = new List<SearchFullInfoTvShowViewModel>();

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<TvInfo>();
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<List<SearchFullInfoTvShowViewModel>>(movieDBResults);

foreach(var map in mapped)
{
var processed = await ProcessResult(map);
results.Add(processed);
}
return results;
}

private async Task<IEnumerable<SearchTvShowViewModel>> ProcessResults(List<MovieDbSearchResult> items)
{
var retVal = new List<SearchTvShowViewModel>();
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Ombi/ClientApp/src/app/services/searchV2.service.ts
Expand Up @@ -63,6 +63,10 @@ export class SearchV2Service extends ServiceHelpers {
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/requested/${currentlyLoaded}/${toLoad}`).toPromise();
}

public recentlyRequestedTvByPage(currentlyLoaded: number, toLoad: number): Promise<ISearchTvResultV2[]> {
return this.http.get<ISearchTvResultV2[]>(`${this.url}/tv/requested/${currentlyLoaded}/${toLoad}`).toPromise();
}

public seasonalMoviesByPage(currentlyLoaded: number, toLoad: number): Promise<ISearchMovieResult[]> {
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/seasonal/${currentlyLoaded}/${toLoad}`).toPromise();
}
Expand Down
12 changes: 12 additions & 0 deletions src/Ombi/Controllers/V2/SearchController.cs
Expand Up @@ -189,6 +189,18 @@ public async Task<IEnumerable<SearchMovieViewModel>> RecentlyRequestedMovies(int
{
return await _movieEngineV2.RecentlyRequestedMovies(currentPosition, amountToLoad, Request.HttpContext.RequestAborted);
}
/// <summary>
/// Returns Recently Requested Tv using Paging
/// </summary>
/// <remarks>We use TheMovieDb as the Movie Provider</remarks>
/// <returns></returns>
[HttpGet("tv/requested/{currentPosition}/{amountToLoad}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesDefaultResponseType]
public async Task<IEnumerable<SearchFullInfoTvShowViewModel>> RecentlyRequestedTv(int currentPosition, int amountToLoad)
{
return await _tvEngineV2.RecentlyRequestedShows(currentPosition, amountToLoad, Request.HttpContext.RequestAborted);
}

/// <summary>
/// Returns Now Playing Movies
Expand Down

0 comments on commit d417526

Please sign in to comment.