From 8a99144df709513d3d5f1f4f8e69ac581b20f784 Mon Sep 17 00:00:00 2001 From: softworkz Date: Thu, 1 Oct 2015 03:43:41 +0200 Subject: [PATCH] OmdbItemProvider: Use search instead of title API In my configuration, the Omdb provider is the first in the list for movie metadata. This was the default at the time I installed MB and I never changed that (don't know what the current defaults are for a new installation). When I use the identify command for movies in the metadata editor, I always get a single result only. This is due to the fact that the Omdb provider used the title API with "t=moviename", while there is also a search api with "s=moviename" which will return multiple results. This commit modifies the OmdbItemProvider to use the search API variant and enable returning multiple results --- .../Omdb/OmdbItemProvider.cs | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs b/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs index 36e7697d77..f8763b8470 100644 --- a/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs +++ b/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs @@ -59,6 +59,8 @@ namespace MediaBrowser.Providers.Omdb public async Task> GetSearchResults(ItemLookupInfo searchInfo, string type, CancellationToken cancellationToken) { + bool isSearch = false; + var list = new List(); var imdbId = searchInfo.GetProviderId(MetadataProviders.Imdb); @@ -75,7 +77,7 @@ namespace MediaBrowser.Providers.Omdb name = parsedName.Name; year = year ?? yearInName; } - + if (string.IsNullOrWhiteSpace(imdbId)) { if (year.HasValue) @@ -83,8 +85,10 @@ namespace MediaBrowser.Providers.Omdb 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; + isSearch = true; } else { @@ -101,9 +105,23 @@ namespace MediaBrowser.Providers.Omdb }).ConfigureAwait(false)) { - var result = _jsonSerializer.DeserializeFromStream(stream); + var resultList = new List(); - if (string.Equals(result.Response, "true", StringComparison.OrdinalIgnoreCase)) + if (isSearch) + { + var searchResultList = _jsonSerializer.DeserializeFromStream(stream); + resultList.AddRange(searchResultList.Search); + } + else + { + var result = _jsonSerializer.DeserializeFromStream(stream); + if (string.Equals(result.Response, "true", StringComparison.OrdinalIgnoreCase)) + { + resultList.Add(result); + } + } + + foreach (var result in resultList) { var item = new RemoteSearchResult(); @@ -264,5 +282,15 @@ namespace MediaBrowser.Providers.Omdb public string Type { get; set; } public string Response { get; set; } } + + private class SearchResultList + { + /// + /// Gets or sets the results. + /// + /// The results. + public List Search { get; set; } + } + } }