2021-10-26 13:49:01 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2020-06-19 18:24:13 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 20:03:10 +00:00
|
|
|
using System.Collections.Generic;
|
2021-11-19 14:32:07 +00:00
|
|
|
using System.Linq;
|
2020-12-23 12:06:29 +00:00
|
|
|
using System.Net.Http;
|
2019-01-13 19:26:31 +00:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2020-08-31 17:05:21 +00:00
|
|
|
using MediaBrowser.Common.Net;
|
2016-06-04 02:56:04 +00:00
|
|
|
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;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
2019-01-13 19:26:31 +00:00
|
|
|
using MediaBrowser.Model.IO;
|
2014-10-06 23:58:46 +00:00
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
|
2020-03-09 14:36:02 +00:00
|
|
|
namespace MediaBrowser.Providers.Plugins.Omdb
|
2014-10-06 23:58:46 +00:00
|
|
|
{
|
|
|
|
public class OmdbImageProvider : IRemoteImageProvider, IHasOrder
|
|
|
|
{
|
2020-08-17 19:10:02 +00:00
|
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
2021-11-19 14:32:07 +00:00
|
|
|
private readonly OmdbProvider _omdbProvider;
|
2014-10-06 23:58:46 +00:00
|
|
|
|
2021-11-16 11:24:17 +00:00
|
|
|
public OmdbImageProvider(IHttpClientFactory httpClientFactory, IFileSystem fileSystem, IServerConfigurationManager configurationManager)
|
2014-10-06 23:58:46 +00:00
|
|
|
{
|
2020-08-17 19:10:02 +00:00
|
|
|
_httpClientFactory = httpClientFactory;
|
2021-11-19 14:32:07 +00:00
|
|
|
_omdbProvider = new OmdbProvider(_httpClientFactory, fileSystem, configurationManager);
|
2014-10-06 23:58:46 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 11:20:39 +00:00
|
|
|
public string Name => "The Open Movie Database";
|
|
|
|
|
|
|
|
// After other internet providers, because they're better
|
|
|
|
// But before fallback providers like screengrab
|
|
|
|
public int Order => 90;
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
2014-10-06 23:58:46 +00:00
|
|
|
{
|
2023-02-28 23:44:57 +00:00
|
|
|
yield return ImageType.Primary;
|
2014-10-06 23:58:46 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
2014-10-06 23:58:46 +00:00
|
|
|
{
|
2020-06-06 19:17:49 +00:00
|
|
|
var imdbId = item.GetProviderId(MetadataProvider.Imdb);
|
2021-11-19 14:32:07 +00:00
|
|
|
if (string.IsNullOrWhiteSpace(imdbId))
|
|
|
|
{
|
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
|
|
|
}
|
2014-10-06 23:58:46 +00:00
|
|
|
|
2021-11-19 14:32:07 +00:00
|
|
|
var rootObject = await _omdbProvider.GetRootObject(imdbId, cancellationToken).ConfigureAwait(false);
|
2016-06-04 02:56:04 +00:00
|
|
|
|
2021-11-20 07:32:07 +00:00
|
|
|
if (string.IsNullOrEmpty(rootObject.Poster))
|
2014-10-06 23:58:46 +00:00
|
|
|
{
|
2021-11-19 14:32:07 +00:00
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
|
|
|
}
|
2016-06-04 01:08:27 +00:00
|
|
|
|
2021-11-19 14:32:07 +00:00
|
|
|
// the poster url is sometimes higher quality than the poster api
|
|
|
|
return new[]
|
|
|
|
{
|
|
|
|
new RemoteImageInfo
|
2014-10-06 23:58:46 +00:00
|
|
|
{
|
2021-11-19 14:32:07 +00:00
|
|
|
ProviderName = Name,
|
|
|
|
Url = rootObject.Poster
|
2016-06-04 01:08:27 +00:00
|
|
|
}
|
2021-11-19 14:32:07 +00:00
|
|
|
};
|
2014-10-06 23:58:46 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 19:10:02 +00:00
|
|
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
2014-10-06 23:58:46 +00:00
|
|
|
{
|
2020-08-31 17:05:21 +00:00
|
|
|
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
|
2014-10-06 23:58:46 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
public bool Supports(BaseItem item)
|
2014-10-06 23:58:46 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|