Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tidusjar committed Mar 19, 2021
1 parent 10c47d0 commit e39f35c
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 345 deletions.
1 change: 1 addition & 0 deletions src/Ombi.Core/Engine/Interfaces/IMovieEngineV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ public interface IMovieEngineV2

Task<MovieFullInfoViewModel> GetMovieInfoByImdbId(string imdbId, CancellationToken requestAborted);
Task<IEnumerable<StreamingData>> GetStreamInformation(int movieDbId, CancellationToken cancellationToken);
Task<IEnumerable<SearchMovieViewModel>> RecentlyRequestedMovies(int currentlyLoaded, int toLoad, CancellationToken cancellationToken);
}
}
48 changes: 43 additions & 5 deletions src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
using Ombi.Core.Models.Requests;
using Ombi.Core.Models.Search;
using Ombi.Core.Models.Search.V2;
using Ombi.Core.Models.UI;
using Ombi.Core.Rule.Interfaces;
using Ombi.Core.Settings;
using Ombi.Helpers;
using Ombi.Settings.Settings.Models;
using Ombi.Store.Entities;
using Ombi.Store.Entities.Requests;
using Ombi.Store.Repository;
using System;
using System.Collections.Generic;
Expand All @@ -27,20 +29,21 @@ public class MovieSearchEngineV2 : BaseMediaEngine, IMovieEngineV2
{
public MovieSearchEngineV2(IPrincipal identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper,
ILogger<MovieSearchEngineV2> logger, IRuleEvaluator r, OmbiUserManager um, ICacheService mem, ISettingsService<OmbiSettings> s, IRepository<RequestSubscription> sub,
ISettingsService<CustomizationSettings> customizationSettings)
ISettingsService<CustomizationSettings> customizationSettings, IMovieRequestEngine movieRequestEngine)
: base(identity, service, r, um, mem, s, sub)
{
MovieApi = movApi;
Mapper = mapper;
Logger = logger;
_customizationSettings = customizationSettings;
_movieRequestEngine = movieRequestEngine;
}

private IMovieDbApi MovieApi { get; }
private IMapper Mapper { get; }
private ILogger Logger { get; }
private readonly ISettingsService<CustomizationSettings> _customizationSettings;

private readonly IMovieRequestEngine _movieRequestEngine;

