using MediaBrowser.Common.Net; using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Channels; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Net; using MediaBrowser.Model.Providers; using System.Collections.Generic; using System.Net; using System.Threading; using System.Threading.Tasks; namespace MediaBrowser.Providers.Omdb { public class OmdbImageProvider : IRemoteImageProvider, IHasOrder { private readonly IHttpClient _httpClient; public OmdbImageProvider(IHttpClient httpClient) { _httpClient = httpClient; } public IEnumerable GetSupportedImages(IHasImages item) { return new List { ImageType.Primary }; } public Task> GetImages(IHasImages item, CancellationToken cancellationToken) { var imdbId = item.GetProviderId(MetadataProviders.Imdb); var list = new List(); if (!string.IsNullOrWhiteSpace(imdbId)) { list.Add(new RemoteImageInfo { ProviderName = Name, Url = string.Format("http://img.omdbapi.com/?i={0}&apikey=82e83907", imdbId) }); } return Task.FromResult>(list); } public Task GetImageResponse(string url, CancellationToken cancellationToken) { return _httpClient.GetResponse(new HttpRequestOptions { CancellationToken = cancellationToken, Url = url, ResourcePool = OmdbProvider.ResourcePool }); } public string Name { get { return "The Open Movie Database"; } } public bool Supports(IHasImages item) { // We'll hammer Omdb if we enable this if (item is Person) { return false; } // Save the http requests since we know it's not currently supported if (item is Season || item is Episode) { return false; } var channelItem = item as IChannelMediaItem; if (channelItem != null) { if (channelItem.ContentType == ChannelMediaContentType.Movie) { return true; } if (channelItem.ContentType == ChannelMediaContentType.MovieExtra) { if (channelItem.ExtraType == ExtraType.Trailer) { return true; } } } // Supports images for tv movies var tvProgram = item as LiveTvProgram; if (tvProgram != null && tvProgram.IsMovie) { return true; } return item is Movie; } public int Order { get { // After other internet providers, because they're better // But before fallback providers like screengrab return 90; } } } }