jellyfin/MediaBrowser.Providers/Omdb/OmdbImageProvider.cs

105 lines
3.0 KiB
C#
Raw Normal View History

2014-10-06 23:58:46 +00:00
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
2015-03-14 20:00:32 +00:00
using MediaBrowser.Controller.LiveTv;
2014-10-06 23:58:46 +00:00
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<ImageType> GetSupportedImages(IHasImages item)
{
return new List<ImageType>
{
ImageType.Primary
};
}
public Task<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, CancellationToken cancellationToken)
{
var imdbId = item.GetProviderId(MetadataProviders.Imdb);
var list = new List<RemoteImageInfo>();
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<IEnumerable<RemoteImageInfo>>(list);
}
2016-01-15 19:15:32 +00:00
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
2014-10-06 23:58:46 +00:00
{
2016-01-15 19:15:32 +00:00
return _httpClient.GetResponse(new HttpRequestOptions
2014-10-06 23:58:46 +00:00
{
CancellationToken = cancellationToken,
Url = url,
ResourcePool = OmdbProvider.ResourcePool
2016-01-15 19:15:32 +00:00
});
2014-10-06 23:58:46 +00:00
}
public string Name
{
get { return "The Open Movie Database"; }
}
public bool Supports(IHasImages item)
{
2015-09-16 03:55:26 +00:00
// We'll hammer Omdb if we enable this
2014-10-06 23:58:46 +00:00
if (item is Person)
{
return false;
}
// Save the http requests since we know it's not currently supported
2016-01-15 20:29:52 +00:00
if (item is Season || item is Episode)
2014-10-06 23:58:46 +00:00
{
return false;
}
2015-03-14 20:00:32 +00:00
// Supports images for tv movies
var tvProgram = item as LiveTvProgram;
if (tvProgram != null && tvProgram.IsMovie)
{
return true;
}
2016-03-19 15:38:05 +00:00
return item is Movie || item is Trailer;
2014-10-06 23:58:46 +00:00
}
public int Order
{
get
{
// After other internet providers, because they're better
// But before fallback providers like screengrab
return 90;
}
}
}
}