Switch to method per image conversion
This commit is contained in:
parent
4a5e8b99a0
commit
2b283d249f
|
@ -71,8 +71,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
|
|||
var backdrops = collection.Images.Backdrops;
|
||||
var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count);
|
||||
|
||||
TmdbUtils.ConvertToRemoteImageInfo(posters, _tmdbClientManager.GetPosterUrl, ImageType.Primary, language, remoteImages);
|
||||
TmdbUtils.ConvertToRemoteImageInfo(backdrops, _tmdbClientManager.GetBackdropUrl, ImageType.Backdrop, language, remoteImages);
|
||||
TmdbUtils.ConvertPostersToRemoteImageInfo(posters, _tmdbClientManager, language, remoteImages);
|
||||
TmdbUtils.ConvertBackdropsToRemoteImageInfo(backdrops, _tmdbClientManager, 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.ConvertToRemoteImageInfo(posters, _tmdbClientManager.GetPosterUrl, ImageType.Primary, language, remoteImages);
|
||||
TmdbUtils.ConvertToRemoteImageInfo(backdrops, _tmdbClientManager.GetBackdropUrl, ImageType.Backdrop, language, remoteImages);
|
||||
TmdbUtils.ConvertPostersToRemoteImageInfo(posters, _tmdbClientManager, language, remoteImages);
|
||||
TmdbUtils.ConvertBackdropsToRemoteImageInfo(backdrops, _tmdbClientManager, 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.ConvertToRemoteImageInfo(profiles, _tmdbClientManager.GetProfileUrl, ImageType.Primary, language, remoteImages);
|
||||
TmdbUtils.ConvertProfilesToRemoteImageInfo(profiles, _tmdbClientManager, language, remoteImages);
|
||||
|
||||
return remoteImages;
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
|||
|
||||
var remoteImages = new List<RemoteImageInfo>(stills.Count);
|
||||
|
||||
TmdbUtils.ConvertToRemoteImageInfo(stills, _tmdbClientManager.GetStillUrl, ImageType.Primary, language, remoteImages);
|
||||
TmdbUtils.ConvertStillsToRemoteImageInfo(stills, _tmdbClientManager, language, remoteImages);
|
||||
|
||||
return remoteImages;
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
|||
|
||||
var remoteImages = new List<RemoteImageInfo>(posters.Count);
|
||||
|
||||
TmdbUtils.ConvertToRemoteImageInfo(posters, _tmdbClientManager.GetPosterUrl, ImageType.Primary, language, remoteImages);
|
||||
TmdbUtils.ConvertPostersToRemoteImageInfo(posters, _tmdbClientManager, 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.ConvertToRemoteImageInfo(posters, _tmdbClientManager.GetPosterUrl, ImageType.Primary, language, remoteImages);
|
||||
TmdbUtils.ConvertToRemoteImageInfo(backdrops, _tmdbClientManager.GetBackdropUrl, ImageType.Backdrop, language, remoteImages);
|
||||
TmdbUtils.ConvertPostersToRemoteImageInfo(posters, _tmdbClientManager, language, remoteImages);
|
||||
TmdbUtils.ConvertBackdropsToRemoteImageInfo(backdrops, _tmdbClientManager, language, remoteImages);
|
||||
|
||||
return remoteImages;
|
||||
}
|
||||
|
|
|
@ -195,6 +195,54 @@ 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>
|
||||
|
@ -203,7 +251,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
|||
/// <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>
|
||||
public static void ConvertToRemoteImageInfo(List<ImageData> images, Func<string, string> imageUrlConverter, ImageType type, string requestLanguage, List<RemoteImageInfo> results)
|
||||
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++)
|
||||
{
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Providers.Plugins.Tmdb;
|
||||
using TMDbLib.Objects.General;
|
||||
using MediaBrowser.Providers.Plugins.Tmdb;
|
||||
using Xunit;
|
||||
|
||||
namespace Jellyfin.Providers.Tests.Tmdb
|
||||
|
@ -41,87 +36,5 @@ namespace Jellyfin.Providers.Tests.Tmdb
|
|||
{
|
||||
Assert.Equal(expected, TmdbUtils.AdjustImageLanguage(imageLanguage, requestLanguage));
|
||||
}
|
||||
|
||||
private static TheoryData<ImageType, ImageData, RemoteImageInfo> GetConvertedImages()
|
||||
{
|
||||
return new TheoryData<ImageType, ImageData, RemoteImageInfo>
|
||||
{
|
||||
{
|
||||
ImageType.Primary,
|
||||
new ()
|
||||
{
|
||||
Width = 1,
|
||||
Height = 1,
|
||||
AspectRatio = 1,
|
||||
FilePath = "path 1",
|
||||
Iso_639_1 = "en",
|
||||
VoteAverage = 1.2,
|
||||
VoteCount = 5
|
||||
},
|
||||
new ()
|
||||
{
|
||||
Type = ImageType.Primary,
|
||||
Width = 1,
|
||||
Height = 1,
|
||||
Url = "converted path 1",
|
||||
Language = "en-US",
|
||||
CommunityRating = 1.2,
|
||||
VoteCount = 5,
|
||||
RatingType = RatingType.Score,
|
||||
ProviderName = TmdbUtils.ProviderName
|
||||
}
|
||||
},
|
||||
{
|
||||
ImageType.Backdrop,
|
||||
new ()
|
||||
{
|
||||
Width = 4,
|
||||
Height = 2,
|
||||
AspectRatio = 2,
|
||||
FilePath = "path 2",
|
||||
Iso_639_1 = null,
|
||||
VoteAverage = 0,
|
||||
VoteCount = 0
|
||||
},
|
||||
new ()
|
||||
{
|
||||
Type = ImageType.Backdrop,
|
||||
Width = 4,
|
||||
Height = 2,
|
||||
Url = "converted path 2",
|
||||
Language = null,
|
||||
CommunityRating = 0,
|
||||
VoteCount = 0,
|
||||
RatingType = RatingType.Score,
|
||||
ProviderName = TmdbUtils.ProviderName
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetConvertedImages))]
|
||||
public static void ConvertToRemoteImageInfo_ImageList_ConvertsAll(ImageType type, ImageData input, RemoteImageInfo expected)
|
||||
{
|
||||
var images = new List<ImageData> { input };
|
||||
string UrlConverter(string s)
|
||||
=> "converted " + s;
|
||||
var language = "en-US";
|
||||
|
||||
var results = new List<RemoteImageInfo>(images.Count);
|
||||
TmdbUtils.ConvertToRemoteImageInfo(images, UrlConverter, type, language, results);
|
||||
|
||||
Assert.Single(results);
|
||||
|
||||
Assert.Equal(expected.Type, results[0].Type);
|
||||
Assert.Equal(expected.Width, results[0].Width);
|
||||
Assert.Equal(expected.Height, results[0].Height);
|
||||
Assert.Equal(expected.Url, results[0].Url);
|
||||
Assert.Equal(expected.Language, results[0].Language);
|
||||
Assert.Equal(expected.CommunityRating, results[0].CommunityRating);
|
||||
Assert.Equal(expected.VoteCount, results[0].VoteCount);
|
||||
Assert.Equal(expected.RatingType, results[0].RatingType);
|
||||
Assert.Equal(expected.ProviderName, results[0].ProviderName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user