2021-10-26 06:49:01 -07:00
|
|
|
#nullable disable
|
|
|
|
|
2020-06-19 11:24:13 -07:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 13:03:10 -07:00
|
|
|
using System;
|
2019-01-13 12:26:31 -07:00
|
|
|
using System.Collections.Generic;
|
2020-09-24 10:49:35 -07:00
|
|
|
using System.Globalization;
|
2019-01-13 12:26:31 -07:00
|
|
|
using System.Linq;
|
2020-08-17 12:10:02 -07:00
|
|
|
using System.Net.Http;
|
2019-01-13 12:26:31 -07:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2020-09-24 10:49:35 -07:00
|
|
|
using MediaBrowser.Common.Net;
|
2014-07-07 07:23:08 -07:00
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Dto;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
|
2020-05-30 23:23:09 -07:00
|
|
|
namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
2014-07-07 07:23:08 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
public class TmdbEpisodeImageProvider : IRemoteImageProvider, IHasOrder
|
2014-07-07 07:23:08 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
|
|
private readonly TmdbClientManager _tmdbClientManager;
|
|
|
|
|
|
|
|
public TmdbEpisodeImageProvider(IHttpClientFactory httpClientFactory, TmdbClientManager tmdbClientManager)
|
2020-09-08 07:12:47 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
_httpClientFactory = httpClientFactory;
|
|
|
|
_tmdbClientManager = tmdbClientManager;
|
2020-09-08 07:12:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// After TheTvDb
|
|
|
|
public int Order => 1;
|
2014-07-07 07:23:08 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
public string Name => TmdbUtils.ProviderName;
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
2014-07-07 07:23:08 -07:00
|
|
|
{
|
|
|
|
return new List<ImageType>
|
|
|
|
{
|
|
|
|
ImageType.Primary
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
2014-07-07 07:23:08 -07:00
|
|
|
{
|
|
|
|
var episode = (Controller.Entities.TV.Episode)item;
|
|
|
|
var series = episode.Series;
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
var seriesTmdbId = Convert.ToInt32(series?.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);
|
2014-07-07 07:23:08 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (seriesTmdbId <= 0)
|
2014-07-07 07:23:08 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
2014-07-07 07:23:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var seasonNumber = episode.ParentIndexNumber;
|
|
|
|
var episodeNumber = episode.IndexNumber;
|
|
|
|
|
|
|
|
if (!seasonNumber.HasValue || !episodeNumber.HasValue)
|
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
2014-07-07 07:23:08 -07:00
|
|
|
}
|
|
|
|
|
2016-06-24 16:53:38 -07:00
|
|
|
var language = item.GetPreferredMetadataLanguage();
|
|
|
|
|
2021-03-05 00:18:04 -07: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 10:49:35 -07:00
|
|
|
var episodeResult = await _tmdbClientManager
|
2021-04-09 09:02:23 -07:00
|
|
|
.GetEpisodeAsync(seriesTmdbId, seasonNumber.Value, episodeNumber.Value, series.DisplayOrder, null, null, cancellationToken)
|
2020-09-24 10:49:35 -07:00
|
|
|
.ConfigureAwait(false);
|
2014-07-07 07:23:08 -07:00
|
|
|
|
2020-10-06 05:54:17 -07:00
|
|
|
var stills = episodeResult?.Images?.Stills;
|
|
|
|
if (stills == null)
|
2014-07-07 07:23:08 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
|
|
|
}
|
2020-05-30 23:28:01 -07:00
|
|
|
|
2020-10-06 05:54:17 -07:00
|
|
|
var remoteImages = new RemoteImageInfo[stills.Count];
|
|
|
|
for (var i = 0; i < stills.Count; i++)
|
2020-09-24 10:49:35 -07:00
|
|
|
{
|
2020-10-06 05:54:17 -07:00
|
|
|
var image = stills[i];
|
|
|
|
remoteImages[i] = new RemoteImageInfo
|
2014-07-07 07:23:08 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
Url = _tmdbClientManager.GetStillUrl(image.FilePath),
|
|
|
|
CommunityRating = image.VoteAverage,
|
|
|
|
VoteCount = image.VoteCount,
|
|
|
|
Width = image.Width,
|
|
|
|
Height = image.Height,
|
|
|
|
Language = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, language),
|
|
|
|
ProviderName = Name,
|
|
|
|
Type = ImageType.Primary,
|
|
|
|
RatingType = RatingType.Score
|
2020-10-06 05:54:17 -07:00
|
|
|
};
|
2020-09-24 10:49:35 -07:00
|
|
|
}
|
2014-07-07 07:23:08 -07:00
|
|
|
|
2021-09-08 14:20:11 -07:00
|
|
|
return remoteImages;
|
2014-07-07 07:23:08 -07:00
|
|
|
}
|
|
|
|
|
2020-08-17 12:10:02 -07:00
|
|
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
2014-07-07 07:23:08 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
|
2014-07-07 07:23:08 -07:00
|
|
|
}
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
public bool Supports(BaseItem item)
|
2014-07-07 07:23:08 -07:00
|
|
|
{
|
|
|
|
return item is Controller.Entities.TV.Episode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|