@ -20,11 +20,13 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
private readonly Logger _logger ;
private readonly IHttpRequestBuilderFactory _requestBuilder ;
private readonly IHttpRequestBuilderFactory _movieBuilder ;
public SkyHookProxy ( IHttpClient httpClient , ISonarrCloudRequestBuilder requestBuilder , Logger logger )
{
_httpClient = httpClient ;
_requestBuilder = requestBuilder . SkyHookTvdb ;
_movieBuilder = requestBuilder . TMDB ;
_logger = logger ;
}
@ -58,6 +60,65 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
return new Tuple < Series , List < Episode > > ( series , episodes . ToList ( ) ) ;
}
public Movie GetMovieInfo ( int TmdbId )
{
var request = _movieBuilder . Create ( )
. SetSegment ( "route" , "movie" )
. SetSegment ( "id" , TmdbId . ToString ( ) )
. SetSegment ( "secondaryRoute" , "" )
. AddQueryParam ( "append_to_response" , "alternative_titles" )
. AddQueryParam ( "country" , "US" )
. Build ( ) ;
request . AllowAutoRedirect = true ;
request . SuppressHttpError = true ;
var response = _httpClient . Get < MovieResourceRoot > ( request ) ;
var resource = response . Resource ;
var movie = new Movie ( ) ;
movie . TmdbId = TmdbId ;
movie . ImdbId = resource . imdb_id ;
movie . Title = resource . title ;
movie . TitleSlug = movie . Title . ToLower ( ) . Replace ( " " , "-" ) ;
movie . CleanTitle = Parser . Parser . CleanSeriesTitle ( movie . Title ) ;
movie . Overview = resource . overview ;
movie . Website = resource . homepage ;
movie . InCinemas = DateTime . Parse ( resource . release_date ) ;
movie . Year = movie . InCinemas . Value . Year ;
movie . Images . Add ( new MediaCover . MediaCover ( MediaCoverTypes . Poster , "http://image.tmdb.org/t/p/" + "w500" + resource . poster_path ) ) ; //TODO: Update to load image specs from tmdb page!
movie . Images . Add ( new MediaCover . MediaCover ( MediaCoverTypes . Banner , "http://image.tmdb.org/t/p/" + "w1280" + resource . backdrop_path ) ) ;
movie . Runtime = resource . runtime ;
foreach ( Title title in resource . alternative_titles . titles )
{
movie . AlternativeTitles . Add ( title . title ) ;
}
movie . Ratings = new Ratings ( ) ;
movie . Ratings . Votes = resource . vote_count ;
movie . Ratings . Value = ( decimal ) resource . vote_average ;
foreach ( Genre genre in resource . genres )
{
movie . Genres . Add ( genre . name ) ;
}
if ( resource . status = = "Released" )
{
movie . Status = MovieStatusType . Released ;
}
else
{
movie . Status = MovieStatusType . Announced ;
}
return movie ;
}
public Movie GetMovieInfo ( string ImdbId )
{
var imdbRequest = new HttpRequest ( "http://www.omdbapi.com/?i=" + ImdbId + "&plot=full&r=json" ) ;
@ -136,11 +197,22 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
}
}
var searchTerm = lowerTitle . Replace ( " +", "_" ) . Replace ( " " , "_ ") ;
var searchTerm = lowerTitle . Replace ( " _", "+" ) . Replace ( " " , "+ ") ;
var firstChar = searchTerm . First ( ) ;
var imdbRequest = new HttpRequest ( "https://v2.sg.media-imdb.com/suggests/" + firstChar + "/" + searchTerm + ".json" ) ;
var request = _movieBuilder . Create ( )
. SetSegment ( "route" , "search" )
. SetSegment ( "id" , "movie" )
. SetSegment ( "secondaryRoute" , "" )
. AddQueryParam ( "query" , searchTerm )
. AddQueryParam ( "include_adult" , false )
. Build ( ) ;
request . AllowAutoRedirect = true ;
request . SuppressHttpError = true ;
/ * var imdbRequest = new HttpRequest ( "https://v2.sg.media-imdb.com/suggests/" + firstChar + "/" + searchTerm + ".json" ) ;
var response = _httpClient . Get ( imdbRequest ) ;
@ -154,31 +226,35 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
_logger . Warn ( "Json object: " + json ) ;
_logger . Warn ( "Crash ahead." ) ;
_logger . Warn ( "Crash ahead." ) ; * /
var response = _httpClient . Get < MovieSearchRoot > ( request ) ;
var movieResults = response . Resource . results ;
var imdbMovies = new List < Movie > ( ) ;
foreach ( MovieResource entry in json . d )
foreach ( MovieRes ult result in movieResults )
{
var imdbMovie = new Movie ( ) ;
imdbMovie . ImdbId = entry . id ;
imdbMovie . TmdbId = result . id ;
try
{
imdbMovie . SortTitle = entry. l ;
imdbMovie . Title = entry. l ;
string titleSlug = entry. l ;
imdbMovie . SortTitle = result. title ;
imdbMovie . Title = result. title ;
string titleSlug = result. title ;
imdbMovie . TitleSlug = titleSlug . ToLower ( ) . Replace ( " " , "-" ) ;
imdbMovie . Year = entry. y ;
imdbMovie . Year = DateTime. Parse ( result . release_date ) . Year ;
imdbMovie . Images = new List < MediaCover . MediaCover > ( ) ;
try
{
string url = ( string ) entry . i [ 0 ] ;
var imdbPoster = new MediaCover . MediaCover ( MediaCoverTypes . Poster , url ) ;
string url = result . poster_path ;
var imdbPoster = new MediaCover . MediaCover ( MediaCoverTypes . Poster , "http://image.tmdb.org/t/p/" + "w500" + url ) ;
imdbMovie . Images . Add ( imdbPoster ) ;
}
catch ( Exception e )
{
_logger . Debug ( entry ) ;
_logger . Debug ( result ) ;
continue ;
}