You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
3.5 KiB
100 lines
3.5 KiB
6 years ago
|
using System.Collections.Generic;
|
||
6 years ago
|
using System.Threading;
|
||
|
using System.Threading.Tasks;
|
||
|
using MediaBrowser.Common;
|
||
9 years ago
|
using MediaBrowser.Common.Net;
|
||
|
using MediaBrowser.Controller.Configuration;
|
||
10 years ago
|
using MediaBrowser.Controller.Entities;
|
||
|
using MediaBrowser.Controller.Entities.Movies;
|
||
|
using MediaBrowser.Controller.Entities.TV;
|
||
|
using MediaBrowser.Controller.Providers;
|
||
|
using MediaBrowser.Model.Entities;
|
||
6 years ago
|
using MediaBrowser.Model.IO;
|
||
10 years ago
|
using MediaBrowser.Model.Providers;
|
||
9 years ago
|
using MediaBrowser.Model.Serialization;
|
||
10 years ago
|
|
||
5 years ago
|
namespace MediaBrowser.Providers.Plugins.Omdb
|
||
10 years ago
|
{
|
||
|
public class OmdbImageProvider : IRemoteImageProvider, IHasOrder
|
||
|
{
|
||
|
private readonly IHttpClient _httpClient;
|
||
9 years ago
|
private readonly IJsonSerializer _jsonSerializer;
|
||
|
private readonly IFileSystem _fileSystem;
|
||
|
private readonly IServerConfigurationManager _configurationManager;
|
||
6 years ago
|
private readonly IApplicationHost _appHost;
|
||
10 years ago
|
|
||
6 years ago
|
public OmdbImageProvider(IJsonSerializer jsonSerializer, IApplicationHost appHost, IHttpClient httpClient, IFileSystem fileSystem, IServerConfigurationManager configurationManager)
|
||
10 years ago
|
{
|
||
9 years ago
|
_jsonSerializer = jsonSerializer;
|
||
10 years ago
|
_httpClient = httpClient;
|
||
9 years ago
|
_fileSystem = fileSystem;
|
||
|
_configurationManager = configurationManager;
|
||
6 years ago
|
_appHost = appHost;
|
||
10 years ago
|
}
|
||
|
|
||
6 years ago
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
||
10 years ago
|
{
|
||
|
return new List<ImageType>
|
||
|
{
|
||
|
ImageType.Primary
|
||
|
};
|
||
|
}
|
||
|
|
||
6 years ago
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
||
10 years ago
|
{
|
||
|
var imdbId = item.GetProviderId(MetadataProviders.Imdb);
|
||
|
|
||
|
var list = new List<RemoteImageInfo>();
|
||
|
|
||
6 years ago
|
var provider = new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _appHost, _configurationManager);
|
||
9 years ago
|
|
||
|
if (!string.IsNullOrWhiteSpace(imdbId))
|
||
10 years ago
|
{
|
||
6 years ago
|
var rootObject = await provider.GetRootObject(imdbId, cancellationToken).ConfigureAwait(false);
|
||
9 years ago
|
|
||
|
if (!string.IsNullOrEmpty(rootObject.Poster))
|
||
10 years ago
|
{
|
||
8 years ago
|
if (item is Episode)
|
||
9 years ago
|
{
|
||
6 years ago
|
// img.omdbapi.com is returning 404's
|
||
8 years ago
|
list.Add(new RemoteImageInfo
|
||
|
{
|
||
|
ProviderName = Name,
|
||
|
Url = rootObject.Poster
|
||
|
});
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
list.Add(new RemoteImageInfo
|
||
|
{
|
||
|
ProviderName = Name,
|
||
6 years ago
|
Url = string.Format("https://img.omdbapi.com/?i={0}&apikey=2c9d9507", imdbId)
|
||
8 years ago
|
});
|
||
|
}
|
||
9 years ago
|
}
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
return list;
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
||
10 years ago
|
{
|
||
9 years ago
|
return _httpClient.GetResponse(new HttpRequestOptions
|
||
10 years ago
|
{
|
||
|
CancellationToken = cancellationToken,
|
||
8 years ago
|
Url = url
|
||
9 years ago
|
});
|
||
10 years ago
|
}
|
||
|
|
||
6 years ago
|
public string Name => "The Open Movie Database";
|
||
10 years ago
|
|
||
6 years ago
|
public bool Supports(BaseItem item)
|
||
10 years ago
|
{
|
||
9 years ago
|
return item is Movie || item is Trailer || item is Episode;
|
||
10 years ago
|
}
|
||
6 years ago
|
// After other internet providers, because they're better
|
||
|
// But before fallback providers like screengrab
|
||
6 years ago
|
public int Order => 90;
|
||
10 years ago
|
}
|
||
|
}
|