2020-06-19 20:24:13 +02:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
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;
|
2020-09-28 23:56:55 +02: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-02-09 07:08:10 +01:00
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Dto;
|
|
|
|
using MediaBrowser.Model.Entities;
|
2020-09-24 19:49:35 +02:00
|
|
|
using MediaBrowser.Model.Extensions;
|
2014-02-09 07:08:10 +01:00
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
|
2020-05-31 08:23:09 +02:00
|
|
|
namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
2014-02-09 07:08:10 +01:00
|
|
|
{
|
2019-08-18 13:20:52 +02:00
|
|
|
public class TmdbSeriesImageProvider : IRemoteImageProvider, IHasOrder
|
2014-02-09 07:08:10 +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-02-09 07:08:10 +01:00
|
|
|
|
2020-09-24 19:49:35 +02:00
|
|
|
public TmdbSeriesImageProvider(IHttpClientFactory httpClientFactory, TmdbClientManager tmdbClientManager)
|
2014-02-09 07:08:10 +01:00
|
|
|
{
|
2020-08-17 21:10:02 +02:00
|
|
|
_httpClientFactory = httpClientFactory;
|
2020-09-24 19:49:35 +02:00
|
|
|
_tmdbClientManager = tmdbClientManager;
|
2014-02-09 07:08:10 +01:00
|
|
|
}
|
|
|
|
|
2020-09-24 19:49:35 +02:00
|
|
|
public string Name => TmdbUtils.ProviderName;
|
2014-02-09 07:08:10 +01:00
|
|
|
|
2020-09-08 16:12:47 +02:00
|
|
|
// After tvdb and fanart
|
|
|
|
public int Order => 2;
|
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
public bool Supports(BaseItem item)
|
2014-02-09 07:08:10 +01:00
|
|
|
{
|
|
|
|
return item is Series;
|
|
|
|
}
|
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
2014-02-09 07:08:10 +01:00
|
|
|
{
|
|
|
|
return new List<ImageType>
|
|
|
|
{
|
2019-01-08 00:27:46 +01:00
|
|
|
ImageType.Primary,
|
2014-02-09 07:08:10 +01:00
|
|
|
ImageType.Backdrop
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
2014-02-09 07:08:10 +01:00
|
|
|
{
|
2020-09-24 19:49:35 +02:00
|
|
|
var tmdbId = item.GetProviderId(MetadataProvider.Tmdb);
|
2014-02-09 07:08:10 +01:00
|
|
|
|
2020-09-24 19:49:35 +02:00
|
|
|
if (string.IsNullOrEmpty(tmdbId))
|
2014-02-09 07:08:10 +01:00
|
|
|
{
|
2021-04-13 19:53:09 +02:00
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
2014-02-09 07:08:10 +01: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 series = await _tmdbClientManager
|
2021-03-05 08:18:04 +01:00
|
|
|
.GetSeriesAsync(Convert.ToInt32(tmdbId, CultureInfo.InvariantCulture), null, null, cancellationToken)
|
2020-09-24 19:49:35 +02:00
|
|
|
.ConfigureAwait(false);
|
2014-02-09 07:08:10 +01:00
|
|
|
|
2020-09-24 19:49:35 +02:00
|
|
|
if (series?.Images == null)
|
2014-02-09 07:08:10 +01:00
|
|
|
{
|
2020-09-27 20:13:38 +02:00
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
2014-02-09 07:08:10 +01:00
|
|
|
}
|
|
|
|
|
2020-10-06 14:54:17 +02:00
|
|
|
var posters = series.Images.Posters;
|
|
|
|
var backdrops = series.Images.Backdrops;
|
2014-02-09 07:08:10 +01:00
|
|
|
|
2020-10-06 14:54:17 +02:00
|
|
|
var remoteImages = new RemoteImageInfo[posters.Count + backdrops.Count];
|
|
|
|
|
|
|
|
for (var i = 0; i < posters.Count; i++)
|
2020-09-24 19:49:35 +02:00
|
|
|
{
|
2020-10-06 14:54:17 +02:00
|
|
|
var poster = posters[i];
|
|
|
|
remoteImages[i] = new RemoteImageInfo
|
2020-09-24 19:49:35 +02:00
|
|
|
{
|
|
|
|
Url = _tmdbClientManager.GetPosterUrl(poster.FilePath),
|
|
|
|
CommunityRating = poster.VoteAverage,
|
|
|
|
VoteCount = poster.VoteCount,
|
|
|
|
Width = poster.Width,
|
|
|
|
Height = poster.Height,
|
|
|
|
Language = TmdbUtils.AdjustImageLanguage(poster.Iso_639_1, language),
|
|
|
|
ProviderName = Name,
|
|
|
|
Type = ImageType.Primary,
|
|
|
|
RatingType = RatingType.Score
|
2020-10-06 14:54:17 +02:00
|
|
|
};
|
2020-09-24 19:49:35 +02:00
|
|
|
}
|
2014-02-09 07:08:10 +01:00
|
|
|
|
2020-10-06 14:54:17 +02:00
|
|
|
for (var i = 0; i < backdrops.Count; i++)
|
2014-02-09 07:08:10 +01:00
|
|
|
{
|
2020-09-24 19:49:35 +02:00
|
|
|
var backdrop = series.Images.Backdrops[i];
|
2020-10-06 14:54:17 +02:00
|
|
|
remoteImages[posters.Count + i] = new RemoteImageInfo
|
2020-09-24 19:49:35 +02:00
|
|
|
{
|
|
|
|
Url = _tmdbClientManager.GetBackdropUrl(backdrop.FilePath),
|
|
|
|
CommunityRating = backdrop.VoteAverage,
|
|
|
|
VoteCount = backdrop.VoteCount,
|
|
|
|
Width = backdrop.Width,
|
|
|
|
Height = backdrop.Height,
|
|
|
|
ProviderName = Name,
|
|
|
|
Type = ImageType.Backdrop,
|
|
|
|
RatingType = RatingType.Score
|
2020-10-06 14:54:17 +02:00
|
|
|
};
|
2014-02-09 07:08:10 +01:00
|
|
|
}
|
|
|
|
|
2020-09-24 19:49:35 +02:00
|
|
|
return remoteImages.OrderByLanguageDescending(language);
|
2014-02-09 07:08:10 +01:00
|
|
|
}
|
2020-05-31 08:28:01 +02:00
|
|
|
|
2020-08-17 21:10:02 +02:00
|
|
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
2014-02-09 07:08:10 +01:00
|
|
|
{
|
2020-08-31 19:05:21 +02:00
|
|
|
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
|
2014-02-09 07:08:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|