OmdbEpisodeProvider.cs 3.3 KB

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