2016-10-25 19:02:04 +00:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2016-06-04 00:23:44 +00:00
|
|
|
|
using MediaBrowser.Common.Net;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2016-01-10 05:19:19 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
|
using MediaBrowser.Model.Serialization;
|
|
|
|
|
using MediaBrowser.Providers.Omdb;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-10-25 19:02:04 +00:00
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Controller.IO;
|
2016-01-10 05:19:19 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.TV
|
|
|
|
|
{
|
|
|
|
|
class OmdbEpisodeProvider :
|
|
|
|
|
IRemoteMetadataProvider<Episode, EpisodeInfo>,
|
|
|
|
|
IHasOrder
|
|
|
|
|
{
|
|
|
|
|
private readonly IJsonSerializer _jsonSerializer;
|
|
|
|
|
private readonly IHttpClient _httpClient;
|
2016-04-18 04:25:43 +00:00
|
|
|
|
private readonly OmdbItemProvider _itemProvider;
|
2016-06-04 00:23:44 +00:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
|
private readonly IServerConfigurationManager _configurationManager;
|
2016-01-10 05:19:19 +00:00
|
|
|
|
|
2016-06-04 00:23:44 +00:00
|
|
|
|
public OmdbEpisodeProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogger logger, ILibraryManager libraryManager, IFileSystem fileSystem, IServerConfigurationManager configurationManager)
|
2016-01-10 05:19:19 +00:00
|
|
|
|
{
|
|
|
|
|
_jsonSerializer = jsonSerializer;
|
|
|
|
|
_httpClient = httpClient;
|
2016-06-04 00:23:44 +00:00
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
|
_configurationManager = configurationManager;
|
|
|
|
|
_itemProvider = new OmdbItemProvider(jsonSerializer, httpClient, logger, libraryManager, fileSystem, configurationManager);
|
2016-01-10 05:19:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(EpisodeInfo searchInfo, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return _itemProvider.GetSearchResults(searchInfo, "episode", cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo info, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2016-06-23 01:27:25 +00:00
|
|
|
|
var result = new MetadataResult<Episode>()
|
2016-01-10 05:19:19 +00:00
|
|
|
|
{
|
2016-09-18 04:27:17 +00:00
|
|
|
|
Item = new Episode(),
|
|
|
|
|
QueriedById = true
|
2016-01-10 05:19:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-04-18 04:25:43 +00:00
|
|
|
|
// Allowing this will dramatically increase scan times
|
|
|
|
|
if (info.IsMissingEpisode || info.IsVirtualUnaired)
|
|
|
|
|
{
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-23 17:09:50 +00:00
|
|
|
|
string seriesImdbId;
|
|
|
|
|
if (info.SeriesProviderIds.TryGetValue(MetadataProviders.Imdb.ToString(), out seriesImdbId) && !string.IsNullOrEmpty(seriesImdbId))
|
2016-01-10 05:19:19 +00:00
|
|
|
|
{
|
2016-12-23 17:09:50 +00:00
|
|
|
|
if (info.IndexNumber.HasValue &&
|
|
|
|
|
info.ParentIndexNumber.HasValue)
|
|
|
|
|
{
|
|
|
|
|
result.HasMetadata = await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _configurationManager)
|
|
|
|
|
.FetchEpisodeData(result, info.IndexNumber.Value, info.ParentIndexNumber.Value, seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
2016-01-10 05:19:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Order
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// After TheTvDb
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "The Open Movie Database"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return _itemProvider.GetImageResponse(url, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|