| | | 1 | | #nullable disable |
| | | 2 | | |
| | | 3 | | #pragma warning disable CS1591 |
| | | 4 | | |
| | | 5 | | using System.Collections.Generic; |
| | | 6 | | using System.Linq; |
| | | 7 | | using System.Net.Http; |
| | | 8 | | using System.Threading; |
| | | 9 | | using System.Threading.Tasks; |
| | | 10 | | using MediaBrowser.Common.Net; |
| | | 11 | | using MediaBrowser.Controller.Configuration; |
| | | 12 | | using MediaBrowser.Controller.Entities; |
| | | 13 | | using MediaBrowser.Controller.Entities.Movies; |
| | | 14 | | using MediaBrowser.Controller.Entities.TV; |
| | | 15 | | using MediaBrowser.Controller.Providers; |
| | | 16 | | using MediaBrowser.Model.Entities; |
| | | 17 | | using MediaBrowser.Model.IO; |
| | | 18 | | using MediaBrowser.Model.Providers; |
| | | 19 | | |
| | | 20 | | namespace MediaBrowser.Providers.Plugins.Omdb |
| | | 21 | | { |
| | | 22 | | public class OmdbImageProvider : IRemoteImageProvider, IHasOrder |
| | | 23 | | { |
| | | 24 | | private readonly IHttpClientFactory _httpClientFactory; |
| | | 25 | | private readonly OmdbProvider _omdbProvider; |
| | | 26 | | |
| | | 27 | | public OmdbImageProvider(IHttpClientFactory httpClientFactory, IFileSystem fileSystem, IServerConfigurationManag |
| | | 28 | | { |
| | 21 | 29 | | _httpClientFactory = httpClientFactory; |
| | 21 | 30 | | _omdbProvider = new OmdbProvider(_httpClientFactory, fileSystem, configurationManager); |
| | 21 | 31 | | } |
| | | 32 | | |
| | 0 | 33 | | public string Name => "The Open Movie Database"; |
| | | 34 | | |
| | | 35 | | // After other internet providers, because they're better |
| | | 36 | | // But before fallback providers like screengrab |
| | 0 | 37 | | public int Order => 90; |
| | | 38 | | |
| | | 39 | | public IEnumerable<ImageType> GetSupportedImages(BaseItem item) |
| | | 40 | | { |
| | | 41 | | yield return ImageType.Primary; |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken) |
| | | 45 | | { |
| | | 46 | | var imdbId = item.GetProviderId(MetadataProvider.Imdb); |
| | | 47 | | if (string.IsNullOrWhiteSpace(imdbId)) |
| | | 48 | | { |
| | | 49 | | return Enumerable.Empty<RemoteImageInfo>(); |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | var rootObject = await _omdbProvider.GetRootObject(imdbId, cancellationToken).ConfigureAwait(false); |
| | | 53 | | |
| | | 54 | | if (string.IsNullOrEmpty(rootObject.Poster)) |
| | | 55 | | { |
| | | 56 | | return Enumerable.Empty<RemoteImageInfo>(); |
| | | 57 | | } |
| | | 58 | | |
| | | 59 | | // the poster url is sometimes higher quality than the poster api |
| | | 60 | | return new[] |
| | | 61 | | { |
| | | 62 | | new RemoteImageInfo |
| | | 63 | | { |
| | | 64 | | ProviderName = Name, |
| | | 65 | | Url = rootObject.Poster |
| | | 66 | | } |
| | | 67 | | }; |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken) |
| | | 71 | | { |
| | 0 | 72 | | return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken); |
| | | 73 | | } |
| | | 74 | | |
| | | 75 | | public bool Supports(BaseItem item) |
| | | 76 | | { |
| | 55 | 77 | | return item is Movie || item is Trailer || item is Episode; |
| | | 78 | | } |
| | | 79 | | } |
| | | 80 | | } |