more identify fixes

This commit is contained in:
Luke Pulverenti 2016-04-24 20:36:10 -04:00
parent d459b97a21
commit fb3863de7e
3 changed files with 27 additions and 35 deletions

View File

@ -20,6 +20,7 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using CommonIO; using CommonIO;
using MediaBrowser.Model.Serialization;
namespace MediaBrowser.Providers.Manager namespace MediaBrowser.Providers.Manager
{ {
@ -60,6 +61,7 @@ namespace MediaBrowser.Providers.Manager
private IEnumerable<IMetadataSaver> _savers; private IEnumerable<IMetadataSaver> _savers;
private IImageSaver[] _imageSavers; private IImageSaver[] _imageSavers;
private readonly IServerApplicationPaths _appPaths; private readonly IServerApplicationPaths _appPaths;
private readonly IJsonSerializer _json;
private IExternalId[] _externalIds; private IExternalId[] _externalIds;
@ -73,7 +75,7 @@ namespace MediaBrowser.Providers.Manager
/// <param name="libraryMonitor">The directory watchers.</param> /// <param name="libraryMonitor">The directory watchers.</param>
/// <param name="logManager">The log manager.</param> /// <param name="logManager">The log manager.</param>
/// <param name="fileSystem">The file system.</param> /// <param name="fileSystem">The file system.</param>
public ProviderManager(IHttpClient httpClient, IServerConfigurationManager configurationManager, ILibraryMonitor libraryMonitor, ILogManager logManager, IFileSystem fileSystem, IServerApplicationPaths appPaths, Func<ILibraryManager> libraryManagerFactory) public ProviderManager(IHttpClient httpClient, IServerConfigurationManager configurationManager, ILibraryMonitor libraryMonitor, ILogManager logManager, IFileSystem fileSystem, IServerApplicationPaths appPaths, Func<ILibraryManager> libraryManagerFactory, IJsonSerializer json)
{ {
_logger = logManager.GetLogger("ProviderManager"); _logger = logManager.GetLogger("ProviderManager");
_httpClient = httpClient; _httpClient = httpClient;
@ -82,6 +84,7 @@ namespace MediaBrowser.Providers.Manager
_fileSystem = fileSystem; _fileSystem = fileSystem;
_appPaths = appPaths; _appPaths = appPaths;
_libraryManagerFactory = libraryManagerFactory; _libraryManagerFactory = libraryManagerFactory;
_json = json;
} }
/// <summary> /// <summary>
@ -730,8 +733,6 @@ namespace MediaBrowser.Providers.Manager
where TItemType : BaseItem, new() where TItemType : BaseItem, new()
where TLookupType : ItemLookupInfo where TLookupType : ItemLookupInfo
{ {
const int maxResults = 10;
// Give it a dummy path just so that it looks like a file system item // Give it a dummy path just so that it looks like a file system item
var dummy = new TItemType var dummy = new TItemType
{ {
@ -761,7 +762,6 @@ namespace MediaBrowser.Providers.Manager
} }
var resultList = new List<RemoteSearchResult>(); var resultList = new List<RemoteSearchResult>();
var foundProviderIds = new Dictionary<Tuple<string, string>, RemoteSearchResult>();
foreach (var provider in providers) foreach (var provider in providers)
{ {
@ -771,32 +771,27 @@ namespace MediaBrowser.Providers.Manager
foreach (var result in results) 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 if (existingMatch == null)
foreach (var providerId in result.ProviderIds)
{
var idTuple = new Tuple<string, string>(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)
{ {
resultList.Add(result); 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) catch (Exception ex)
@ -805,6 +800,8 @@ namespace MediaBrowser.Providers.Manager
} }
} }
//_logger.Debug("Returning search results {0}", _json.SerializeToString(resultList));
return resultList; return resultList;
} }

View File

@ -64,8 +64,6 @@ namespace MediaBrowser.Providers.Omdb
{ {
var episodeSearchInfo = searchInfo as EpisodeInfo; var episodeSearchInfo = searchInfo as EpisodeInfo;
var list = new List<RemoteSearchResult>();
var imdbId = searchInfo.GetProviderId(MetadataProviders.Imdb); var imdbId = searchInfo.GetProviderId(MetadataProviders.Imdb);
var url = "http://www.omdbapi.com/?plot=full&r=json"; 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 var item = new RemoteSearchResult
{ {
IndexNumber = searchInfo.IndexNumber, IndexNumber = searchInfo.IndexNumber,
Name = result.Title, Name = result.Title,
ParentIndexNumber = searchInfo.ParentIndexNumber, ParentIndexNumber = searchInfo.ParentIndexNumber,
ProviderIds = searchInfo.ProviderIds,
SearchProviderName = Name SearchProviderName = Name
}; };
@ -185,11 +182,9 @@ namespace MediaBrowser.Providers.Omdb
item.ImageUrl = result.Poster; item.ImageUrl = result.Poster;
} }
list.Add(item); return item;
} });
} }
return list;
} }
public Task<MetadataResult<Trailer>> GetMetadata(TrailerInfo info, CancellationToken cancellationToken) public Task<MetadataResult<Trailer>> GetMetadata(TrailerInfo info, CancellationToken cancellationToken)

View File

@ -440,7 +440,7 @@ namespace MediaBrowser.Server.Startup.Common
LibraryMonitor = new LibraryMonitor(LogManager, TaskManager, LibraryManager, ServerConfigurationManager, FileSystemManager, this); LibraryMonitor = new LibraryMonitor(LogManager, TaskManager, LibraryManager, ServerConfigurationManager, FileSystemManager, this);
RegisterSingleInstance(LibraryMonitor); 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); RegisterSingleInstance(ProviderManager);
SeriesOrderManager = new SeriesOrderManager(); SeriesOrderManager = new SeriesOrderManager();