@ -33,6 +33,7 @@ using NLog;
using Ombi.Api.Interfaces ;
using Ombi.Api.Interfaces ;
using Ombi.Api.Models.Emby ;
using Ombi.Api.Models.Emby ;
using Ombi.Helpers ;
using Ombi.Helpers ;
using Polly ;
using RestSharp ;
using RestSharp ;
namespace Ombi.Api
namespace Ombi.Api
@ -71,6 +72,26 @@ namespace Ombi.Api
return obj ;
return obj ;
}
}
public EmbySystemInfo GetSystemInformation ( string apiKey , Uri baseUrl )
{
var request = new RestRequest
{
Resource = "emby/System/Info" ,
Method = Method . GET
} ;
AddHeaders ( request , apiKey ) ;
var policy = RetryHandler . RetryAndWaitPolicy ( ( exception , timespan ) = > Log . Error ( exception , "Exception when calling GetSystemInformation for Emby, Retrying {0}" , timespan ) , new [ ] {
TimeSpan . FromSeconds ( 1 ) ,
TimeSpan . FromSeconds ( 5 )
} ) ;
var obj = policy . Execute ( ( ) = > Api . ExecuteJson < EmbySystemInfo > ( request , baseUrl ) ) ;
return obj ;
}
public EmbyItemContainer < EmbyLibrary > ViewLibrary ( string apiKey , string userId , Uri baseUri )
public EmbyItemContainer < EmbyLibrary > ViewLibrary ( string apiKey , string userId , Uri baseUri )
{
{
var request = new RestRequest
var request = new RestRequest
@ -142,29 +163,71 @@ namespace Ombi.Api
TimeSpan . FromSeconds ( 5 )
TimeSpan . FromSeconds ( 5 )
} ) ;
} ) ;
switch ( type )
IRestResponse response = null ;
try
{
switch ( type )
{
case EmbyMediaType . Movie :
response = policy . Execute ( ( ) = > Api . Execute ( request , baseUri ) ) ;
break ;
case EmbyMediaType . Series :
response = policy . Execute ( ( ) = > Api . Execute ( request , baseUri ) ) ;
break ;
case EmbyMediaType . Music :
break ;
case EmbyMediaType . Episode :
response = policy . Execute ( ( ) = > Api . Execute ( request , baseUri ) ) ;
break ;
default :
throw new ArgumentOutOfRangeException ( nameof ( type ) , type , null ) ;
}
var info = new EmbyInformation ( ) ;
switch ( type )
{
case EmbyMediaType . Movie :
return new EmbyInformation
{
MovieInformation = JsonConvert . DeserializeObject < EmbyMovieInformation > ( response . Content )
} ;
case EmbyMediaType . Series :
return new EmbyInformation
{
SeriesInformation = JsonConvert . DeserializeObject < EmbySeriesInformation > ( response . Content )
} ;
case EmbyMediaType . Music :
break ;
case EmbyMediaType . Episode :
return new EmbyInformation
{
EpisodeInformation = JsonConvert . DeserializeObject < EmbyEpisodeInformation > ( response . Content )
} ;
default :
throw new ArgumentOutOfRangeException ( nameof ( type ) , type , null ) ;
}
}
catch ( Exception e )
{
{
case EmbyMediaType . Movie :
Log . Error ( "Could not get the media item's information" ) ;
return new EmbyInformation
Log . Error ( e ) ;
{
Log . Debug ( "ResponseContent" ) ;
MovieInformation = policy . Execute ( ( ) = > Api . ExecuteJson < EmbyMovieInformation > ( request , baseUri ) )
Log . Debug ( response ? . Content ? ? "Empty" ) ;
} ;
Log . Debug ( "ResponseStatusCode" ) ;
case EmbyMediaType . Series :
Log . Debug ( response ? . StatusCode ? ? HttpStatusCode . PreconditionFailed ) ;
return new EmbyInformation
{
Log . Debug ( "ResponseError" ) ;
SeriesInformation =
Log . Debug ( response ? . ErrorMessage ? ? "No Error" ) ;
policy . Execute ( ( ) = > Api . ExecuteJson < EmbySeriesInformation > ( request , baseUri ) )
Log . Debug ( "ResponseException" ) ;
} ;
Log . Debug ( response ? . ErrorException ? ? new Exception ( ) ) ;
case EmbyMediaType . Music :
break ;
case EmbyMediaType . Episode :
return new EmbyInformation
throw ;
{
EpisodeInformation =
policy . Execute ( ( ) = > Api . ExecuteJson < EmbyEpisodeInformation > ( request , baseUri ) )
} ;
default :
throw new ArgumentOutOfRangeException ( nameof ( type ) , type , null ) ;
}
}
return new EmbyInformation ( ) ;
return new EmbyInformation ( ) ;
}
}