From fb3863de7e0c8868c9175d6a23b96c5382d83abf Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 24 Apr 2016 20:36:10 -0400 Subject: [PATCH] more identify fixes --- .../Manager/ProviderManager.cs | 49 +++++++++---------- .../Omdb/OmdbItemProvider.cs | 11 ++--- .../ApplicationHost.cs | 2 +- 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.cs index 3199ed12b..c95d58a42 100644 --- a/MediaBrowser.Providers/Manager/ProviderManager.cs +++ b/MediaBrowser.Providers/Manager/ProviderManager.cs @@ -20,6 +20,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using CommonIO; +using MediaBrowser.Model.Serialization; namespace MediaBrowser.Providers.Manager { @@ -60,6 +61,7 @@ namespace MediaBrowser.Providers.Manager private IEnumerable _savers; private IImageSaver[] _imageSavers; private readonly IServerApplicationPaths _appPaths; + private readonly IJsonSerializer _json; private IExternalId[] _externalIds; @@ -73,7 +75,7 @@ namespace MediaBrowser.Providers.Manager /// The directory watchers. /// The log manager. /// The file system. - public ProviderManager(IHttpClient httpClient, IServerConfigurationManager configurationManager, ILibraryMonitor libraryMonitor, ILogManager logManager, IFileSystem fileSystem, IServerApplicationPaths appPaths, Func libraryManagerFactory) + public ProviderManager(IHttpClient httpClient, IServerConfigurationManager configurationManager, ILibraryMonitor libraryMonitor, ILogManager logManager, IFileSystem fileSystem, IServerApplicationPaths appPaths, Func libraryManagerFactory, IJsonSerializer json) { _logger = logManager.GetLogger("ProviderManager"); _httpClient = httpClient; @@ -82,6 +84,7 @@ namespace MediaBrowser.Providers.Manager _fileSystem = fileSystem; _appPaths = appPaths; _libraryManagerFactory = libraryManagerFactory; + _json = json; } /// @@ -730,8 +733,6 @@ namespace MediaBrowser.Providers.Manager where TItemType : BaseItem, new() where TLookupType : ItemLookupInfo { - const int maxResults = 10; - // Give it a dummy path just so that it looks like a file system item var dummy = new TItemType { @@ -761,7 +762,6 @@ namespace MediaBrowser.Providers.Manager } var resultList = new List(); - var foundProviderIds = new Dictionary, RemoteSearchResult>(); foreach (var provider in providers) { @@ -771,32 +771,27 @@ namespace MediaBrowser.Providers.Manager foreach (var result in results) { - var bFound = false; + var existingMatch = resultList.FirstOrDefault(i => i.ProviderIds.Any(p => string.Equals(result.GetProviderId(p.Key), p.Value, StringComparison.OrdinalIgnoreCase))); - // This check prevents duplicate search results by comparing provider ids - foreach (var providerId in result.ProviderIds) - { - var idTuple = new Tuple(providerId.Key.ToLower(), providerId.Value.ToLower()); - - if (!foundProviderIds.ContainsKey(idTuple)) - { - foundProviderIds.Add(idTuple, result); - } - else - { - bFound = true; - var existingResult = foundProviderIds[idTuple]; - if (string.IsNullOrEmpty(existingResult.ImageUrl) && !string.IsNullOrEmpty(result.ImageUrl)) - { - existingResult.ImageUrl = result.ImageUrl; - } - } - } - - if (!bFound && resultList.Count < maxResults) + if (existingMatch == null) { resultList.Add(result); } + else + { + foreach (var providerId in result.ProviderIds) + { + if (!existingMatch.ProviderIds.ContainsKey(providerId.Key)) + { + existingMatch.ProviderIds.Add(providerId.Key, providerId.Value); + } + } + + if (string.IsNullOrWhiteSpace(existingMatch.ImageUrl)) + { + existingMatch.ImageUrl = result.ImageUrl; + } + } } } catch (Exception ex) @@ -805,6 +800,8 @@ namespace MediaBrowser.Providers.Manager } } + //_logger.Debug("Returning search results {0}", _json.SerializeToString(resultList)); + return resultList; } diff --git a/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs b/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs index 1b8ecd521..8acaf30d5 100644 --- a/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs +++ b/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs @@ -64,8 +64,6 @@ namespace MediaBrowser.Providers.Omdb { var episodeSearchInfo = searchInfo as EpisodeInfo; - var list = new List(); - var imdbId = searchInfo.GetProviderId(MetadataProviders.Imdb); var url = "http://www.omdbapi.com/?plot=full&r=json"; @@ -148,14 +146,13 @@ namespace MediaBrowser.Providers.Omdb } } - foreach (var result in resultList) + return resultList.Select(result => { var item = new RemoteSearchResult { IndexNumber = searchInfo.IndexNumber, Name = result.Title, ParentIndexNumber = searchInfo.ParentIndexNumber, - ProviderIds = searchInfo.ProviderIds, SearchProviderName = Name }; @@ -185,11 +182,9 @@ namespace MediaBrowser.Providers.Omdb item.ImageUrl = result.Poster; } - list.Add(item); - } + return item; + }); } - - return list; } public Task> GetMetadata(TrailerInfo info, CancellationToken cancellationToken) diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index 93dbe2945..b371ac751 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -440,7 +440,7 @@ namespace MediaBrowser.Server.Startup.Common LibraryMonitor = new LibraryMonitor(LogManager, TaskManager, LibraryManager, ServerConfigurationManager, FileSystemManager, this); RegisterSingleInstance(LibraryMonitor); - ProviderManager = new ProviderManager(HttpClient, ServerConfigurationManager, LibraryMonitor, LogManager, FileSystemManager, ApplicationPaths, () => LibraryManager); + ProviderManager = new ProviderManager(HttpClient, ServerConfigurationManager, LibraryMonitor, LogManager, FileSystemManager, ApplicationPaths, () => LibraryManager, JsonSerializer); RegisterSingleInstance(ProviderManager); SeriesOrderManager = new SeriesOrderManager();