| | | 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.Movies; |
| | | 11 | | using MediaBrowser.Controller.Providers; |
| | | 12 | | using MediaBrowser.Model.Entities; |
| | | 13 | | using MediaBrowser.Model.Providers; |
| | | 14 | | |
| | | 15 | | namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// BoxSet image provider powered by TMDb. |
| | | 19 | | /// </summary> |
| | | 20 | | public class TmdbBoxSetImageProvider : 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="TmdbBoxSetImageProvider"/> class. |
| | | 27 | | /// </summary> |
| | | 28 | | /// <param name="httpClientFactory">The <see cref="IHttpClientFactory"/>.</param> |
| | | 29 | | /// <param name="tmdbClientManager">The <see cref="TmdbClientManager"/>.</param> |
| | | 30 | | public TmdbBoxSetImageProvider(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 => 0; |
| | | 41 | | |
| | | 42 | | /// <inheritdoc /> |
| | | 43 | | public bool Supports(BaseItem item) |
| | | 44 | | { |
| | 55 | 45 | | return item is BoxSet; |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <inheritdoc /> |
| | | 49 | | public IEnumerable<ImageType> GetSupportedImages(BaseItem item) => |
| | 0 | 50 | | [ |
| | 0 | 51 | | ImageType.Primary, |
| | 0 | 52 | | ImageType.Backdrop, |
| | 0 | 53 | | ImageType.Thumb |
| | 0 | 54 | | ]; |
| | | 55 | | |
| | | 56 | | /// <inheritdoc /> |
| | | 57 | | public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken) |
| | | 58 | | { |
| | | 59 | | var tmdbId = Convert.ToInt32(item.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture); |
| | | 60 | | |
| | | 61 | | if (tmdbId <= 0) |
| | | 62 | | { |
| | | 63 | | return Enumerable.Empty<RemoteImageInfo>(); |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | var language = item.GetPreferredMetadataLanguage(); |
| | | 67 | | |
| | | 68 | | // TODO use image languages if All Languages isn't toggled, but there's currently no way to get that value i |
| | | 69 | | var collection = await _tmdbClientManager.GetCollectionAsync(tmdbId, null, null, null, cancellationToken).Co |
| | | 70 | | |
| | | 71 | | if (collection?.Images is null) |
| | | 72 | | { |
| | | 73 | | return Enumerable.Empty<RemoteImageInfo>(); |
| | | 74 | | } |
| | | 75 | | |
| | | 76 | | var posters = collection.Images.Posters; |
| | | 77 | | var backdrops = collection.Images.Backdrops; |
| | | 78 | | var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count); |
| | | 79 | | |
| | | 80 | | remoteImages.AddRange(_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language)); |
| | | 81 | | remoteImages.AddRange(_tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language)); |
| | | 82 | | |
| | | 83 | | return remoteImages; |
| | | 84 | | } |
| | | 85 | | |
| | | 86 | | /// <inheritdoc /> |
| | | 87 | | public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken) |
| | | 88 | | { |
| | 0 | 89 | | return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken); |
| | | 90 | | } |
| | | 91 | | } |
| | | 92 | | } |