2014-02-03 20:51:28 +00:00
|
|
|
|
using MediaBrowser.Common.Net;
|
2014-02-04 20:19:29 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
2014-02-03 20:51:28 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-02-15 16:36:09 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
2014-02-20 04:53:15 +00:00
|
|
|
|
using MediaBrowser.Model.Providers;
|
2014-02-03 20:51:28 +00:00
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2014-02-15 16:36:09 +00:00
|
|
|
|
using MediaBrowser.Providers.Movies;
|
|
|
|
|
using MediaBrowser.Providers.TV;
|
|
|
|
|
using System;
|
2014-02-20 04:53:15 +00:00
|
|
|
|
using System.Collections.Generic;
|
2014-02-03 20:51:28 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.Omdb
|
|
|
|
|
{
|
2014-02-15 16:36:09 +00:00
|
|
|
|
public class OmdbItemProvider : IRemoteMetadataProvider<Series, SeriesInfo>,
|
|
|
|
|
IRemoteMetadataProvider<Movie, MovieInfo>, IRemoteMetadataProvider<Trailer, TrailerInfo>
|
2014-02-03 20:51:28 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly IJsonSerializer _jsonSerializer;
|
|
|
|
|
private readonly IHttpClient _httpClient;
|
2014-02-15 16:36:09 +00:00
|
|
|
|
private readonly ILogger _logger;
|
2014-02-03 20:51:28 +00:00
|
|
|
|
|
2014-02-15 16:36:09 +00:00
|
|
|
|
public OmdbItemProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogger logger)
|
2014-02-03 20:51:28 +00:00
|
|
|
|
{
|
|
|
|
|
_jsonSerializer = jsonSerializer;
|
|
|
|
|
_httpClient = httpClient;
|
2014-02-15 16:36:09 +00:00
|
|
|
|
_logger = logger;
|
2014-02-03 20:51:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 04:53:15 +00:00
|
|
|
|
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return new List<RemoteSearchResult>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(TrailerInfo searchInfo, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return new List<RemoteSearchResult>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return new List<RemoteSearchResult>();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 20:19:29 +00:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
2014-02-20 21:10:26 +00:00
|
|
|
|
get { return "The Open Movie Database"; }
|
2014-02-04 20:19:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-15 16:36:09 +00:00
|
|
|
|
public async Task<MetadataResult<Series>> GetMetadata(SeriesInfo info, CancellationToken cancellationToken)
|
2014-02-03 20:51:28 +00:00
|
|
|
|
{
|
2014-02-15 16:36:09 +00:00
|
|
|
|
var result = new MetadataResult<Series>
|
|
|
|
|
{
|
|
|
|
|
Item = new Series()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var imdbId = info.GetProviderId(MetadataProviders.Imdb);
|
|
|
|
|
|
2014-02-24 03:27:13 +00:00
|
|
|
|
var searchResult = await GetSeriesImdbId(info, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
result.Item.Name = searchResult.Item3;
|
|
|
|
|
|
2014-02-15 16:36:09 +00:00
|
|
|
|
if (string.IsNullOrEmpty(imdbId))
|
|
|
|
|
{
|
|
|
|
|
imdbId = searchResult.Item1;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(searchResult.Item2))
|
|
|
|
|
{
|
|
|
|
|
result.Item.SetProviderId(MetadataProviders.Tvdb, searchResult.Item2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(imdbId))
|
|
|
|
|
{
|
|
|
|
|
result.Item.SetProviderId(MetadataProviders.Imdb, imdbId);
|
|
|
|
|
result.HasMetadata = true;
|
|
|
|
|
|
|
|
|
|
await new OmdbProvider(_jsonSerializer, _httpClient).Fetch(result.Item, imdbId, cancellationToken)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2014-02-03 20:51:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-15 16:36:09 +00:00
|
|
|
|
public Task<MetadataResult<Movie>> GetMetadata(MovieInfo info, CancellationToken cancellationToken)
|
2014-02-03 20:51:28 +00:00
|
|
|
|
{
|
2014-02-15 16:36:09 +00:00
|
|
|
|
return GetMovieResult<Movie>(info, cancellationToken);
|
2014-02-04 20:19:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-15 16:36:09 +00:00
|
|
|
|
public Task<MetadataResult<Trailer>> GetMetadata(TrailerInfo info, CancellationToken cancellationToken)
|
2014-02-04 20:19:29 +00:00
|
|
|
|
{
|
2014-02-15 16:36:09 +00:00
|
|
|
|
var result = new MetadataResult<Trailer>();
|
|
|
|
|
|
|
|
|
|
if (info.IsLocalTrailer)
|
2014-02-04 20:19:29 +00:00
|
|
|
|
{
|
2014-02-15 16:36:09 +00:00
|
|
|
|
return Task.FromResult(result);
|
2014-02-04 20:19:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-15 16:36:09 +00:00
|
|
|
|
return GetMovieResult<Trailer>(info, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<MetadataResult<T>> GetMovieResult<T>(ItemLookupInfo info, CancellationToken cancellationToken)
|
|
|
|
|
where T : Video, new()
|
|
|
|
|
{
|
|
|
|
|
var result = new MetadataResult<T>
|
|
|
|
|
{
|
|
|
|
|
Item = new T()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var imdbId = info.GetProviderId(MetadataProviders.Imdb);
|
|
|
|
|
|
2014-02-24 03:27:13 +00:00
|
|
|
|
var searchResult = await GetMovieImdbId(info, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
result.Item.Name = searchResult.Item3;
|
|
|
|
|
|
2014-02-15 16:36:09 +00:00
|
|
|
|
if (string.IsNullOrEmpty(imdbId))
|
|
|
|
|
{
|
|
|
|
|
imdbId = searchResult.Item1;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(searchResult.Item2))
|
|
|
|
|
{
|
|
|
|
|
result.Item.SetProviderId(MetadataProviders.Tmdb, searchResult.Item2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(imdbId))
|
|
|
|
|
{
|
|
|
|
|
result.Item.SetProviderId(MetadataProviders.Imdb, imdbId);
|
|
|
|
|
result.HasMetadata = true;
|
|
|
|
|
|
|
|
|
|
await new OmdbProvider(_jsonSerializer, _httpClient).Fetch(result.Item, imdbId, cancellationToken)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-22 21:05:00 +00:00
|
|
|
|
private async Task<Tuple<string, string, string>> GetMovieImdbId(ItemLookupInfo info, CancellationToken cancellationToken)
|
2014-02-15 16:36:09 +00:00
|
|
|
|
{
|
|
|
|
|
var result = await new GenericMovieDbInfo<Movie>(_logger, _jsonSerializer).GetMetadata(info, cancellationToken)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
var imdb = result.HasMetadata ? result.Item.GetProviderId(MetadataProviders.Imdb) : null;
|
|
|
|
|
var tmdb = result.HasMetadata ? result.Item.GetProviderId(MetadataProviders.Tmdb) : null;
|
2014-02-22 21:05:00 +00:00
|
|
|
|
var name = result.HasMetadata ? result.Item.Name : null;
|
2014-02-15 16:36:09 +00:00
|
|
|
|
|
2014-02-22 21:05:00 +00:00
|
|
|
|
return new Tuple<string, string, string>(imdb, tmdb, name);
|
2014-02-15 16:36:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-22 21:05:00 +00:00
|
|
|
|
private async Task<Tuple<string, string, string>> GetSeriesImdbId(SeriesInfo info, CancellationToken cancellationToken)
|
2014-02-15 16:36:09 +00:00
|
|
|
|
{
|
|
|
|
|
var result = await TvdbSeriesProvider.Current.GetMetadata(info, cancellationToken)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
var imdb = result.HasMetadata ? result.Item.GetProviderId(MetadataProviders.Imdb) : null;
|
|
|
|
|
var tvdb = result.HasMetadata ? result.Item.GetProviderId(MetadataProviders.Tvdb) : null;
|
2014-02-22 21:05:00 +00:00
|
|
|
|
var name = result.HasMetadata ? result.Item.Name : null;
|
2014-02-15 16:36:09 +00:00
|
|
|
|
|
2014-02-22 21:05:00 +00:00
|
|
|
|
return new Tuple<string, string, string>(imdb, tvdb, name);
|
2014-02-03 20:51:28 +00:00
|
|
|
|
}
|
2014-02-20 04:53:15 +00:00
|
|
|
|
|
|
|
|
|
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
2014-02-03 20:51:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|