OmdbEpisodeProvider.cs 3.3 KB

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