@ -10,6 +10,7 @@ using NzbDrone.Core.Exceptions;
using NzbDrone.Core.MediaCover ;
using NzbDrone.Core.MediaCover ;
using NzbDrone.Core.MetadataSource.SkyHook.Resource ;
using NzbDrone.Core.MetadataSource.SkyHook.Resource ;
using NzbDrone.Core.Tv ;
using NzbDrone.Core.Tv ;
using Newtonsoft.Json ;
namespace NzbDrone.Core.MetadataSource.SkyHook
namespace NzbDrone.Core.MetadataSource.SkyHook
{
{
@ -37,7 +38,11 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
httpRequest . AllowAutoRedirect = true ;
httpRequest . AllowAutoRedirect = true ;
httpRequest . SuppressHttpError = true ;
httpRequest . SuppressHttpError = true ;
var httpResponse = _httpClient . Get < ShowResource > ( httpRequest ) ;
string imdbId = string . Format ( "tt{0:D7}" , tvdbSeriesId ) ;
var imdbRequest = new HttpRequest ( "http://www.omdbapi.com/?i=" + imdbId + "&plot=full&r=json" ) ;
var httpResponse = _httpClient . Get ( imdbRequest ) ;
if ( httpResponse . HasHttpError )
if ( httpResponse . HasHttpError )
{
{
@ -51,8 +56,43 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
}
}
}
}
var episodes = httpResponse . Resource . Episodes . Select ( MapEpisode ) ;
var response = httpResponse . Content ;
var series = MapSeries ( httpResponse . Resource ) ;
dynamic json = JsonConvert . DeserializeObject ( response ) ;
var series = new Series ( ) ;
series . Title = json . Title ;
series . TitleSlug = series . Title . ToLower ( ) . Replace ( " " , "-" ) ;
series . Overview = json . Plot ;
series . CleanTitle = series . Title ;
series . TvdbId = tvdbSeriesId ;
string airDateStr = json . Released ;
DateTime airDate = DateTime . Parse ( airDateStr ) ;
series . FirstAired = airDate ;
series . Year = airDate . Year ;
series . ImdbId = imdbId ;
series . Images = new List < MediaCover . MediaCover > ( ) ;
string url = json . Poster ;
var imdbPoster = new MediaCover . MediaCover ( MediaCoverTypes . Poster , url ) ;
series . Images . Add ( imdbPoster ) ;
var season = new Season ( ) ;
season . SeasonNumber = 1 ;
season . Monitored = true ;
series . Seasons . Add ( season ) ;
var episode = new Episode ( ) ;
episode . AirDate = airDate . ToShortTimeString ( ) ;
episode . Title = json . Title ;
episode . SeasonNumber = 1 ;
episode . EpisodeNumber = 1 ;
episode . Overview = series . Overview ;
episode . AirDate = airDate . ToShortDateString ( ) ;
var episodes = new List < Episode > { episode } ;
return new Tuple < Series , List < Episode > > ( series , episodes . ToList ( ) ) ;
return new Tuple < Series , List < Episode > > ( series , episodes . ToList ( ) ) ;
}
}
@ -89,6 +129,66 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
. AddQueryParam ( "term" , title . ToLower ( ) . Trim ( ) )
. AddQueryParam ( "term" , title . ToLower ( ) . Trim ( ) )
. Build ( ) ;
. Build ( ) ;
var searchTerm = lowerTitle . Replace ( "+" , "_" ) . Replace ( " " , "_" ) ;
var firstChar = searchTerm . First ( ) ;
var imdbRequest = new HttpRequest ( "https://v2.sg.media-imdb.com/suggests/" + firstChar + "/" + searchTerm + ".json" ) ;
var response = _httpClient . Get ( imdbRequest ) ;
var imdbCallback = "imdb$" + searchTerm + "(" ;
var responseCleaned = response . Content . Replace ( imdbCallback , "" ) . TrimEnd ( ")" ) ;
dynamic json = JsonConvert . DeserializeObject ( responseCleaned ) ;
var imdbMovies = new List < Series > ( ) ;
foreach ( dynamic entry in json . d )
{
var imdbMovie = new Series ( ) ;
imdbMovie . ImdbId = entry . id ;
string noTT = imdbMovie . ImdbId . Replace ( "tt" , "" ) ;
try
{
imdbMovie . TvdbId = ( int ) Double . Parse ( noTT ) ;
}
catch
{
imdbMovie . TvdbId = 0 ;
}
try
{
imdbMovie . SortTitle = entry . l ;
imdbMovie . Title = entry . l ;
string titleSlug = entry . l ;
imdbMovie . TitleSlug = titleSlug . ToLower ( ) . Replace ( " " , "-" ) ;
imdbMovie . Year = entry . y ;
imdbMovie . Images = new List < MediaCover . MediaCover > ( ) ;
try
{
string url = entry . i [ 0 ] ;
var imdbPoster = new MediaCover . MediaCover ( MediaCoverTypes . Poster , url ) ;
imdbMovie . Images . Add ( imdbPoster ) ;
}
catch ( Exception e )
{
_logger . Debug ( entry ) ;
continue ;
}
imdbMovies . Add ( imdbMovie ) ;
}
catch
{
}
}
return imdbMovies ;
var httpResponse = _httpClient . Get < List < ShowResource > > ( httpRequest ) ;
var httpResponse = _httpClient . Get < List < ShowResource > > ( httpRequest ) ;
return httpResponse . Resource . SelectList ( MapSeries ) ;
return httpResponse . Resource . SelectList ( MapSeries ) ;