support more search filters

This commit is contained in:
Luke Pulverenti 2014-03-02 12:09:35 -05:00
parent e1387a24c1
commit 771294e756
7 changed files with 105 additions and 70 deletions

View file

@ -22,7 +22,6 @@ namespace MediaBrowser.Providers.BoxSets
{ {
public class MovieDbBoxSetProvider : IRemoteMetadataProvider<BoxSet, BoxSetInfo> public class MovieDbBoxSetProvider : IRemoteMetadataProvider<BoxSet, BoxSetInfo>
{ {
private readonly CultureInfo _enUs = new CultureInfo("en-US");
private const string GetCollectionInfo3 = @"http://api.themoviedb.org/3/collection/{0}?api_key={1}&append_to_response=images"; private const string GetCollectionInfo3 = @"http://api.themoviedb.org/3/collection/{0}?api_key={1}&append_to_response=images";
internal static MovieDbBoxSetProvider Current; internal static MovieDbBoxSetProvider Current;
@ -78,25 +77,7 @@ namespace MediaBrowser.Providers.BoxSets
return new[] { result }; return new[] { result };
} }
var results = await new MovieDbSearch(_logger, _json).GetSearchResults(searchInfo, cancellationToken).ConfigureAwait(false); return await new MovieDbSearch(_logger, _json).GetSearchResults(searchInfo, cancellationToken).ConfigureAwait(false);
return results.Select(i => GetRemoteSearchResult(i, tmdbImageUrl));
}
private RemoteSearchResult GetRemoteSearchResult(MovieDbSearch.TmdbMovieSearchResult tmdbResult, string baseImageUrl)
{
var result = new RemoteSearchResult
{
Name = tmdbResult.name,
SearchProviderName = Name,
ImageUrl = string.IsNullOrEmpty(tmdbResult.poster_path) ? null : (baseImageUrl + tmdbResult.poster_path)
};
result.SetProviderId(MetadataProviders.Tmdb, tmdbResult.id.ToString(_usCulture));
return result;
} }
public async Task<MetadataResult<BoxSet>> GetMetadata(BoxSetInfo id, CancellationToken cancellationToken) public async Task<MetadataResult<BoxSet>> GetMetadata(BoxSetInfo id, CancellationToken cancellationToken)
@ -112,7 +93,7 @@ namespace MediaBrowser.Providers.BoxSets
if (searchResult != null) if (searchResult != null)
{ {
tmdbId = searchResult.id.ToString(_enUs); tmdbId = searchResult.GetProviderId(MetadataProviders.Tmdb);
} }
} }
@ -159,7 +140,7 @@ namespace MediaBrowser.Providers.BoxSets
Overview = obj.overview Overview = obj.overview
}; };
item.SetProviderId(MetadataProviders.Tmdb, obj.id.ToString(_enUs)); item.SetProviderId(MetadataProviders.Tmdb, obj.id.ToString(_usCulture));
return item; return item;
} }

View file

@ -45,7 +45,7 @@ namespace MediaBrowser.Providers.Movies
if (searchResult != null) if (searchResult != null)
{ {
tmdbId = searchResult.id.ToString(_usCulture); tmdbId = searchResult.GetProviderId(MetadataProviders.Tmdb);
} }
} }

View file