public async Task<MovieFullInfoViewModel> GetFullMovieInformation(int theMovieDbId, CancellationToken cancellationToken, string langCode = null)
{
Expand Down Expand Up @@ -187,6 +190,41 @@ public async Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies(int curren
return await TransformMovieResultsToResponse(results);
}

/// <summary>
/// Gets recently requested movies
/// </summary>
/// <returns></returns>
public async Task<IEnumerable<SearchMovieViewModel>> RecentlyRequestedMovies(int currentlyLoaded, int toLoad, CancellationToken cancellationToken)
{
var langCode = await DefaultLanguageCode(null);

var results = new List<MovieResponseDto>();

var requestResult = await Cache.GetOrAdd(nameof(RecentlyRequestedMovies) + "Requests" + toLoad + langCode,
async () =>
{
return await _movieRequestEngine.GetRequests(toLoad, currentlyLoaded, new Models.UI.OrderFilterModel
{
OrderType = OrderType.RequestedDateDesc
});
}, DateTime.Now.AddMinutes(15), cancellationToken);

var movieDBResults = await Cache.GetOrAdd(nameof(RecentlyRequestedMovies) + toLoad + langCode,
async () =>
{
var responses = new List<MovieResponseDto>();
foreach(var movie in requestResult.Collection)
{
responses.Add(await MovieApi.GetMovieInformation(movie.TheMovieDbId));
}
return responses;
}, DateTime.Now.AddHours(12), cancellationToken);

results.AddRange(movieDBResults);

return await TransformMovieResultsToResponse(results);
}


/// <summary>
/// Gets upcoming movies.
Expand Down Expand Up @@ -269,8 +307,8 @@ public async Task<IEnumerable<StreamingData>> GetStreamInformation(int movieDbId
return data;
}

protected async Task<List<SearchMovieViewModel>> TransformMovieResultsToResponse(
IEnumerable<MovieDbSearchResult> movies)
protected async Task<List<SearchMovieViewModel>> TransformMovieResultsToResponse<T>(
IEnumerable<T> movies) where T: new()
{
var settings = await _customizationSettings.GetSettingsAsync();
var viewMovies = new List<SearchMovieViewModel>();
Expand All @@ -286,7 +324,7 @@ protected async Task<List<SearchMovieViewModel>> TransformMovieResultsToResponse
return viewMovies;
}

private async Task<SearchMovieViewModel> ProcessSingleMovie(MovieDbSearchResult movie)
private async Task<SearchMovieViewModel> ProcessSingleMovie<T>(T movie) where T : new()
{
var viewMovie = Mapper.Map<SearchMovieViewModel>(movie);
return await ProcessSingleMovie(viewMovie);
Expand Down
2 changes: 2 additions & 0 deletions src/Ombi.Mapping/Profiles/MovieProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Ombi.Api.TheMovieDb.Models;
using Ombi.Core.Models.Search;
using Ombi.Core.Models.Search.V2;
using Ombi.Store.Entities.Requests;
using Ombi.TheMovieDbApi.Models;
using Keywords = Ombi.Core.Models.Search.V2.Keywords;
using KeywordsValue = Ombi.Api.TheMovieDb.Models.KeywordsValue;
Expand Down Expand Up @@ -76,6 +77,7 @@ public MovieProfile()
CreateMap<TheMovieDbApi.Models.Genre, GenreDto>();

CreateMap<MovieDbSearchResult, SearchMovieViewModel>().ReverseMap();

CreateMap<MovieResponseDto, SearchMovieViewModel>().ReverseMap();

CreateMap<FullMovieInfo, SearchMovieViewModel>().ReverseMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum DiscoverType {
Upcoming,
Trending,
Popular,
RecentlyRequested,
}

@Component({
Expand Down Expand Up @@ -216,6 +217,8 @@ export class CarouselListComponent implements OnInit {
case DiscoverType.Upcoming:
this.movies = await this.searchService.upcomingMoviesByPage(this.currentlyLoaded, this.amountToLoad);
break
case DiscoverType.RecentlyRequested:
this.movies = await this.searchService.recentlyRequestedMoviesByPage(this.currentlyLoaded, this.amountToLoad);
}
this.currentlyLoaded += this.amountToLoad;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
<div class="small-middle-container">
<div *ngIf="loadingFlag" class="row justify-content-md-center top-spacing loading-spinner">
</div>
<div class="section">
<h2>Popular</h2>
<h2>{{'Discovery.PopularTab' | translate}}</h2>
<div>
<carousel-list [id]="'popular'" [discoverType]="DiscoverType.Popular"></carousel-list>
</div>

</div>

<div class="section">
<h2>Trending</h2>
<h2>{{'Discovery.TrendingTab' | translate}}</h2>
<div >
<carousel-list [id]="'trending'" [discoverType]="DiscoverType.Trending"></carousel-list>
</div>

</div>

<div class="section">
<h2>Upcoming</h2>
<h2>{{'Discovery.UpcomingTab' | translate}}</h2>
<div>
<carousel-list [id]="'upcoming'" [discoverType]="DiscoverType.Upcoming"></carousel-list>
</div>

</div>
<!-- <div class="section">
<h2>{{'Discovery.RecentlyRequestedTab' | translate}}</h2>
<div>
<carousel-list [id]="'recentlyRequested'" [discoverType]="DiscoverType.RecentlyRequested"></carousel-list>
</div>
</div> -->
</div>
Loading

0 comments on commit e39f35c

Please sign in to comment.