| | 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 series image provider powered by TheMovieDb. |
| | 19 | | /// </summary> |
| | 20 | | public class TmdbSeriesImageProvider : 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="TmdbSeriesImageProvider"/> class. |
| | 27 | | /// </summary> |
| | 28 | | /// <param name="httpClientFactory">The <see cref="IHttpClientFactory"/>.</param> |
| | 29 | | /// <param name="tmdbClientManager">The <see cref="TmdbClientManager"/>.</param> |
| | 30 | | public TmdbSeriesImageProvider(IHttpClientFactory httpClientFactory, TmdbClientManager tmdbClientManager) |
| | 31 | | { |
| 21 | 32 | | _httpClientFactory = httpClientFactory; |
| 21 | 33 | | _tmdbClientManager = tmdbClientManager; |
| 21 | 34 | | } |
| | 35 | |
|
| | 36 | | /// <inheritdoc /> |
| 0 | 37 | | public string Name => TmdbUtils.ProviderName; |
| | 38 | |
|
| | 39 | | /// <inheritdoc /> |
| 0 | 40 | | public int Order => 2; |
| | 41 | |
|
| | 42 | | /// <inheritdoc /> |
| | 43 | | public bool Supports(BaseItem item) |
| | 44 | | { |
| 53 | 45 | | return item is Series; |
| | 46 | | } |
| | 47 | |
|
| | 48 | | /// <inheritdoc /> |
| | 49 | | public IEnumerable<ImageType> GetSupportedImages(BaseItem item) => |
| 0 | 50 | | [ |
| 0 | 51 | | ImageType.Primary, |
| 0 | 52 | | ImageType.Backdrop, |
| 0 | 53 | | ImageType.Logo, |
| 0 | 54 | | ImageType.Thumb |
| 0 | 55 | | ]; |
| | 56 | |
|
| | 57 | | /// <inheritdoc /> |
| | 58 | | public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken) |
| | 59 | | { |
| | 60 | | var tmdbId = item.GetProviderId(MetadataProvider.Tmdb); |
| | 61 | |
|
| | 62 | | if (string.IsNullOrEmpty(tmdbId)) |
| | 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 series = await _tmdbClientManager |
| | 71 | | .GetSeriesAsync(Convert.ToInt32(tmdbId, CultureInfo.InvariantCulture), null, null, cancellationToken) |
| | 72 | | .ConfigureAwait(false); |
| | 73 | |
|
| | 74 | | if (series?.Images is null) |
| | 75 | | { |
| | 76 | | return Enumerable.Empty<RemoteImageInfo>(); |
| | 77 | | } |
| | 78 | |
|
| | 79 | | var posters = series.Images.Posters; |
| | 80 | | var backdrops = series.Images.Backdrops; |
| | 81 | | var logos = series.Images.Logos; |
| | 82 | | var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count + logos.Count); |
| | 83 | |
|
| | 84 | | remoteImages.AddRange(_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language)); |
| | 85 | | remoteImages.AddRange(_tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language)); |
| | 86 | | remoteImages.AddRange(_tmdbClientManager.ConvertLogosToRemoteImageInfo(logos, language)); |
| | 87 | |
|
| | 88 | | return remoteImages; |
| | 89 | | } |
| | 90 | |
|
| | 91 | | /// <inheritdoc /> |
| | 92 | | public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken) |
| | 93 | | { |
| 0 | 94 | | return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken); |
| | 95 | | } |
| | 96 | | } |
| | 97 | | } |