jellyfin/MediaBrowser.Providers/Plugins/Omdb/OmdbEpisodeProvider.cs

82 lines
3.1 KiB
C#
Raw Normal View History

#pragma warning disable CS1591
using System.Collections.Generic;
2020-08-17 12:10:02 -07:00
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers;
2020-03-09 07:36:02 -07:00
namespace MediaBrowser.Providers.Plugins.Omdb
{
public class OmdbEpisodeProvider : IRemoteMetadataProvider<Episode, EpisodeInfo>, IHasOrder
{
2020-08-17 12:10:02 -07:00
private readonly IHttpClientFactory _httpClientFactory;
2016-04-17 21:25:43 -07:00
private readonly OmdbItemProvider _itemProvider;
private readonly IFileSystem _fileSystem;
private readonly IServerConfigurationManager _configurationManager;
2018-09-12 10:26:21 -07:00
private readonly IApplicationHost _appHost;
public OmdbEpisodeProvider(
IApplicationHost appHost,
2020-08-17 12:10:02 -07:00
IHttpClientFactory httpClientFactory,
ILibraryManager libraryManager,
IFileSystem fileSystem,
IServerConfigurationManager configurationManager)
{
2020-08-17 12:10:02 -07:00
_httpClientFactory = httpClientFactory;
_fileSystem = fileSystem;
_configurationManager = configurationManager;
2018-09-12 10:26:21 -07:00
_appHost = appHost;
_itemProvider = new OmdbItemProvider(_appHost, httpClientFactory, libraryManager, fileSystem, configurationManager);
}
// After TheTvDb
public int Order => 1;
public string Name => "The Open Movie Database";
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)
{
var result = new MetadataResult<Episode>()
{
Item = new Episode(),
QueriedById = true
};
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;
}
2020-06-06 12:17:49 -07:00
if (info.SeriesProviderIds.TryGetValue(MetadataProvider.Imdb.ToString(), out string seriesImdbId) && !string.IsNullOrEmpty(seriesImdbId))
{
if (info.IndexNumber.HasValue && info.ParentIndexNumber.HasValue)
2016-12-23 10:09:50 -07:00
{
result.HasMetadata = await new OmdbProvider(_httpClientFactory, _fileSystem, _appHost, _configurationManager)
2020-06-06 12:17:49 -07:00
.FetchEpisodeData(result, info.IndexNumber.Value, info.ParentIndexNumber.Value, info.GetProviderId(MetadataProvider.Imdb), seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
2016-12-23 10:09:50 -07:00
}
}
return result;
}
2020-08-17 12:10:02 -07:00
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _itemProvider.GetImageResponse(url, cancellationToken);
}
}
}