2019-01-13 21:03:10 +01:00
|
|
|
using System;
|
2019-01-13 20:26:31 +01:00
|
|
|
using System.Collections.Generic;
|
2020-09-24 19:49:35 +02:00
|
|
|
using System.Globalization;
|
2019-01-13 20:26:31 +01:00
|
|
|
using System.Linq;
|
2020-08-17 21:10:02 +02:00
|
|
|
using System.Net.Http;
|
2019-01-13 20:26:31 +01:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2020-08-31 19:05:21 +02:00
|
|
|
using MediaBrowser.Common.Net;
|
2014-01-30 22:47:13 +01:00
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
|
2020-05-31 08:23:09 +02:00
|
|
|
namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
|
2014-01-30 22:47:13 +01:00
|
|
|
{
|
2022-04-15 19:27:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// BoxSet image provider powered by TMDb.
|
|
|
|
/// </summary>
|
2019-08-18 13:20:52 +02:00
|
|
|
public class TmdbBoxSetImageProvider : IRemoteImageProvider, IHasOrder
|
2014-01-30 22:47:13 +01:00
|
|
|
{
|
2020-08-17 21:10:02 +02:00
|
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
2020-09-24 19:49:35 +02:00
|
|
|
private readonly TmdbClientManager _tmdbClientManager;
|
2014-01-30 22:47:13 +01:00
|
|
|
|
2022-04-15 19:27:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="TmdbBoxSetImageProvider"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="httpClientFactory">The <see cref="IHttpClientFactory"/>.</param>
|
|
|
|
/// <param name="tmdbClientManager">The <see cref="TmdbClientManager"/>.</param>
|
2020-09-24 19:49:35 +02:00
|
|
|
public TmdbBoxSetImageProvider(IHttpClientFactory httpClientFactory, TmdbClientManager tmdbClientManager)
|
2014-01-30 22:47:13 +01:00
|
|
|
{
|
2020-08-17 21:10:02 +02:00
|
|
|
_httpClientFactory = httpClientFactory;
|
2020-09-24 19:49:35 +02:00
|
|
|
_tmdbClientManager = tmdbClientManager;
|
2014-01-30 22:47:13 +01:00
|
|
|
}
|
|
|
|
|
2022-04-15 19:27:38 +02:00
|
|
|
/// <inheritdoc />
|
2020-09-24 19:49:35 +02:00
|
|
|
public string Name => TmdbUtils.ProviderName;
|
2014-01-30 22:47:13 +01:00
|
|
|
|
2022-04-15 19:27:38 +02:00
|
|
|
/// <inheritdoc />
|
2020-09-24 19:49:35 +02:00
|
|
|
public int Order => 0;
|
2014-01-30 22:47:13 +01:00
|
|
|
|
2022-04-15 19:27:38 +02:00
|
|
|
/// <inheritdoc />
|
2018-09-12 19:26:21 +02:00
|
|
|
public bool Supports(BaseItem item)
|
2014-01-30 22:47:13 +01:00
|
|
|
{
|
|
|
|
return item is BoxSet;
|
|
|
|
}
|
|
|
|
|
2022-04-15 19:27:38 +02:00
|
|
|
/// <inheritdoc />
|
2024-02-29 01:39:31 +01:00
|
|
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item) =>
|
|
|
|
[
|
|
|
|
ImageType.Primary,
|
|
|
|
ImageType.Backdrop,
|
|
|
|
ImageType.Thumb
|
|
|
|
];
|
2014-01-30 22:47:13 +01:00
|
|
|
|
2022-04-15 19:27:38 +02:00
|
|
|
/// <inheritdoc />
|
2018-09-12 19:26:21 +02:00
|
|
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
2014-01-30 22:47:13 +01:00
|
|
|
{
|
2020-09-24 19:49:35 +02:00
|
|
|
var tmdbId = Convert.ToInt32(item.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);
|
2014-01-30 22:47:13 +01:00
|
|
|
|
2020-09-24 19:49:35 +02:00
|
|
|
if (tmdbId <= 0)
|
2014-01-30 22:47:13 +01:00
|
|
|
{
|
2020-09-24 19:49:35 +02:00
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
|
|
|
}
|
2014-01-30 22:47:13 +01:00
|
|
|
|
2020-09-24 19:49:35 +02:00
|
|
|
var language = item.GetPreferredMetadataLanguage();
|
2014-01-30 22:47:13 +01:00
|
|
|
|
2021-03-05 08:18:04 +01:00
|
|
|
// TODO use image languages if All Languages isn't toggled, but there's currently no way to get that value in here
|
|
|
|
var collection = await _tmdbClientManager.GetCollectionAsync(tmdbId, null, null, cancellationToken).ConfigureAwait(false);
|
2014-01-30 22:47:13 +01:00
|
|
|
|
2022-12-05 15:00:20 +01:00
|
|
|
if (collection?.Images is null)
|
2020-09-24 19:49:35 +02:00
|
|
|
{
|
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
2014-01-30 22:47:13 +01:00
|
|
|
}
|
|
|
|
|
2021-10-22 00:35:14 +02:00
|
|
|
var posters = collection.Images.Posters;
|
|
|
|
var backdrops = collection.Images.Backdrops;
|
|
|
|
var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count);
|
2014-01-30 22:47:13 +01:00
|
|
|
|
2023-01-11 10:36:18 +01:00
|
|
|
remoteImages.AddRange(_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language));
|
|
|
|
remoteImages.AddRange(_tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language));
|
2014-01-30 22:47:13 +01:00
|
|
|
|
2021-09-08 23:20:11 +02:00
|
|
|
return remoteImages;
|
2014-01-30 22:47:13 +01:00
|
|
|
}
|
|
|
|
|
2022-04-15 19:27:38 +02:00
|
|
|
/// <inheritdoc />
|
2020-08-17 21:10:02 +02:00
|
|
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
2014-01-30 22:47:13 +01:00
|
|
|
{
|
2020-08-31 19:05:21 +02:00
|
|
|
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
|
2014-01-30 22:47:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|