@ -12,6 +12,7 @@ using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
@ -35,6 +36,8 @@ namespace MediaBrowser.Providers.Movies
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly ILocalizationManager _localization; private readonly ILocalizationManager _localization;
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
public MovieDbProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILogger logger, ILocalizationManager localization) public MovieDbProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILogger logger, ILocalizationManager localization)
{ {
_jsonSerializer = jsonSerializer; _jsonSerializer = jsonSerializer;
@ -46,9 +49,47 @@ namespace MediaBrowser.Providers.Movies
Current = this; Current = this;
} }
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken) public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken)
{ {
return new List<RemoteSearchResult>(); return GetMovieSearchResults(searchInfo, cancellationToken);
}
public async Task<IEnumerable<RemoteSearchResult>> GetMovieSearchResults(ItemLookupInfo searchInfo, CancellationToken cancellationToken)
{
var tmdbSettings = await GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.base_url + "original";
var tmdbId = searchInfo.GetProviderId(MetadataProviders.Tmdb);
if (!string.IsNullOrEmpty(tmdbId))
{
cancellationToken.ThrowIfCancellationRequested();
await EnsureMovieInfo(tmdbId, searchInfo.MetadataLanguage, cancellationToken).ConfigureAwait(false);
var dataFilePath = GetDataFilePath(tmdbId, searchInfo.MetadataLanguage);
var obj = _jsonSerializer.DeserializeFromFile<CompleteMovieData>(dataFilePath);
var remoteResult = new RemoteSearchResult
{
Name = obj.title ?? obj.original_title ?? obj.name,
SearchProviderName = Name,
ImageUrl = string.IsNullOrWhiteSpace(obj.poster_path) ? null : tmdbImageUrl + obj.poster_path
};
remoteResult.SetProviderId(MetadataProviders.Tmdb, obj.id.ToString(_usCulture));
if (!string.IsNullOrWhiteSpace(obj.imdb_id))
{
remoteResult.SetProviderId(MetadataProviders.Imdb, obj.imdb_id);
}
return new[] { remoteResult };
}
return await new MovieDbSearch(_logger, _jsonSerializer).GetMovieSearchResults(searchInfo, cancellationToken).ConfigureAwait(false);
} }
public Task<MetadataResult<Movie>> GetMetadata(MovieInfo info, CancellationToken cancellationToken) public Task<MetadataResult<Movie>> GetMetadata(MovieInfo info, CancellationToken cancellationToken)
@ -57,7 +98,7 @@ namespace MediaBrowser.Providers.Movies
} }
public Task<MetadataResult<T>> GetItemMetadata<T>(ItemLookupInfo id, CancellationToken cancellationToken) public Task<MetadataResult<T>> GetItemMetadata<T>(ItemLookupInfo id, CancellationToken cancellationToken)
where T : Video, new () where T : Video, new()
{ {
var movieDb = new GenericMovieDbInfo<T>(_logger, _jsonSerializer); var movieDb = new GenericMovieDbInfo<T>(_logger, _jsonSerializer);

View file

@ -1,6 +1,8 @@
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -29,27 +31,31 @@ namespace MediaBrowser.Providers.Movies
_json = json; _json = json;
} }
public Task<IEnumerable<TmdbMovieSearchResult>> GetSearchResults(SeriesInfo idInfo, CancellationToken cancellationToken) public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo idInfo, CancellationToken cancellationToken)
{ {
return GetSearchResults(idInfo, "tv", cancellationToken); return GetSearchResults(idInfo, "tv", cancellationToken);
} }
public Task<IEnumerable<TmdbMovieSearchResult>> GetMovieSearchResults(ItemLookupInfo idInfo, CancellationToken cancellationToken) public Task<IEnumerable<RemoteSearchResult>> GetMovieSearchResults(ItemLookupInfo idInfo, CancellationToken cancellationToken)
{ {
return GetSearchResults(idInfo, "movie", cancellationToken); return GetSearchResults(idInfo, "movie", cancellationToken);
} }
public Task<IEnumerable<TmdbMovieSearchResult>> GetSearchResults(BoxSetInfo idInfo, CancellationToken cancellationToken) public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(BoxSetInfo idInfo, CancellationToken cancellationToken)
{ {
return GetSearchResults(idInfo, "collection", cancellationToken); return GetSearchResults(idInfo, "collection", cancellationToken);
} }
private async Task<IEnumerable<TmdbMovieSearchResult>> GetSearchResults(ItemLookupInfo idInfo, string searchType, CancellationToken cancellationToken) private async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ItemLookupInfo idInfo, string searchType, CancellationToken cancellationToken)
{ {
var name = idInfo.Name; var name = idInfo.Name;
var year = idInfo.Year; var year = idInfo.Year;
int? yearInName = null; int? yearInName = null;
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.base_url + "original";
NameParser.ParseName(name, out name, out yearInName); NameParser.ParseName(name, out name, out yearInName);
year = year ?? yearInName; year = year ?? yearInName;
@ -60,14 +66,14 @@ namespace MediaBrowser.Providers.Movies
//nope - search for it //nope - search for it
//var searchType = item is BoxSet ? "collection" : "movie"; //var searchType = item is BoxSet ? "collection" : "movie";
var results = await GetSearchResults(name, searchType, year, language, cancellationToken).ConfigureAwait(false); var results = await GetSearchResults(name, searchType, year, language, tmdbImageUrl, cancellationToken).ConfigureAwait(false);
if (results.Count == 0) if (results.Count == 0)
{ {
//try in english if wasn't before //try in english if wasn't before
if (!string.Equals(language, "en", StringComparison.OrdinalIgnoreCase)) if (!string.Equals(language, "en", StringComparison.OrdinalIgnoreCase))
{ {
results = await GetSearchResults(name, searchType, year, "en", cancellationToken).ConfigureAwait(false); results = await GetSearchResults(name, searchType, year, "en", tmdbImageUrl, cancellationToken).ConfigureAwait(false);
} }
} }
@ -88,21 +94,29 @@ namespace MediaBrowser.Providers.Movies
// Search again if the new name is different // Search again if the new name is different
if (!string.Equals(name, originalName)) if (!string.Equals(name, originalName))
{ {
results = await GetSearchResults(name, searchType, year, language, cancellationToken).ConfigureAwait(false); results = await GetSearchResults(name, searchType, year, language, tmdbImageUrl, cancellationToken).ConfigureAwait(false);
if (results.Count == 0 && !string.Equals(language, "en", StringComparison.OrdinalIgnoreCase)) if (results.Count == 0 && !string.Equals(language, "en", StringComparison.OrdinalIgnoreCase))
{ {
//one more time, in english //one more time, in english
results = await GetSearchResults(name, searchType, year, "en", cancellationToken).ConfigureAwait(false); results = await GetSearchResults(name, searchType, year, "en", tmdbImageUrl, cancellationToken).ConfigureAwait(false);
} }
} }
} }
return results; return results.Where(i =>
{
if (year.HasValue && i.ProductionYear.HasValue)
{
return year.Value == i.ProductionYear.Value;
} }
private async Task<List<TmdbMovieSearchResult>> GetSearchResults(string name, string type, int? year, string language, CancellationToken cancellationToken) return true;
});
}
private async Task<List<RemoteSearchResult>> GetSearchResults(string name, string type, int? year, string language, string baseImageUrl, CancellationToken cancellationToken)
{ {
var url3 = string.Format(Search3, WebUtility.UrlEncode(name), ApiKey, language, type); var url3 = string.Format(Search3, WebUtility.UrlEncode(name), ApiKey, language, type);
@ -124,6 +138,32 @@ namespace MediaBrowser.Providers.Movies
return resultTuples.OrderBy(i => GetSearchResultOrder(i.Item1, year)) return resultTuples.OrderBy(i => GetSearchResultOrder(i.Item1, year))
.ThenBy(i => i.Item2) .ThenBy(i => i.Item2)
.Select(i => i.Item1) .Select(i => i.Item1)
.Select(i =>
{
var remoteResult = new RemoteSearchResult
{
SearchProviderName = MovieDbProvider.Current.Name,
Name = i.title ?? i.original_title ?? i.name,
ImageUrl = string.IsNullOrWhiteSpace(i.poster_path) ? null : baseImageUrl + i.poster_path
};
if (!string.IsNullOrWhiteSpace(i.release_date))
{
DateTime r;
// These dates are always in this exact format
if (DateTime.TryParseExact(i.release_date, "yyyy-MM-dd", EnUs, DateTimeStyles.None, out r))
{
remoteResult.PremiereDate = r.ToUniversalTime();
remoteResult.ProductionYear = remoteResult.PremiereDate.Value.Year;
}
}
remoteResult.SetProviderId(MetadataProviders.Tmdb, i.id.ToString(EnUs));
return remoteResult;
})
.ToList(); .ToList();
} }
} }

