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