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-09-24 19:49:35 +02:00
|
|
|
using MediaBrowser.Common.Net;
|
2014-07-07 16:23:08 +02:00
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
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.TV
|
2014-07-07 16:23:08 +02:00
|
|
|
{
|
2022-04-15 19:27:38 +02:00
|
|
|
/// <summary>
|
2022-04-27 13:08:54 +02:00
|
|
|
/// TV episode image provider powered by TheMovieDb.
|
2022-04-15 19:27:38 +02:00
|
|
|
/// </summary>
|
2020-09-24 19:49:35 +02:00
|
|
|
public class TmdbEpisodeImageProvider : IRemoteImageProvider, IHasOrder
|
2014-07-07 16:23:08 +02:00
|
|
|
{
|
2020-09-24 19:49:35 +02:00
|
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
|
|
private readonly TmdbClientManager _tmdbClientManager;
|
|
|
|
|
2022-04-15 19:27:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="TmdbEpisodeImageProvider"/> 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 TmdbEpisodeImageProvider(IHttpClientFactory httpClientFactory, TmdbClientManager tmdbClientManager)
|
2020-09-08 16:12:47 +02:00
|
|
|
{
|
2020-09-24 19:49:35 +02:00
|
|
|
_httpClientFactory = httpClientFactory;
|
|
|
|
_tmdbClientManager = tmdbClientManager;
|
2020-09-08 16:12:47 +02:00
|
|
|
}
|
|
|
|
|
2022-04-15 19:27:38 +02:00
|
|
|
/// <inheritdoc />
|
2020-09-08 16:12:47 +02:00
|
|
|
public int Order => 1;
|
2014-07-07 16:23:08 +02:00
|
|
|
|
2022-04-15 19:27:38 +02:00
|
|
|
/// <inheritdoc />
|
2020-09-24 19:49:35 +02:00
|
|
|
public string Name => TmdbUtils.ProviderName;
|
|
|
|
|
2022-04-15 19:27:38 +02:00
|
|
|
/// <inheritdoc />
|
|
|
|
public bool Supports(BaseItem item)
|
|
|
|
{
|
|
|
|
return item is Controller.Entities.TV.Episode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2018-09-12 19:26:21 +02:00
|
|
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
2014-07-07 16:23:08 +02:00
|
|
|
{
|
|
|
|
return new List<ImageType>
|
|
|
|
{
|
|
|
|
ImageType.Primary
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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-07-07 16:23:08 +02:00
|
|
|
{
|
|
|
|
var episode = (Controller.Entities.TV.Episode)item;
|
|
|
|
var series = episode.Series;
|
|
|
|
|
2020-09-24 19:49:35 +02:00
|
|
|
var seriesTmdbId = Convert.ToInt32(series?.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);
|
2014-07-07 16:23:08 +02:00
|
|
|
|
2023-02-23 19:09:16 +01:00
|
|
|
if (series == null || seriesTmdbId <= 0)
|
2014-07-07 16:23:08 +02:00
|
|
|
{
|
2020-09-24 19:49:35 +02:00
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
2014-07-07 16:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var seasonNumber = episode.ParentIndexNumber;
|
|
|
|
var episodeNumber = episode.IndexNumber;
|
|
|
|
|
|
|
|
if (!seasonNumber.HasValue || !episodeNumber.HasValue)
|
|
|
|
{
|
2020-09-24 19:49:35 +02:00
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
2014-07-07 16:23:08 +02:00
|
|
|
}
|
|
|
|
|
2016-06-25 01:53:38 +02:00
|
|
|
var language = item.GetPreferredMetadataLanguage();
|
|
|
|
|
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
|
2020-09-24 19:49:35 +02:00
|
|
|
var episodeResult = await _tmdbClientManager
|
2021-04-09 18:02:23 +02:00
|
|
|
.GetEpisodeAsync(seriesTmdbId, seasonNumber.Value, episodeNumber.Value, series.DisplayOrder, null, null, cancellationToken)
|
2020-09-24 19:49:35 +02:00
|
|
|
.ConfigureAwait(false);
|
2014-07-07 16:23:08 +02:00
|
|
|
|
2020-10-06 14:54:17 +02:00
|
|
|
var stills = episodeResult?.Images?.Stills;
|
2022-12-05 15:00:20 +01:00
|
|
|
if (stills is null)
|
2014-07-07 16:23:08 +02:00
|
|
|
{
|
2020-09-24 19:49:35 +02:00
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
|
|
|
}
|
2020-05-31 08:28:01 +02:00
|
|
|
|
2023-01-11 10:36:18 +01:00
|
|
|
return _tmdbClientManager.ConvertStillsToRemoteImageInfo(stills, language);
|
2014-07-07 16:23:08 +02: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-07-07 16:23:08 +02:00
|
|
|
{
|
2020-09-24 19:49:35 +02:00
|
|
|
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
|
2014-07-07 16:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|