Move ConvertToRemoteImage to TmdbClientManager

pull/6763/head
Joe Rogers 3 years ago
parent 2b283d249f
commit 4fc0521d69
No known key found for this signature in database
GPG Key ID: 0074AD57B8FDBBB4

@ -13,7 +13,6 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
@ -71,8 +70,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
var backdrops = collection.Images.Backdrops;
var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count);
TmdbUtils.ConvertPostersToRemoteImageInfo(posters, _tmdbClientManager, language, remoteImages);
TmdbUtils.ConvertBackdropsToRemoteImageInfo(backdrops, _tmdbClientManager, language, remoteImages);
_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages);
_tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language, remoteImages);
return remoteImages;
}

@ -87,8 +87,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
var backdrops = movie.Images.Backdrops;
var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count);
TmdbUtils.ConvertPostersToRemoteImageInfo(posters, _tmdbClientManager, language, remoteImages);
TmdbUtils.ConvertBackdropsToRemoteImageInfo(backdrops, _tmdbClientManager, language, remoteImages);
_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages);
_tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language, remoteImages);
return remoteImages;
}

@ -63,7 +63,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
var profiles = personResult.Images.Profiles;
var remoteImages = new List<RemoteImageInfo>(profiles.Count);
TmdbUtils.ConvertProfilesToRemoteImageInfo(profiles, _tmdbClientManager, language, remoteImages);
_tmdbClientManager.ConvertProfilesToRemoteImageInfo(profiles, language, remoteImages);
return remoteImages;
}

@ -76,7 +76,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
var remoteImages = new List<RemoteImageInfo>(stills.Count);
TmdbUtils.ConvertStillsToRemoteImageInfo(stills, _tmdbClientManager, language, remoteImages);
_tmdbClientManager.ConvertStillsToRemoteImageInfo(stills, language, remoteImages);
return remoteImages;
}

@ -63,7 +63,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
var remoteImages = new List<RemoteImageInfo>(posters.Count);
TmdbUtils.ConvertPostersToRemoteImageInfo(posters, _tmdbClientManager, language, remoteImages);
_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages);
return remoteImages;
}

@ -71,8 +71,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
var backdrops = series.Images.Backdrops;
var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count);
TmdbUtils.ConvertPostersToRemoteImageInfo(posters, _tmdbClientManager, language, remoteImages);
TmdbUtils.ConvertBackdropsToRemoteImageInfo(backdrops, _tmdbClientManager, language, remoteImages);
_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages);
_tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language, remoteImages);
return remoteImages;
}

@ -5,6 +5,9 @@ using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using Microsoft.Extensions.Caching.Memory;
using TMDbLib.Client;
using TMDbLib.Objects.Collections;
@ -497,33 +500,85 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
}
/// <summary>
/// Gets the absolute URL of the backdrop image.
/// Gets the absolute URL of the profile image.
/// </summary>
/// <param name="backdropPath">The relative URL of the backdrop image.</param>
/// <param name="actorProfilePath">The relative URL of the profile image.</param>
/// <returns>The absolute URL.</returns>
public string GetBackdropUrl(string backdropPath)
public string GetProfileUrl(string actorProfilePath)
{
return GetUrl(_tmDbClient.Config.Images.BackdropSizes[^1], backdropPath);
return GetUrl(_tmDbClient.Config.Images.ProfileSizes[^1], actorProfilePath);
}
/// <summary>
/// Gets the absolute URL of the profile image.
/// Converts poster <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s.
/// </summary>
/// <param name="actorProfilePath">The relative URL of the profile image.</param>
/// <returns>The absolute URL.</returns>
public string GetProfileUrl(string actorProfilePath)
/// <param name="images">The input images.</param>
/// <param name="requestLanguage">The requested language.</param>
/// <param name="results">The collection to add the remote images into.</param>
public void ConvertPostersToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results)
{
return GetUrl(_tmDbClient.Config.Images.ProfileSizes[^1], actorProfilePath);
ConvertToRemoteImageInfo(images, _tmDbClient.Config.Images.PosterSizes[^1], ImageType.Primary, requestLanguage, results);
}
/// <summary>
/// Gets the absolute URL of the still image.
/// Converts backdrop <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s.
/// </summary>
/// <param name="filePath">The relative URL of the still image.</param>
/// <returns>The absolute URL.</returns>
public string GetStillUrl(string filePath)
/// <param name="images">The input images.</param>
/// <param name="requestLanguage">The requested language.</param>
/// <param name="results">The collection to add the remote images into.</param>
public void ConvertBackdropsToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results)
{
ConvertToRemoteImageInfo(images, _tmDbClient.Config.Images.BackdropSizes[^1], ImageType.Backdrop, requestLanguage, results);
}
/// <summary>
/// Converts profile <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s.
/// </summary>
/// <param name="images">The input images.</param>
/// <param name="requestLanguage">The requested language.</param>
/// <param name="results">The collection to add the remote images into.</param>
public void ConvertProfilesToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results)
{
ConvertToRemoteImageInfo(images, _tmDbClient.Config.Images.ProfileSizes[^1], ImageType.Primary, requestLanguage, results);
}
/// <summary>
/// Converts still <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s.
/// </summary>
/// <param name="images">The input images.</param>
/// <param name="requestLanguage">The requested language.</param>
/// <param name="results">The collection to add the remote images into.</param>
public void ConvertStillsToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results)
{
ConvertToRemoteImageInfo(images, _tmDbClient.Config.Images.StillSizes[^1], ImageType.Primary, requestLanguage, results);
}
/// <summary>
/// Converts <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s.
/// </summary>
/// <param name="images">The input images.</param>
/// <param name="size">The size of the image to fetch.</param>
/// <param name="type">The type of the image.</param>
/// <param name="requestLanguage">The requested language.</param>
/// <param name="results">The collection to add the remote images into.</param>
private void ConvertToRemoteImageInfo(List<ImageData> images, string size, ImageType type, string requestLanguage, List<RemoteImageInfo> results)
{
return GetUrl(_tmDbClient.Config.Images.StillSizes[^1], filePath);
for (var i = 0; i < images.Count; i++)
{
var image = images[i];
results.Add(new RemoteImageInfo
{
Url = GetUrl(size, image.FilePath),
CommunityRating = image.VoteAverage,
VoteCount = image.VoteCount,
Width = image.Width,
Height = image.Height,
Language = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, requestLanguage),
ProviderName = TmdbUtils.ProviderName,
Type = type,
RatingType = RatingType.Score
});
}
}
private Task EnsureClientConfigAsync()

