OmdbEpisodeProvider.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using MediaBrowser.Model.IO;
  2. using MediaBrowser.Common.Net;
  3. using MediaBrowser.Controller.Configuration;
  4. using MediaBrowser.Controller.Entities.TV;
  5. using MediaBrowser.Controller.Library;
  6. using MediaBrowser.Controller.Providers;
  7. using MediaBrowser.Model.Entities;
  8. using MediaBrowser.Model.Logging;
  9. using MediaBrowser.Model.Providers;
  10. using MediaBrowser.Model.Serialization;
  11. using MediaBrowser.Providers.Omdb;
  12. using System.Collections.Generic;
  13. using System.Threading;
  14. using System.Threading.Tasks;
  15. using MediaBrowser.Common.IO;
  16. using MediaBrowser.Controller.IO;
  17. namespace MediaBrowser.Providers.TV
  18. {
  19. class OmdbEpisodeProvider :
  20. IRemoteMetadataProvider<Episode, EpisodeInfo>,
  21. IHasOrder
  22. {
  23. private readonly IJsonSerializer _jsonSerializer;
  24. private readonly IHttpClient _httpClient;
  25. private readonly OmdbItemProvider _itemProvider;
  26. private readonly IFileSystem _fileSystem;
  27. private readonly IServerConfigurationManager _configurationManager;
  28. public OmdbEpisodeProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogger logger, ILibraryManager libraryManager, IFileSystem fileSystem, IServerConfigurationManager configurationManager)
  29. {
  30. _jsonSerializer = jsonSerializer;
  31. _httpClient = httpClient;
  32. _fileSystem = fileSystem;
  33. _configurationManager = configurationManager;
  34. _itemProvider = new OmdbItemProvider(jsonSerializer, 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 || info.IsVirtualUnaired)
  49. {
  50. return result;
  51. }
  52. string seriesImdbId;
  53. if (info.SeriesProviderIds.TryGetValue(MetadataProviders.Imdb.ToString(), out seriesImdbId) && !string.IsNullOrEmpty(seriesImdbId))
  54. {
  55. if (info.IndexNumber.HasValue &&
  56. info.ParentIndexNumber.HasValue)
  57. {
  58. result.HasMetadata = await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _configurationManager)
  59. .FetchEpisodeData(result, info.IndexNumber.Value, info.ParentIndexNumber.Value, seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
  60. }
  61. }
  62. return result;
  63. }
  64. public int Order
  65. {
  66. get
  67. {
  68. // After TheTvDb
  69. return 1;
  70. }
  71. }
  72. public string Name
  73. {
  74. get { return "The Open Movie Database"; }
  75. }
  76. public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
  77. {
  78. return _itemProvider.GetImageResponse(url, cancellationToken);
  79. }
  80. }
  81. }