2016-10-25 19:02:04 +00:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2016-06-04 02:56:04 +00:00
|
|
|
|
using MediaBrowser.Common.Net;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2014-10-06 23:58:46 +00:00
|
|
|
|
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.Entities;
|
|
|
|
|
using MediaBrowser.Model.Providers;
|
2016-06-04 02:56:04 +00:00
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2014-10-06 23:58:46 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-10-25 19:02:04 +00:00
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Controller.IO;
|
2014-10-06 23:58:46 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.Omdb
|
|
|
|
|
{
|
|
|
|
|
public class OmdbImageProvider : IRemoteImageProvider, IHasOrder
|
|
|
|
|
{
|
|
|
|
|
private readonly IHttpClient _httpClient;
|
2016-06-04 02:56:04 +00:00
|
|
|
|
private readonly IJsonSerializer _jsonSerializer;
|
|
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
|
private readonly IServerConfigurationManager _configurationManager;
|
2014-10-06 23:58:46 +00:00
|
|
|
|
|
2016-06-04 02:56:04 +00:00
|
|
|
|
public OmdbImageProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem, IServerConfigurationManager configurationManager)
|
2014-10-06 23:58:46 +00:00
|
|
|
|
{
|
2016-06-04 02:56:04 +00:00
|
|
|
|
_jsonSerializer = jsonSerializer;
|
2014-10-06 23:58:46 +00:00
|
|
|
|
_httpClient = httpClient;
|
2016-06-04 02:56:04 +00:00
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
|
_configurationManager = configurationManager;
|
2014-10-06 23:58:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
return new List<ImageType>
|
|
|
|
|
{
|
|
|
|
|
ImageType.Primary
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-04 01:08:27 +00:00
|
|
|
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, CancellationToken cancellationToken)
|
2014-10-06 23:58:46 +00:00
|
|
|
|
{
|
|
|
|
|
var imdbId = item.GetProviderId(MetadataProviders.Imdb);
|
|
|
|
|
|
|
|
|
|
var list = new List<RemoteImageInfo>();
|
|
|
|
|
|
2016-06-04 02:56:04 +00:00
|
|
|
|
var provider = new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _configurationManager);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(imdbId))
|
2014-10-06 23:58:46 +00:00
|
|
|
|
{
|
2016-06-04 02:56:04 +00:00
|
|
|
|
OmdbProvider.RootObject rootObject = await provider.GetRootObject(imdbId, cancellationToken).ConfigureAwait(false);
|
2016-06-04 01:08:27 +00:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(rootObject.Poster))
|
2014-10-06 23:58:46 +00:00
|
|
|
|
{
|
2016-06-04 01:08:27 +00:00
|
|
|
|
list.Add(new RemoteImageInfo
|
|
|
|
|
{
|
|
|
|
|
ProviderName = Name,
|
|
|
|
|
Url = string.Format("https://img.omdbapi.com/?i={0}&apikey=82e83907", imdbId)
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-10-06 23:58:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-04 01:08:27 +00:00
|
|
|
|
return list;
|
2014-10-06 23:58:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
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,
|
2016-10-31 18:39:41 +00:00
|
|
|
|
Url = url
|
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-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-06-04 01:08:27 +00:00
|
|
|
|
return item is Movie || item is Trailer || item is Episode;
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|