2020-06-19 18:24:13 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 20:03:10 +00:00
|
|
|
using System.Collections.Generic;
|
2019-01-13 19:26:31 +00:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using MediaBrowser.Common;
|
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;
|
2019-01-13 19:26:31 +00:00
|
|
|
using MediaBrowser.Model.IO;
|
2016-01-10 05:19:19 +00:00
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
using MediaBrowser.Model.Serialization;
|
|
|
|
|
2020-03-09 14:36:02 +00:00
|
|
|
namespace MediaBrowser.Providers.Plugins.Omdb
|
2016-01-10 05:19:19 +00:00
|
|
|
{
|
2020-05-12 20:03:15 +00:00
|
|
|
public class OmdbEpisodeProvider : IRemoteMetadataProvider<Episode, EpisodeInfo>, IHasOrder
|
2016-01-10 05:19:19 +00:00
|
|
|
{
|
|
|
|
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;
|
2018-09-12 17:26:21 +00:00
|
|
|
private readonly IApplicationHost _appHost;
|
2016-01-10 05:19:19 +00:00
|
|
|
|
2020-05-12 20:03:15 +00:00
|
|
|
public OmdbEpisodeProvider(
|
|
|
|
IJsonSerializer jsonSerializer,
|
|
|
|
IApplicationHost appHost,
|
|
|
|
IHttpClient httpClient,
|
|
|
|
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;
|
2018-09-12 17:26:21 +00:00
|
|
|
_appHost = appHost;
|
2020-05-12 20:03:15 +00:00
|
|
|
_itemProvider = new OmdbItemProvider(jsonSerializer, _appHost, httpClient, libraryManager, fileSystem, configurationManager);
|
2016-01-10 05:19:19 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 20:03:15 +00:00
|
|
|
// After TheTvDb
|
|
|
|
public int Order => 1;
|
|
|
|
|
|
|
|
public string Name => "The Open Movie Database";
|
|
|
|
|
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
|
2017-08-13 02:09:07 +00:00
|
|
|
if (info.IsMissingEpisode)
|
2016-04-18 04:25:43 +00:00
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-06 19:17:49 +00:00
|
|
|
if (info.SeriesProviderIds.TryGetValue(MetadataProvider.Imdb.ToString(), out string seriesImdbId) && !string.IsNullOrEmpty(seriesImdbId))
|
2016-01-10 05:19:19 +00:00
|
|
|
{
|
2017-05-03 21:53:33 +00:00
|
|
|
if (info.IndexNumber.HasValue && info.ParentIndexNumber.HasValue)
|
2016-12-23 17:09:50 +00:00
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
result.HasMetadata = await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _appHost, _configurationManager)
|
2020-06-06 19:17:49 +00:00
|
|
|
.FetchEpisodeData(result, info.IndexNumber.Value, info.ParentIndexNumber.Value, info.GetProviderId(MetadataProvider.Imdb), seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
2016-12-23 17:09:50 +00:00
|
|
|
}
|
2016-01-10 05:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
return _itemProvider.GetImageResponse(url, cancellationToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|