OmdbEpisodeProvider.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. namespace MediaBrowser.Providers.Plugins.Omdb
  15. {
  16. public class OmdbEpisodeProvider : IRemoteMetadataProvider<Episode, EpisodeInfo>, IHasOrder
  17. {
  18. private readonly IJsonSerializer _jsonSerializer;
  19. private readonly IHttpClient _httpClient;
  20. private readonly OmdbItemProvider _itemProvider;
  21. private readonly IFileSystem _fileSystem;
  22. private readonly IServerConfigurationManager _configurationManager;
  23. private readonly IApplicationHost _appHost;
  24. public OmdbEpisodeProvider(
  25. IJsonSerializer jsonSerializer,
  26. IApplicationHost appHost,
  27. IHttpClient httpClient,
  28. ILibraryManager libraryManager,
  29. IFileSystem fileSystem,
  30. IServerConfigurationManager configurationManager)
  31. {
  32. _jsonSerializer = jsonSerializer;
  33. _httpClient = httpClient;
  34. _fileSystem = fileSystem;
  35. _configurationManager = configurationManager;
  36. _appHost = appHost;
  37. _itemProvider = new OmdbItemProvider(jsonSerializer, _appHost, httpClient, libraryManager, fileSystem, configurationManager);
  38. }
  39. // After TheTvDb
  40. public int Order => 1;
  41. public string Name => "The Open Movie Database";
  42. public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(EpisodeInfo searchInfo, CancellationToken cancellationToken)
  43. {
  44. return _itemProvider.GetSearchResults(searchInfo, "episode", cancellationToken);
  45. }
  46. public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo info, CancellationToken cancellationToken)
  47. {
  48. var result = new MetadataResult<Episode>()
  49. {
  50. Item = new Episode(),
  51. QueriedById = true
  52. };
  53. // Allowing this will dramatically increase scan times
  54. if (info.IsMissingEpisode)
  55. {
  56. return result;
  57. }
  58. if (info.SeriesProviderIds.TryGetValue(MetadataProvider.Imdb.ToString(), out string seriesImdbId) && !string.IsNullOrEmpty(seriesImdbId))
  59. {
  60. if (info.IndexNumber.HasValue && info.ParentIndexNumber.HasValue)
  61. {
  62. result.HasMetadata = await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _appHost, _configurationManager)
  63. .FetchEpisodeData(result, info.IndexNumber.Value, info.ParentIndexNumber.Value, info.GetProviderId(MetadataProvider.Imdb), seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
  64. }
  65. }
  66. return result;
  67. }
  68. public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
  69. {
  70. return _itemProvider.GetImageResponse(url, cancellationToken);
  71. }
  72. }
  73. }