aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs')
-rw-r--r--MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs143
1 files changed, 46 insertions, 97 deletions
diff --git a/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs
index f6592afe4..df1e12240 100644
--- a/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs
+++ b/MediaBrowser.Providers/Plugins/Tmdb/BoxSets/TmdbBoxSetImageProvider.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Threading;
@@ -12,25 +13,25 @@ using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
+using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Providers;
-using MediaBrowser.Providers.Plugins.Tmdb.Models.Collections;
-using MediaBrowser.Providers.Plugins.Tmdb.Models.General;
-using MediaBrowser.Providers.Plugins.Tmdb.Movies;
namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
{
public class TmdbBoxSetImageProvider : IRemoteImageProvider, IHasOrder
{
private readonly IHttpClientFactory _httpClientFactory;
+ private readonly TmdbClientManager _tmdbClientManager;
- public TmdbBoxSetImageProvider(IHttpClientFactory httpClientFactory)
+ public TmdbBoxSetImageProvider(IHttpClientFactory httpClientFactory, TmdbClientManager tmdbClientManager)
{
_httpClientFactory = httpClientFactory;
+ _tmdbClientManager = tmdbClientManager;
}
- public string Name => ProviderName;
+ public string Name => TmdbUtils.ProviderName;
- public static string ProviderName => TmdbUtils.ProviderName;
+ public int Order => 0;
public bool Supports(BaseItem item)
{
@@ -48,112 +49,60 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
- var tmdbId = item.GetProviderId(MetadataProvider.Tmdb);
+ var tmdbId = Convert.ToInt32(item.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);
- if (!string.IsNullOrEmpty(tmdbId))
+ if (tmdbId <= 0)
{
- var language = item.GetPreferredMetadataLanguage();
-
- var mainResult = await TmdbBoxSetProvider.Current.GetMovieDbResult(tmdbId, null, cancellationToken).ConfigureAwait(false);
+ return Enumerable.Empty<RemoteImageInfo>();
+ }
- if (mainResult != null)
- {
- var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
+ var language = item.GetPreferredMetadataLanguage();
- var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
+ var collection = await _tmdbClientManager.GetCollectionAsync(tmdbId, language, TmdbUtils.GetImageLanguagesParam(language), cancellationToken).ConfigureAwait(false);
- return GetImages(mainResult, language, tmdbImageUrl);
- }
+ if (collection?.Images == null)
+ {
+ return Enumerable.Empty<RemoteImageInfo>();
}
- return new List<RemoteImageInfo>();
- }
+ var remoteImages = new List<RemoteImageInfo>();
- private IEnumerable<RemoteImageInfo> GetImages(CollectionResult obj, string language, string baseUrl)
- {
- var list = new List<RemoteImageInfo>();
-
- var images = obj.Images ?? new CollectionImages();
-
- list.AddRange(GetPosters(images).Select(i => new RemoteImageInfo
- {
- Url = baseUrl + i.File_Path,
- CommunityRating = i.Vote_Average,
- VoteCount = i.Vote_Count,
- Width = i.Width,
- Height = i.Height,
- Language = TmdbMovieProvider.AdjustImageLanguage(i.Iso_639_1, language),
- ProviderName = Name,
- Type = ImageType.Primary,
- RatingType = RatingType.Score
- }));
-
- list.AddRange(GetBackdrops(images).Select(i => new RemoteImageInfo
+ for (var i = 0; i < collection.Images.Posters.Count; i++)
{
- Url = baseUrl + i.File_Path,
- CommunityRating = i.Vote_Average,
- VoteCount = i.Vote_Count,
- Width = i.Width,
- Height = i.Height,
- ProviderName = Name,
- Type = ImageType.Backdrop,
- RatingType = RatingType.Score
- }));
-
- var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase);
-
- return list.OrderByDescending(i =>
- {
- if (string.Equals(language, i.Language, StringComparison.OrdinalIgnoreCase))
- {
- return 3;
- }
-
- if (!isLanguageEn)
+ var poster = collection.Images.Posters[i];
+ remoteImages.Add(new RemoteImageInfo
{
- if (string.Equals("en", i.Language, StringComparison.OrdinalIgnoreCase))
- {
- return 2;
- }
- }
+ Url = _tmdbClientManager.GetPosterUrl(poster.FilePath),
+ CommunityRating = poster.VoteAverage,
+ VoteCount = poster.VoteCount,
+ Width = poster.Width,
+ Height = poster.Height,
+ Language = TmdbUtils.AdjustImageLanguage(poster.Iso_639_1, language),
+ ProviderName = Name,
+ Type = ImageType.Primary,
+ RatingType = RatingType.Score
+ });
+ }
- if (string.IsNullOrEmpty(i.Language))
+ for (var i = 0; i < collection.Images.Backdrops.Count; i++)
+ {
+ var backdrop = collection.Images.Backdrops[i];
+ remoteImages.Add(new RemoteImageInfo
{
- return isLanguageEn ? 3 : 2;
- }
-
- return 0;
- })
- .ThenByDescending(i => i.CommunityRating ?? 0)
- .ThenByDescending(i => i.VoteCount ?? 0);
- }
-
- /// <summary>
- /// Gets the posters.
- /// </summary>
- /// <param name="images">The images.</param>
- /// <returns>IEnumerable{MovieDbProvider.Poster}.</returns>
- private IEnumerable<Poster> GetPosters(CollectionImages images)
- {
- return images.Posters ?? new List<Poster>();
- }
-
- /// <summary>
- /// Gets the backdrops.
- /// </summary>
- /// <param name="images">The images.</param>
- /// <returns>IEnumerable{MovieDbProvider.Backdrop}.</returns>
- private IEnumerable<Backdrop> GetBackdrops(CollectionImages images)
- {
- var eligibleBackdrops = images.Backdrops == null ? new List<Backdrop>() :
- images.Backdrops;
+ Url = _tmdbClientManager.GetBackdropUrl(backdrop.FilePath),
+ CommunityRating = backdrop.VoteAverage,
+ VoteCount = backdrop.VoteCount,
+ Width = backdrop.Width,
+ Height = backdrop.Height,
+ ProviderName = Name,
+ Type = ImageType.Backdrop,
+ RatingType = RatingType.Score
+ });
+ }
- return eligibleBackdrops.OrderByDescending(i => i.Vote_Average)
- .ThenByDescending(i => i.Vote_Count);
+ return remoteImages.OrderByLanguageDescending(language);
}
- public int Order => 0;
-
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);