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