2019-01-13 20:03:10 +00:00
|
|
|
using System;
|
2019-01-13 19:26:31 +00:00
|
|
|
using System.Collections.Generic;
|
2020-09-24 17:49:35 +00:00
|
|
|
using System.Globalization;
|
2020-09-28 21:56:55 +00:00
|
|
|
using System.Linq;
|
2020-08-17 19:10:02 +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;
|
2014-02-09 06:08:10 +00:00
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
|
2020-05-31 06:23:09 +00:00
|
|
|
namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
2014-02-09 06:08:10 +00:00
|
|
|
{
|
2022-04-15 17:27:38 +00:00
|
|
|
/// <summary>
|
|
|
|
/// TV series image provider powered by TheMovieDb.
|
|
|
|
/// </summary>
|
2019-08-18 11:20:52 +00:00
|
|
|
public class TmdbSeriesImageProvider : IRemoteImageProvider, IHasOrder
|
2014-02-09 06:08:10 +00:00
|
|
|
{
|
2020-08-17 19:10:02 +00:00
|
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
2020-09-24 17:49:35 +00:00
|
|
|
private readonly TmdbClientManager _tmdbClientManager;
|
2014-02-09 06:08:10 +00:00
|
|
|
|
2022-04-15 17:27:38 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="TmdbSeriesImageProvider"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="httpClientFactory">The <see cref="IHttpClientFactory"/>.</param>
|
|
|
|
/// <param name="tmdbClientManager">The <see cref="TmdbClientManager"/>.</param>
|
2020-09-24 17:49:35 +00:00
|
|
|
public TmdbSeriesImageProvider(IHttpClientFactory httpClientFactory, TmdbClientManager tmdbClientManager)
|
2014-02-09 06:08:10 +00:00
|
|
|
{
|
2020-08-17 19:10:02 +00:00
|
|
|
_httpClientFactory = httpClientFactory;
|
2020-09-24 17:49:35 +00:00
|
|
|
_tmdbClientManager = tmdbClientManager;
|
2014-02-09 06:08:10 +00:00
|
|
|
}
|
|
|
|
|
2022-04-15 17:27:38 +00:00
|
|
|
/// <inheritdoc />
|
2020-09-24 17:49:35 +00:00
|
|
|
public string Name => TmdbUtils.ProviderName;
|
2014-02-09 06:08:10 +00:00
|
|
|
|
2022-04-15 17:27:38 +00:00
|
|
|
/// <inheritdoc />
|
2020-09-08 14:12:47 +00:00
|
|
|
public int Order => 2;
|
|
|
|
|
2022-04-15 17:27:38 +00:00
|
|
|
/// <inheritdoc />
|
2018-09-12 17:26:21 +00:00
|
|
|
public bool Supports(BaseItem item)
|
2014-02-09 06:08:10 +00:00
|
|
|
{
|
|
|
|
return item is Series;
|
|
|
|
}
|
|
|
|
|
2022-04-15 17:27:38 +00:00
|
|
|
/// <inheritdoc />
|
2018-09-12 17:26:21 +00:00
|
|
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
2014-02-09 06:08:10 +00:00
|
|
|
{
|
2023-02-28 23:44:57 +00:00
|
|
|
return new ImageType[]
|
2014-02-09 06:08:10 +00:00
|
|
|
{
|
2019-01-07 23:27:46 +00:00
|
|
|
ImageType.Primary,
|
2021-10-21 22:35:14 +00:00
|
|
|
ImageType.Backdrop,
|
|
|
|
ImageType.Logo
|
2014-02-09 06:08:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-15 17:27:38 +00:00
|
|
|
/// <inheritdoc />
|
2018-09-12 17:26:21 +00:00
|
|
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
2014-02-09 06:08:10 +00:00
|
|
|
{
|
2020-09-24 17:49:35 +00:00
|
|
|
var tmdbId = item.GetProviderId(MetadataProvider.Tmdb);
|
2014-02-09 06:08:10 +00:00
|
|
|
|
2020-09-24 17:49:35 +00:00
|
|
|
if (string.IsNullOrEmpty(tmdbId))
|
2014-02-09 06:08:10 +00:00
|
|
|
{
|
2021-04-13 17:53:09 +00:00
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
2014-02-09 06:08:10 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 23:53:38 +00:00
|
|
|
var language = item.GetPreferredMetadataLanguage();
|
|
|
|
|
2021-03-05 07:18:04 +00:00
|
|
|
// TODO use image languages if All Languages isn't toggled, but there's currently no way to get that value in here
|
2020-09-24 17:49:35 +00:00
|
|
|
var series = await _tmdbClientManager
|
2021-03-05 07:18:04 +00:00
|
|
|
.GetSeriesAsync(Convert.ToInt32(tmdbId, CultureInfo.InvariantCulture), null, null, cancellationToken)
|
2020-09-24 17:49:35 +00:00
|
|
|
.ConfigureAwait(false);
|
2014-02-09 06:08:10 +00:00
|
|
|
|
2022-12-05 14:00:20 +00:00
|
|
|
if (series?.Images is null)
|
2014-02-09 06:08:10 +00:00
|
|
|
{
|
2020-09-27 18:13:38 +00:00
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
2014-02-09 06:08:10 +00:00
|
|
|
}
|
|
|
|
|
2020-10-06 12:54:17 +00:00
|
|
|
var posters = series.Images.Posters;
|
|
|
|
var backdrops = series.Images.Backdrops;
|
2021-10-21 22:35:14 +00:00
|
|
|
var logos = series.Images.Logos;
|
|
|
|
var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count + logos.Count);
|
2014-02-09 06:08:10 +00:00
|
|
|
|
2023-01-11 09:36:18 +00:00
|
|
|
remoteImages.AddRange(_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language));
|
|
|
|
remoteImages.AddRange(_tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language));
|
|
|
|
remoteImages.AddRange(_tmdbClientManager.ConvertLogosToRemoteImageInfo(logos, language));
|
2014-02-09 06:08:10 +00:00
|
|
|
|
2021-09-08 21:20:11 +00:00
|
|
|
return remoteImages;
|
2014-02-09 06:08:10 +00:00
|
|
|
}
|
2020-05-31 06:28:01 +00:00
|
|
|
|
2022-04-15 17:27:38 +00:00
|
|
|
/// <inheritdoc />
|
2020-08-17 19:10:02 +00:00
|
|
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
2014-02-09 06:08:10 +00:00
|
|
|
{
|
2020-08-31 17:05:21 +00:00
|
|
|
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
|
2014-02-09 06:08:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|