OmdbEpisodeProvider.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma warning disable CS1591
  2. using System.Collections.Generic;
  3. using System.Net.Http;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using MediaBrowser.Common;
  7. using MediaBrowser.Controller.Configuration;
  8. using MediaBrowser.Controller.Entities.TV;
  9. using MediaBrowser.Controller.Library;
  10. using MediaBrowser.Controller.Providers;
  11. using MediaBrowser.Model.Entities;
  12. using MediaBrowser.Model.IO;
  13. using MediaBrowser.Model.Providers;
  14. using MediaBrowser.Model.Serialization;
  15. namespace MediaBrowser.Providers.Plugins.Omdb
  16. {
  17. public class OmdbEpisodeProvider : IRemoteMetadataProvider<Episode, EpisodeInfo>, IHasOrder
  18. {
  19. private readonly IJsonSerializer _jsonSerializer;
  20. private readonly IHttpClientFactory _httpClientFactory;
  21. private readonly OmdbItemProvider _itemProvider;
  22. private readonly IFileSystem _fileSystem;
  23. private readonly IServerConfigurationManager _configurationManager;
  24. private readonly IApplicationHost _appHost;
  25. public OmdbEpisodeProvider(
  26. IJsonSerializer jsonSerializer,
  27. IApplicationHost appHost,
  28. IHttpClientFactory httpClientFactory,
  29. ILibraryManager libraryManager,
  30. IFileSystem fileSystem,
  31. IServerConfigurationManager configurationManager)
  32. {
  33. _jsonSerializer = jsonSerializer;
  34. _httpClientFactory = httpClientFactory;
  35. _fileSystem = fileSystem;
  36. _configurationManager = configurationManager;
  37. _appHost = appHost;
  38. _itemProvider = new OmdbItemProvider(jsonSerializer, _appHost, httpClientFactory, libraryManager, fileSystem, configurationManager);
  39. }
  40. // After TheTvDb
  41. public int Order => 1;
  42. public string Name => "The Open Movie Database";
  43. public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(EpisodeInfo searchInfo, CancellationToken cancellationToken)
  44. {
  45. return _itemProvider.GetSearchResults(searchInfo, "episode", cancellationToken);
  46. }
  47. public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo info, CancellationToken cancellationToken)
  48. {
  49. var result = new MetadataResult<Episode>()
  50. {
  51. Item = new Episode(),
  52. QueriedById = true
  53. };
  54. // Allowing this will dramatically increase scan times
  55. if (info.IsMissingEpisode)
  56. {
  57. return result;
  58. }
  59. if (info.SeriesProviderIds.TryGetValue(MetadataProvider.Imdb.ToString(), out string seriesImdbId) && !string.IsNullOrEmpty(seriesImdbId))
  60. {
  61. if (info.IndexNumber.HasValue && info.ParentIndexNumber.HasValue)
  62. {
  63. result.HasMetadata = await new OmdbProvider(_jsonSerializer, _httpClientFactory, _fileSystem, _appHost, _configurationManager)
  64. .FetchEpisodeData(result, info.IndexNumber.Value, info.ParentIndexNumber.Value, info.GetProviderId(MetadataProvider.Imdb), seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
  65. }
  66. }
  67. return result;
  68. }
  69. public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
  70. {
  71. return _itemProvider.GetImageResponse(url, cancellationToken);
  72. }
  73. }
  74. }