@ -1,23 +1,22 @@
using System ;
using AutoMapper ;
using AutoMapper ;
using Microsoft.EntityFrameworkCore ;
using Microsoft.Extensions.Logging ;
using Ombi.Api.TheMovieDb ;
using Ombi.Api.TheMovieDb.Models ;
using Ombi.Core.Authentication ;
using Ombi.Core.Models.Requests ;
using Ombi.Core.Models.Search ;
using System.Collections.Generic ;
using System.Linq ;
using System.Security.Principal ;
using System.Threading.Tasks ;
using Microsoft.EntityFrameworkCore ;
using Ombi.Core.Rule.Interfaces ;
using Microsoft.Extensions.Caching.Memory ;
using Ombi.Core.Authentication ;
using Ombi.Core.Settings ;
using Ombi.Helpers ;
using Ombi.Settings.Settings.Models ;
using Ombi.Store.Entities ;
using Ombi.Store.Repository ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Security.Principal ;
using System.Threading.Tasks ;
namespace Ombi.Core.Engine
{
@ -43,8 +42,9 @@ namespace Ombi.Core.Engine
/// </summary>
/// <param name="theMovieDbId">The movie database identifier.</param>
/// <returns></returns>
public async Task < SearchMovieViewModel > LookupImdbInformation ( int theMovieDbId , string langCode = "en" )
public async Task < SearchMovieViewModel > LookupImdbInformation ( int theMovieDbId , string langCode = null )
{
langCode = await DefaultLanguageCode ( langCode ) ;
var movieInfo = await MovieApi . GetMovieInformationWithExtraInfo ( theMovieDbId , langCode ) ;
var viewMovie = Mapper . Map < SearchMovieViewModel > ( movieInfo ) ;
@ -58,6 +58,7 @@ namespace Ombi.Core.Engine
/// <returns></returns>
public async Task < IEnumerable < SearchMovieViewModel > > Search ( string search , int? year , string langaugeCode )
{
langaugeCode = await DefaultLanguageCode ( langaugeCode ) ;
var result = await MovieApi . SearchMovie ( search , year , langaugeCode ) ;
if ( result ! = null )
@ -72,9 +73,10 @@ namespace Ombi.Core.Engine
/// </summary>
/// <param name="theMovieDbId"></param>
/// <returns></returns>
public async Task < IEnumerable < SearchMovieViewModel > > SimilarMovies ( int theMovieDbId )
public async Task < IEnumerable < SearchMovieViewModel > > SimilarMovies ( int theMovieDbId , string langCode )
{
var result = await MovieApi . SimilarMovies ( theMovieDbId ) ;
langCode = await DefaultLanguageCode ( langCode ) ;
var result = await MovieApi . SimilarMovies ( theMovieDbId , langCode ) ;
if ( result ! = null )
{
Logger . LogDebug ( "Search Result: {result}" , result ) ;
@ -89,7 +91,12 @@ namespace Ombi.Core.Engine
/// <returns></returns>
public async Task < IEnumerable < SearchMovieViewModel > > PopularMovies ( )
{
var result = await Cache . GetOrAdd ( CacheKeys . PopularMovies , async ( ) = > await MovieApi . PopularMovies ( ) , DateTime . Now . AddHours ( 12 ) ) ;
var result = await Cache . GetOrAdd ( CacheKeys . PopularMovies , async ( ) = >
{
var langCode = await DefaultLanguageCode ( null ) ;
return await MovieApi . PopularMovies ( langCode ) ;
} , DateTime . Now . AddHours ( 12 ) ) ;
if ( result ! = null )
{
return await TransformMovieResultsToResponse ( result . Take ( MovieLimit ) ) ; // Take x to stop us overloading the API
@ -103,7 +110,11 @@ namespace Ombi.Core.Engine
/// <returns></returns>
public async Task < IEnumerable < SearchMovieViewModel > > TopRatedMovies ( )
{
var result = await Cache . GetOrAdd ( CacheKeys . TopRatedMovies , async ( ) = > await MovieApi . TopRated ( ) , DateTime . Now . AddHours ( 12 ) ) ;
var result = await Cache . GetOrAdd ( CacheKeys . TopRatedMovies , async ( ) = >
{
var langCode = await DefaultLanguageCode ( null ) ;
return await MovieApi . TopRated ( langCode ) ;
} , DateTime . Now . AddHours ( 12 ) ) ;
if ( result ! = null )
{
return await TransformMovieResultsToResponse ( result . Take ( MovieLimit ) ) ; // Take x to stop us overloading the API
@ -117,7 +128,11 @@ namespace Ombi.Core.Engine
/// <returns></returns>
public async Task < IEnumerable < SearchMovieViewModel > > UpcomingMovies ( )
{
var result = await Cache . GetOrAdd ( CacheKeys . UpcomingMovies , async ( ) = > await MovieApi . Upcoming ( ) , DateTime . Now . AddHours ( 12 ) ) ;
var result = await Cache . GetOrAdd ( CacheKeys . UpcomingMovies , async ( ) = >
{
var langCode = await DefaultLanguageCode ( null ) ;
return await MovieApi . Upcoming ( langCode ) ;
} , DateTime . Now . AddHours ( 12 ) ) ;
if ( result ! = null )
{
Logger . LogDebug ( "Search Result: {result}" , result ) ;
@ -132,7 +147,11 @@ namespace Ombi.Core.Engine
/// <returns></returns>
public async Task < IEnumerable < SearchMovieViewModel > > NowPlayingMovies ( )
{
var result = await Cache . GetOrAdd ( CacheKeys . NowPlayingMovies , async ( ) = > await MovieApi . NowPlaying ( ) , DateTime . Now . AddHours ( 12 ) ) ;
var result = await Cache . GetOrAdd ( CacheKeys . NowPlayingMovies , async ( ) = >
{
var langCode = await DefaultLanguageCode ( null ) ;
return await MovieApi . NowPlaying ( langCode ) ;
} , DateTime . Now . AddHours ( 12 ) ) ;
if ( result ! = null )
{
return await TransformMovieResultsToResponse ( result . Take ( MovieLimit ) ) ; // Take x to stop us overloading the API