| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Globalization; |
| | | 4 | | using System.Linq; |
| | | 5 | | using System.Net.Http; |
| | | 6 | | using System.Threading; |
| | | 7 | | using System.Threading.Tasks; |
| | | 8 | | using MediaBrowser.Common.Net; |
| | | 9 | | using MediaBrowser.Controller.Entities; |
| | | 10 | | using MediaBrowser.Controller.Entities.TV; |
| | | 11 | | using MediaBrowser.Controller.Providers; |
| | | 12 | | using MediaBrowser.Model.Entities; |
| | | 13 | | using MediaBrowser.Model.Providers; |
| | | 14 | | |
| | | 15 | | namespace MediaBrowser.Providers.Plugins.Tmdb.TV |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// TV season image provider powered by TheMovieDb. |
| | | 19 | | /// </summary> |
| | | 20 | | public class TmdbSeasonImageProvider : IRemoteImageProvider, IHasOrder |
| | | 21 | | { |
| | | 22 | | private readonly IHttpClientFactory _httpClientFactory; |
| | | 23 | | private readonly TmdbClientManager _tmdbClientManager; |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Initializes a new instance of the <see cref="TmdbSeasonImageProvider"/> class. |
| | | 27 | | /// </summary> |
| | | 28 | | /// <param name="httpClientFactory">The <see cref="IHttpClientFactory"/>.</param> |
| | | 29 | | /// <param name="tmdbClientManager">The <see cref="TmdbClientManager"/>.</param> |
| | | 30 | | public TmdbSeasonImageProvider(IHttpClientFactory httpClientFactory, TmdbClientManager tmdbClientManager) |
| | | 31 | | { |
| | 21 | 32 | | _httpClientFactory = httpClientFactory; |
| | 21 | 33 | | _tmdbClientManager = tmdbClientManager; |
| | 21 | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <inheritdoc/> |
| | 0 | 37 | | public int Order => 1; |
| | | 38 | | |
| | | 39 | | /// <inheritdoc/> |
| | 0 | 40 | | public string Name => TmdbUtils.ProviderName; |
| | | 41 | | |
| | | 42 | | /// <inheritdoc /> |
| | | 43 | | public bool Supports(BaseItem item) |
| | | 44 | | { |
| | 55 | 45 | | return item is Season; |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <inheritdoc /> |
| | | 49 | | public IEnumerable<ImageType> GetSupportedImages(BaseItem item) |
| | | 50 | | { |
| | | 51 | | yield return ImageType.Primary; |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | /// <inheritdoc /> |
| | | 55 | | public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken) |
| | | 56 | | { |
| | | 57 | | var season = (Season)item; |
| | | 58 | | var series = season?.Series; |
| | | 59 | | |
| | | 60 | | var seriesTmdbId = Convert.ToInt32(series?.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCultur |
| | | 61 | | |
| | | 62 | | if (seriesTmdbId <= 0 || season?.IndexNumber is null) |
| | | 63 | | { |
| | | 64 | | return Enumerable.Empty<RemoteImageInfo>(); |
| | | 65 | | } |
| | | 66 | | |
| | | 67 | | var language = item.GetPreferredMetadataLanguage(); |
| | | 68 | | |
| | | 69 | | // TODO use image languages if All Languages isn't toggled, but there's currently no way to get that value i |
| | | 70 | | var seasonResult = await _tmdbClientManager |
| | | 71 | | .GetSeasonAsync(seriesTmdbId, season.IndexNumber.Value, null, null, null, cancellationToken) |
| | | 72 | | .ConfigureAwait(false); |
| | | 73 | | |
| | | 74 | | var posters = seasonResult?.Images?.Posters; |
| | | 75 | | if (posters is null) |
| | | 76 | | { |
| | | 77 | | return Enumerable.Empty<RemoteImageInfo>(); |
| | | 78 | | } |
| | | 79 | | |
| | | 80 | | return _tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language); |
| | | 81 | | } |
| | | 82 | | |
| | | 83 | | /// <inheritdoc /> |
| | | 84 | | public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken) |
| | | 85 | | { |
| | 0 | 86 | | return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken); |
| | | 87 | | } |
| | | 88 | | } |
| | | 89 | | } |