View file

@ -23,9 +23,9 @@ namespace MediaBrowser.Providers.Movies
return MovieDbProvider.Current.GetItemMetadata<Trailer>(info, cancellationToken); return MovieDbProvider.Current.GetItemMetadata<Trailer>(info, cancellationToken);
} }
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(TrailerInfo searchInfo, CancellationToken cancellationToken) public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(TrailerInfo searchInfo, CancellationToken cancellationToken)
{ {
return new List<RemoteSearchResult>(); return MovieDbProvider.Current.GetMovieSearchResults(searchInfo, cancellationToken);
} }
public string Name public string Name

View file

@ -4,7 +4,6 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Localization; using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
@ -130,32 +129,7 @@ namespace MediaBrowser.Providers.TV
} }
} }
var searchResults = await new MovieDbSearch(_logger, _jsonSerializer).GetSearchResults(searchInfo, cancellationToken).ConfigureAwait(false); return await new MovieDbSearch(_logger, _jsonSerializer).GetSearchResults(searchInfo, cancellationToken).ConfigureAwait(false);
return searchResults.Select(i =>
{
var remoteResult = new RemoteSearchResult
{
SearchProviderName = Name,
Name = i.name,
ImageUrl = string.IsNullOrWhiteSpace(i.poster_path) ? null : tmdbImageUrl + i.poster_path
};
if (!string.IsNullOrWhiteSpace(i.release_date))
{
DateTime r;
// These dates are always in this exact format
if (DateTime.TryParseExact(i.release_date, "yyyy-MM-dd", _usCulture, DateTimeStyles.None, out r))
{
remoteResult.PremiereDate = r.ToUniversalTime();
}
}
remoteResult.SetProviderId(MetadataProviders.Tmdb, i.id.ToString(_usCulture));
return remoteResult;
});
} }
public async Task<MetadataResult<Series>> GetMetadata(SeriesInfo info, CancellationToken cancellationToken) public async Task<MetadataResult<Series>> GetMetadata(SeriesInfo info, CancellationToken cancellationToken)
@ -202,7 +176,7 @@ namespace MediaBrowser.Providers.TV
if (searchResult != null) if (searchResult != null)
{ {
tmdbId = searchResult.id.ToString(_usCulture); tmdbId = searchResult.GetProviderId(MetadataProviders.Tmdb);
} }
} }

View file

@ -7,7 +7,6 @@ using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Sorting; using MediaBrowser.Controller.Sorting;
@ -49,7 +48,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
private List<Guid> _channelIdList = new List<Guid>(); private List<Guid> _channelIdList = new List<Guid>();
private Dictionary<Guid, LiveTvProgram> _programs = new Dictionary<Guid, LiveTvProgram>(); private Dictionary<Guid, LiveTvProgram> _programs = new Dictionary<Guid, LiveTvProgram>();
private SemaphoreSlim _refreshSemaphore = new SemaphoreSlim(1, 1); private readonly SemaphoreSlim _refreshSemaphore = new SemaphoreSlim(1, 1);
public LiveTvManager(IServerConfigurationManager config, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager, ILibraryManager libraryManager, ITaskManager taskManager) public LiveTvManager(IServerConfigurationManager config, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager, ILibraryManager libraryManager, ITaskManager taskManager)
{ {