2020-06-19 11:24:13 -07:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-12-18 09:18:55 -07:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2020-09-24 10:49:35 -07:00
|
|
|
using System.Globalization;
|
2019-12-18 09:18:55 -07:00
|
|
|
using System.Linq;
|
2020-08-17 12:10:02 -07:00
|
|
|
using System.Net.Http;
|
2019-12-18 09:18:55 -07:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2020-08-31 10:05:21 -07:00
|
|
|
using MediaBrowser.Common.Net;
|
2019-12-18 09:18:55 -07: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 10:49:35 -07:00
|
|
|
using MediaBrowser.Model.Extensions;
|
2019-12-18 09:18:55 -07:00
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
|
2020-05-30 23:23:09 -07:00
|
|
|
namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
2019-12-18 09:18:55 -07:00
|
|
|
{
|
|
|
|
public class TmdbSeasonImageProvider : IRemoteImageProvider, IHasOrder
|
|
|
|
{
|
2020-08-17 12:10:02 -07:00
|
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
2020-09-24 10:49:35 -07:00
|
|
|
private readonly TmdbClientManager _tmdbClientManager;
|
2019-12-18 09:18:55 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
public TmdbSeasonImageProvider(IHttpClientFactory httpClientFactory, TmdbClientManager tmdbClientManager)
|
2019-12-18 09:18:55 -07:00
|
|
|
{
|
2020-08-17 12:10:02 -07:00
|
|
|
_httpClientFactory = httpClientFactory;
|
2020-09-24 10:49:35 -07:00
|
|
|
_tmdbClientManager = tmdbClientManager;
|
2019-12-18 09:18:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public int Order => 1;
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
public string Name => TmdbUtils.ProviderName;
|
2019-12-18 09:18:55 -07:00
|
|
|
|
2020-08-17 12:10:02 -07:00
|
|
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
2019-12-18 09:18:55 -07:00
|
|
|
{
|
2020-08-31 10:05:21 -07:00
|
|
|
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
|
2019-12-18 09:18:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
var season = (Season)item;
|
2020-09-24 10:49:35 -07:00
|
|
|
var series = season?.Series;
|
2019-12-18 09:18:55 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
var seriesTmdbId = Convert.ToInt32(series?.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);
|
2019-12-18 09:18:55 -07:00
|
|
|
|
2020-09-24 11:18:45 -07:00
|
|
|
if (seriesTmdbId <= 0 || season?.IndexNumber == null)
|
2019-12-18 09:18:55 -07:00
|
|
|
{
|
2019-12-19 10:59:55 -07:00
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
2019-12-18 09:18:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var language = item.GetPreferredMetadataLanguage();
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
var seasonResult = await _tmdbClientManager
|
|
|
|
.GetSeasonAsync(seriesTmdbId, season.IndexNumber.Value, language, TmdbUtils.GetImageLanguagesParam(language), cancellationToken)
|
|
|
|
.ConfigureAwait(false);
|
2019-12-18 09:18:55 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (seasonResult?.Images?.Posters == null)
|
2019-12-18 09:18:55 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
return Enumerable.Empty<RemoteImageInfo>();
|
|
|
|
}
|
2019-12-18 09:18:55 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
var remoteImages = new List<RemoteImageInfo>();
|
|
|
|
for (var i = 0; i < seasonResult.Images.Posters.Count; i++)
|
2019-12-18 09:18:55 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
var image = seasonResult.Images.Posters[i];
|
|
|
|
remoteImages.Add(new RemoteImageInfo
|
2019-12-18 09:18:55 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
Url = _tmdbClientManager.GetPosterUrl(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
|
|
|
|
});
|
2019-12-18 09:18:55 -07:00
|
|
|
}
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
return remoteImages.OrderByLanguageDescending(language);
|
2019-12-18 09:18:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
|
|
|
{
|
|
|
|
return new List<ImageType>
|
|
|
|
{
|
|
|
|
ImageType.Primary
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Supports(BaseItem item)
|
|
|
|
{
|
|
|
|
return item is Season;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|