2020-06-19 11:24:13 -07:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 13:03:10 -07:00
|
|
|
using System.Collections.Generic;
|
2020-08-17 12:10:02 -07:00
|
|
|
using System.Net.Http;
|
2019-01-13 12:26:31 -07:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2016-06-03 17:23:44 -07:00
|
|
|
using MediaBrowser.Controller.Configuration;
|
2016-01-09 22:19:19 -07:00
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
2019-01-13 12:26:31 -07:00
|
|
|
using MediaBrowser.Model.IO;
|
2016-01-09 22:19:19 -07:00
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
|
2020-03-09 07:36:02 -07:00
|
|
|
namespace MediaBrowser.Providers.Plugins.Omdb
|
2016-01-09 22:19:19 -07:00
|
|
|
{
|
2020-05-12 13:03:15 -07:00
|
|
|
public class OmdbEpisodeProvider : IRemoteMetadataProvider<Episode, EpisodeInfo>, IHasOrder
|
2016-01-09 22:19:19 -07:00
|
|
|
{
|
2016-04-17 21:25:43 -07:00
|
|
|
private readonly OmdbItemProvider _itemProvider;
|
2021-11-19 07:32:07 -07:00
|
|
|
private readonly OmdbProvider _omdbProvider;
|
2016-01-09 22:19:19 -07:00
|
|
|
|
2020-05-12 13:03:15 -07:00
|
|
|
public OmdbEpisodeProvider(
|
2020-08-17 12:10:02 -07:00
|
|
|
IHttpClientFactory httpClientFactory,
|
2020-05-12 13:03:15 -07:00
|
|
|
ILibraryManager libraryManager,
|
|
|
|
IFileSystem fileSystem,
|
|
|
|
IServerConfigurationManager configurationManager)
|
2016-01-09 22:19:19 -07:00
|
|
|
{
|
2021-11-19 07:32:07 -07:00
|
|
|
_itemProvider = new OmdbItemProvider(httpClientFactory, libraryManager, fileSystem, configurationManager);
|
|
|
|
_omdbProvider = new OmdbProvider(httpClientFactory, fileSystem, configurationManager);
|
2016-01-09 22:19:19 -07:00
|
|
|
}
|
|
|
|
|
2020-05-12 13:03:15 -07:00
|
|
|
// After TheTvDb
|
|
|
|
public int Order => 1;
|
|
|
|
|
|
|
|
public string Name => "The Open Movie Database";
|
|
|
|
|
2016-01-09 22:19:19 -07:00
|
|
|
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(EpisodeInfo searchInfo, CancellationToken cancellationToken)
|
|
|
|
{
|
2021-11-19 07:32:07 -07:00
|
|
|
return _itemProvider.GetSearchResults(searchInfo, cancellationToken);
|
2016-01-09 22:19:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo info, CancellationToken cancellationToken)
|
|
|
|
{
|
2021-11-19 07:32:07 -07:00
|
|
|
var result = new MetadataResult<Episode>
|
2016-01-09 22:19:19 -07:00
|
|
|
{
|
2016-09-17 21:27:17 -07:00
|
|
|
Item = new Episode(),
|
|
|
|
QueriedById = true
|
2016-01-09 22:19:19 -07:00
|
|
|
};
|
|
|
|
|
2016-04-17 21:25:43 -07:00
|
|
|
// Allowing this will dramatically increase scan times
|
2017-08-12 19:09:07 -07:00
|
|
|
if (info.IsMissingEpisode)
|
2016-04-17 21:25:43 -07:00
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-11-19 07:32:07 -07:00
|
|
|
if (info.SeriesProviderIds.TryGetValue(MetadataProvider.Imdb.ToString(), out string? seriesImdbId)
|
|
|
|
&& !string.IsNullOrEmpty(seriesImdbId)
|
|
|
|
&& info.IndexNumber.HasValue
|
|
|
|
&& info.ParentIndexNumber.HasValue)
|
2016-01-09 22:19:19 -07:00
|
|
|
{
|
2021-11-19 07:32:07 -07:00
|
|
|
result.HasMetadata = await _omdbProvider.FetchEpisodeData(
|
|
|
|
result,
|
|
|
|
info.IndexNumber.Value,
|
|
|
|
info.ParentIndexNumber.Value,
|
|
|
|
info.GetProviderId(MetadataProvider.Imdb),
|
|
|
|
seriesImdbId,
|
|
|
|
info.MetadataLanguage,
|
|
|
|
info.MetadataCountryCode,
|
|
|
|
cancellationToken).ConfigureAwait(false);
|
2016-01-09 22:19:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-08-17 12:10:02 -07:00
|
|
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
2016-01-09 22:19:19 -07:00
|
|
|
{
|
|
|
|
return _itemProvider.GetImageResponse(url, cancellationToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|