2019-01-13 19:26:31 +00:00
|
|
|
using System.Collections.Generic;
|
2020-09-24 17:49:35 +00:00
|
|
|
using System.Globalization;
|
2019-01-13 19:26:31 +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;
|
2013-11-05 16:52:43 +00:00
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
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.People
|
2013-11-05 16:52:43 +00:00
|
|
|
{
|
2022-04-15 17:27:38 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Person image provider powered by TMDb.
|
|
|
|
/// </summary>
|
2019-08-18 11:20:52 +00:00
|
|
|
public class TmdbPersonImageProvider : IRemoteImageProvider, IHasOrder
|
2013-11-05 16:52:43 +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;
|
2013-11-05 16:52:43 +00:00
|
|
|
|
2022-04-15 17:27:38 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="TmdbPersonImageProvider"/> 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 TmdbPersonImageProvider(IHttpClientFactory httpClientFactory, TmdbClientManager tmdbClientManager)
|
2013-11-05 16:52:43 +00:00
|
|
|
{
|
2020-08-17 19:10:02 +00:00
|
|
|
_httpClientFactory = httpClientFactory;
|
2020-09-24 17:49:35 +00:00
|
|
|
_tmdbClientManager = tmdbClientManager;
|
2013-11-05 16:52:43 +00:00
|
|
|
}
|
|
|
|
|
2020-08-31 20:20:19 +00:00
|
|
|
/// <inheritdoc />
|
2020-09-24 17:49:35 +00:00
|
|
|
public string Name => TmdbUtils.ProviderName;
|
2013-11-05 16:52:43 +00:00
|
|
|
|
2020-08-31 20:20:19 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
public int Order => 0;
|
2013-11-05 16:52:43 +00:00
|
|
|
|
2022-04-15 17:27:38 +00:00
|
|
|
/// <inheritdoc />
|
2018-09-12 17:26:21 +00:00
|
|
|
public bool Supports(BaseItem item)
|
2013-11-05 16:52:43 +00:00
|
|
|
{
|
|
|
|
return item is Person;
|
|
|
|
}
|
|
|
|
|
2022-04-15 17:27:38 +00:00
|
|
|
/// <inheritdoc />
|
2018-09-12 17:26:21 +00:00
|
|
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
2014-01-28 18:37:01 +00:00
|
|
|
{
|
2023-02-28 23:44:57 +00:00
|
|
|
yield return ImageType.Primary;
|
2014-01-28 18:37:01 +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)
|
2013-11-05 16:52:43 +00:00
|
|
|
{
|
2013-12-21 18:37:34 +00:00
|
|
|
var person = (Person)item;
|
2013-11-05 16:52:43 +00:00
|
|
|
|
2021-04-20 06:59:15 +00:00
|
|
|
if (!person.TryGetProviderId(MetadataProvider.Tmdb, out var personTmdbId))
|
2013-11-05 16:52:43 +00:00
|
|
|
{
|
2021-04-20 06:59:15 +00:00
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
|
|
|
}
|
2020-06-15 21:43:52 +00:00
|
|
|
|
2021-05-18 11:44:38 +00:00
|
|
|
var language = item.GetPreferredMetadataLanguage();
|
2021-05-12 12:48:45 +00:00
|
|
|
var personResult = await _tmdbClientManager.GetPersonAsync(int.Parse(personTmdbId, CultureInfo.InvariantCulture), language, cancellationToken).ConfigureAwait(false);
|
2022-12-05 14:00:20 +00:00
|
|
|
if (personResult?.Images?.Profiles is null)
|
2021-04-20 06:59:15 +00:00
|
|
|
{
|
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
|
|
|
}
|
2020-06-15 21:43:52 +00:00
|
|
|
|
2023-01-11 09:36:18 +00:00
|
|
|
return _tmdbClientManager.ConvertProfilesToRemoteImageInfo(personResult.Images.Profiles, language);
|
2013-11-05 16:52:43 +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-01-28 18:37:01 +00:00
|
|
|
{
|
2020-08-31 17:05:21 +00:00
|
|
|
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
|
2014-01-28 18:37:01 +00:00
|
|
|
}
|
2013-11-05 16:52:43 +00:00
|
|
|
}
|
|
|
|
}
|