@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using TMDbLib.Objects.General;
namespace MediaBrowser.Providers.Plugins.Tmdb
@ -194,81 +192,5 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
return newRating.Replace("DE-", "FSK-", StringComparison.OrdinalIgnoreCase);
}
/// <summary>
/// Converts poster <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s.
/// </summary>
/// <param name="images">The input images.</param>
/// <param name="tmdbClientManager">The client manager to use for resolving image urls.</param>
/// <param name="requestLanguage">The requested language.</param>
/// <param name="results">The collection to add the remote images into.</param>
public static void ConvertPostersToRemoteImageInfo(List<ImageData> images, TmdbClientManager tmdbClientManager, string requestLanguage, List<RemoteImageInfo> results)
{
ConvertToRemoteImageInfo(images, tmdbClientManager.GetPosterUrl, ImageType.Primary, requestLanguage, results);
}
/// <summary>
/// Converts backdrop <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s.
/// </summary>
/// <param name="images">The input images.</param>
/// <param name="tmdbClientManager">The client manager to use for resolving image urls.</param>
/// <param name="requestLanguage">The requested language.</param>
/// <param name="results">The collection to add the remote images into.</param>
public static void ConvertBackdropsToRemoteImageInfo(List<ImageData> images, TmdbClientManager tmdbClientManager, string requestLanguage, List<RemoteImageInfo> results)
{
ConvertToRemoteImageInfo(images, tmdbClientManager.GetBackdropUrl, ImageType.Backdrop, requestLanguage, results);
}
/// <summary>
/// Converts profile <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s.
/// </summary>
/// <param name="images">The input images.</param>
/// <param name="tmdbClientManager">The client manager to use for resolving image urls.</param>
/// <param name="requestLanguage">The requested language.</param>
/// <param name="results">The collection to add the remote images into.</param>
public static void ConvertProfilesToRemoteImageInfo(List<ImageData> images, TmdbClientManager tmdbClientManager, string requestLanguage, List<RemoteImageInfo> results)
{
ConvertToRemoteImageInfo(images, tmdbClientManager.GetProfileUrl, ImageType.Primary, requestLanguage, results);
}
/// <summary>
/// Converts still <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s.
/// </summary>
/// <param name="images">The input images.</param>
/// <param name="tmdbClientManager">The client manager to use for resolving image urls.</param>
/// <param name="requestLanguage">The requested language.</param>
/// <param name="results">The collection to add the remote images into.</param>
public static void ConvertStillsToRemoteImageInfo(List<ImageData> images, TmdbClientManager tmdbClientManager, string requestLanguage, List<RemoteImageInfo> results)
{
ConvertToRemoteImageInfo(images, tmdbClientManager.GetStillUrl, ImageType.Primary, requestLanguage, results);
}
/// <summary>
/// Converts <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s.
/// </summary>
/// <param name="images">The input images.</param>
/// <param name="imageUrlConverter">The relevant <see cref="TmdbClientManager"/> Get<i>Type</i>Url function to get the absolute url of the image.</param>
/// <param name="type">The type of the image.</param>
/// <param name="requestLanguage">The requested language.</param>
/// <param name="results">The collection to add the remote images into.</param>
private static void ConvertToRemoteImageInfo(List<ImageData> images, Func<string, string> imageUrlConverter, ImageType type, string requestLanguage, List<RemoteImageInfo> results)
{
for (var i = 0; i < images.Count; i++)
{
var image = images[i];
results.Add(new RemoteImageInfo
{
Url = imageUrlConverter(image.FilePath),
CommunityRating = image.VoteAverage,
VoteCount = image.VoteCount,
Width = image.Width,
Height = image.Height,
Language = AdjustImageLanguage(image.Iso_639_1, requestLanguage),
ProviderName = ProviderName,
Type = type,
RatingType = RatingType.Score
});
}
}
}
}

Loading…
Cancel
Save