@ -1,4 +1,5 @@
using System.Collections.Generic ;
using System.Collections.Generic ;
using System.Net ;
using System.Net.Http ;
using System.Net.Http ;
using System.Threading.Tasks ;
using System.Threading.Tasks ;
using AutoMapper ;
using AutoMapper ;
@ -25,15 +26,37 @@ namespace Ombi.Api.TheMovieDb
{
{
var request = new Request ( $"movie/{movieId}" , BaseUri , HttpMethod . Get ) ;
var request = new Request ( $"movie/{movieId}" , BaseUri , HttpMethod . Get ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
AddRetry ( request ) ;
var result = await Api . Request < MovieResponse > ( request ) ;
var result = await Api . Request < MovieResponse > ( request ) ;
return Mapper . Map < MovieResponseDto > ( result ) ;
return Mapper . Map < MovieResponseDto > ( result ) ;
}
}
public async Task < FindResult > Find ( string externalId , ExternalSource source )
{
var request = new Request ( $"find/{externalId}" , BaseUri , HttpMethod . Get ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
AddRetry ( request ) ;
request . AddQueryString ( "external_source" , source . ToString ( ) ) ;
return await Api . Request < FindResult > ( request ) ;
}
public async Task < TvExternals > GetTvExternals ( int theMovieDbId )
{
var request = new Request ( $"/tv/{theMovieDbId}/external_ids" , BaseUri , HttpMethod . Get ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
AddRetry ( request ) ;
return await Api . Request < TvExternals > ( request ) ;
}
public async Task < List < MovieSearchResult > > SimilarMovies ( int movieId )
public async Task < List < MovieSearchResult > > SimilarMovies ( int movieId )
{
{
var request = new Request ( $"movie/{movieId}/similar" , BaseUri , HttpMethod . Get ) ;
var request = new Request ( $"movie/{movieId}/similar" , BaseUri , HttpMethod . Get ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
AddRetry ( request ) ;
var result = await Api . Request < TheMovieDbContainer < SearchResult > > ( request ) ;
var result = await Api . Request < TheMovieDbContainer < SearchResult > > ( request ) ;
return Mapper . Map < List < MovieSearchResult > > ( result . results ) ;
return Mapper . Map < List < MovieSearchResult > > ( result . results ) ;
@ -44,6 +67,7 @@ namespace Ombi.Api.TheMovieDb
var request = new Request ( $"movie/{movieId}" , BaseUri , HttpMethod . Get ) ;
var request = new Request ( $"movie/{movieId}" , BaseUri , HttpMethod . Get ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "append_to_response" , "videos,release_dates" ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "append_to_response" , "videos,release_dates" ) ;
AddRetry ( request ) ;
var result = await Api . Request < MovieResponse > ( request ) ;
var result = await Api . Request < MovieResponse > ( request ) ;
return Mapper . Map < MovieResponseDto > ( result ) ;
return Mapper . Map < MovieResponseDto > ( result ) ;
}
}
@ -53,6 +77,7 @@ namespace Ombi.Api.TheMovieDb
var request = new Request ( $"search/movie" , BaseUri , HttpMethod . Get ) ;
var request = new Request ( $"search/movie" , BaseUri , HttpMethod . Get ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "query" , searchTerm ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "query" , searchTerm ) ;
AddRetry ( request ) ;
var result = await Api . Request < TheMovieDbContainer < SearchResult > > ( request ) ;
var result = await Api . Request < TheMovieDbContainer < SearchResult > > ( request ) ;
return Mapper . Map < List < MovieSearchResult > > ( result . results ) ;
return Mapper . Map < List < MovieSearchResult > > ( result . results ) ;
@ -62,6 +87,7 @@ namespace Ombi.Api.TheMovieDb
{
{
var request = new Request ( $"movie/popular" , BaseUri , HttpMethod . Get ) ;
var request = new Request ( $"movie/popular" , BaseUri , HttpMethod . Get ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
AddRetry ( request ) ;
var result = await Api . Request < TheMovieDbContainer < SearchResult > > ( request ) ;
var result = await Api . Request < TheMovieDbContainer < SearchResult > > ( request ) ;
return Mapper . Map < List < MovieSearchResult > > ( result . results ) ;
return Mapper . Map < List < MovieSearchResult > > ( result . results ) ;
}
}
@ -70,6 +96,7 @@ namespace Ombi.Api.TheMovieDb
{
{
var request = new Request ( $"movie/top_rated" , BaseUri , HttpMethod . Get ) ;
var request = new Request ( $"movie/top_rated" , BaseUri , HttpMethod . Get ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
AddRetry ( request ) ;
var result = await Api . Request < TheMovieDbContainer < SearchResult > > ( request ) ;
var result = await Api . Request < TheMovieDbContainer < SearchResult > > ( request ) ;
return Mapper . Map < List < MovieSearchResult > > ( result . results ) ;
return Mapper . Map < List < MovieSearchResult > > ( result . results ) ;
}
}
@ -78,6 +105,7 @@ namespace Ombi.Api.TheMovieDb
{
{
var request = new Request ( $"movie/upcoming" , BaseUri , HttpMethod . Get ) ;
var request = new Request ( $"movie/upcoming" , BaseUri , HttpMethod . Get ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
AddRetry ( request ) ;
var result = await Api . Request < TheMovieDbContainer < SearchResult > > ( request ) ;
var result = await Api . Request < TheMovieDbContainer < SearchResult > > ( request ) ;
return Mapper . Map < List < MovieSearchResult > > ( result . results ) ;
return Mapper . Map < List < MovieSearchResult > > ( result . results ) ;
}
}
@ -86,9 +114,14 @@ namespace Ombi.Api.TheMovieDb
{
{
var request = new Request ( $"movie/now_playing" , BaseUri , HttpMethod . Get ) ;
var request = new Request ( $"movie/now_playing" , BaseUri , HttpMethod . Get ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
request . FullUri = request . FullUri . AddQueryParameter ( "api_key" , ApiToken ) ;
AddRetry ( request ) ;
var result = await Api . Request < TheMovieDbContainer < SearchResult > > ( request ) ;
var result = await Api . Request < TheMovieDbContainer < SearchResult > > ( request ) ;
return Mapper . Map < List < MovieSearchResult > > ( result . results ) ;
return Mapper . Map < List < MovieSearchResult > > ( result . results ) ;
}
}
private static void AddRetry ( Request request )
{
request . Retry = true ;
request . StatusCodeToRetry . Add ( ( HttpStatusCode ) 429 ) ;
}
}
}
}
}