@ -59,6 +59,8 @@ namespace MediaBrowser.Providers.Omdb
public async Task < IEnumerable < RemoteSearchResult > > GetSearchResults ( ItemLookupInfo searchInfo , string type , CancellationToken cancellationToken )
public async Task < IEnumerable < RemoteSearchResult > > GetSearchResults ( ItemLookupInfo searchInfo , string type , CancellationToken cancellationToken )
{
{
bool isSearch = false ;
var list = new List < RemoteSearchResult > ( ) ;
var list = new List < RemoteSearchResult > ( ) ;
var imdbId = searchInfo . GetProviderId ( MetadataProviders . Imdb ) ;
var imdbId = searchInfo . GetProviderId ( MetadataProviders . Imdb ) ;
@ -75,7 +77,7 @@ namespace MediaBrowser.Providers.Omdb
name = parsedName . Name ;
name = parsedName . Name ;
year = year ? ? yearInName ;
year = year ? ? yearInName ;
}
}
if ( string . IsNullOrWhiteSpace ( imdbId ) )
if ( string . IsNullOrWhiteSpace ( imdbId ) )
{
{
if ( year . HasValue )
if ( year . HasValue )
@ -83,8 +85,10 @@ namespace MediaBrowser.Providers.Omdb
url + = "&y=" + year . Value . ToString ( CultureInfo . InvariantCulture ) ;
url + = "&y=" + year . Value . ToString ( CultureInfo . InvariantCulture ) ;
}
}
url + = "&t=" + WebUtility . UrlEncode ( name ) ;
// &s means search and returns a list of results as opposed to t
url + = "&s=" + WebUtility . UrlEncode ( name ) ;
url + = "&type=" + type ;
url + = "&type=" + type ;
isSearch = true ;
}
}
else
else
{
{
@ -101,9 +105,23 @@ namespace MediaBrowser.Providers.Omdb
} ) . ConfigureAwait ( false ) )
} ) . ConfigureAwait ( false ) )
{
{
var result = _jsonSerializer . DeserializeFromStream < SearchResult > ( stream ) ;
var result List = new List < SearchResult > ( ) ;
if ( string . Equals ( result . Response , "true" , StringComparison . OrdinalIgnoreCase ) )
if ( isSearch )
{
var searchResultList = _jsonSerializer . DeserializeFromStream < SearchResultList > ( stream ) ;
resultList . AddRange ( searchResultList . Search ) ;
}
else
{
var result = _jsonSerializer . DeserializeFromStream < SearchResult > ( stream ) ;
if ( string . Equals ( result . Response , "true" , StringComparison . OrdinalIgnoreCase ) )
{
resultList . Add ( result ) ;
}
}
foreach ( var result in resultList )
{
{
var item = new RemoteSearchResult ( ) ;
var item = new RemoteSearchResult ( ) ;
@ -264,5 +282,15 @@ namespace MediaBrowser.Providers.Omdb
public string Type { get ; set ; }
public string Type { get ; set ; }
public string Response { get ; set ; }
public string Response { get ; set ; }
}
}
private class SearchResultList
{
/// <summary>
/// Gets or sets the results.
/// </summary>
/// <value>The results.</value>
public List < SearchResult > Search { get ; set ; }
}
}
}
}
}