Merge pull request #6763 from 1337joe/tmdb-image-provider-dedup
This commit is contained in:
commit
5c5d49ee60
|
@ -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;
|
||||
|
||||
|
@ -67,40 +66,12 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
|
|||
return Enumerable.Empty<RemoteImageInfo>();
|
||||
}
|
||||
|
||||
var remoteImages = new List<RemoteImageInfo>();
|
||||
var posters = collection.Images.Posters;
|
||||
var backdrops = collection.Images.Backdrops;
|
||||
var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count);
|
||||
|
||||
for (var i = 0; i < collection.Images.Posters.Count; i++)
|
||||
{
|
||||
var poster = collection.Images.Posters[i];
|
||||
remoteImages.Add(new RemoteImageInfo
|
||||
{
|
||||
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
|
||||
});
|
||||
}
|
||||
|
||||
for (var i = 0; i < collection.Images.Backdrops.Count; i++)
|
||||
{
|
||||
var backdrop = collection.Images.Backdrops[i];
|
||||
remoteImages.Add(new RemoteImageInfo
|
||||
{
|
||||
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
|
||||
});
|
||||
}
|
||||
_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages);
|
||||
_tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language, remoteImages);
|
||||
|
||||
return remoteImages;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
using TMDbLib.Objects.Find;
|
||||
|
@ -84,40 +83,12 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
|
|||
return Enumerable.Empty<RemoteImageInfo>();
|
||||
}
|
||||
|
||||
var remoteImages = new List<RemoteImageInfo>();
|
||||
var posters = movie.Images.Posters;
|
||||
var backdrops = movie.Images.Backdrops;
|
||||
var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count);
|
||||
|
||||
for (var i = 0; i < movie.Images.Posters.Count; i++)
|
||||
{
|
||||
var poster = movie.Images.Posters[i];
|
||||
remoteImages.Add(new RemoteImageInfo
|
||||
{
|
||||
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
|
||||
});
|
||||
}
|
||||
|
||||
for (var i = 0; i < movie.Images.Backdrops.Count; i++)
|
||||
{
|
||||
var backdrop = movie.Images.Backdrops[i];
|
||||
remoteImages.Add(new RemoteImageInfo
|
||||
{
|
||||
Url = _tmdbClientManager.GetPosterUrl(backdrop.FilePath),
|
||||
CommunityRating = backdrop.VoteAverage,
|
||||
VoteCount = backdrop.VoteCount,
|
||||
Width = backdrop.Width,
|
||||
Height = backdrop.Height,
|
||||
ProviderName = Name,
|
||||
Type = ImageType.Backdrop,
|
||||
RatingType = RatingType.Score
|
||||
});
|
||||
}
|
||||
_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages);
|
||||
_tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language, remoteImages);
|
||||
|
||||
return remoteImages;
|
||||
}
|
||||
|
|
|
@ -60,21 +60,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
|
|||
return Enumerable.Empty<RemoteImageInfo>();
|
||||
}
|
||||
|
||||
var remoteImages = new RemoteImageInfo[personResult.Images.Profiles.Count];
|
||||
var profiles = personResult.Images.Profiles;
|
||||
var remoteImages = new List<RemoteImageInfo>(profiles.Count);
|
||||
|
||||
for (var i = 0; i < personResult.Images.Profiles.Count; i++)
|
||||
{
|
||||
var image = personResult.Images.Profiles[i];
|
||||
remoteImages[i] = new RemoteImageInfo
|
||||
{
|
||||
ProviderName = Name,
|
||||
Type = ImageType.Primary,
|
||||
Width = image.Width,
|
||||
Height = image.Height,
|
||||
Language = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, language),
|
||||
Url = _tmdbClientManager.GetProfileUrl(image.FilePath)
|
||||
};
|
||||
}
|
||||
_tmdbClientManager.ConvertProfilesToRemoteImageInfo(profiles, language, remoteImages);
|
||||
|
||||
return remoteImages;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ using System.Threading.Tasks;
|
|||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
|
||||
|
@ -75,23 +74,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
|||
return Enumerable.Empty<RemoteImageInfo>();
|
||||
}
|
||||
|
||||
var remoteImages = new RemoteImageInfo[stills.Count];
|
||||
for (var i = 0; i < stills.Count; i++)
|
||||
{
|
||||
var image = stills[i];
|
||||
remoteImages[i] = new RemoteImageInfo
|
||||
{
|
||||
Url = _tmdbClientManager.GetStillUrl(image.FilePath),
|
||||
CommunityRating = image.VoteAverage,
|
||||
VoteCount = image.VoteCount,
|
||||
Width = image.Width,
|
||||
Height = image.Height,
|
||||
Language = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, language),
|
||||
ProviderName = Name,
|
||||
Type = ImageType.Primary,
|
||||
RatingType = RatingType.Score
|
||||
};
|
||||
}
|
||||
var remoteImages = new List<RemoteImageInfo>(stills.Count);
|
||||
|
||||
_tmdbClientManager.ConvertStillsToRemoteImageInfo(stills, language, remoteImages);
|
||||
|
||||
return remoteImages;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ using MediaBrowser.Common.Net;
|
|||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
|
||||
|
@ -62,23 +61,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
|||
return Enumerable.Empty<RemoteImageInfo>();
|
||||
}
|
||||
|
||||
var remoteImages = new RemoteImageInfo[posters.Count];
|
||||
for (var i = 0; i < posters.Count; i++)
|
||||
{
|
||||
var image = posters[i];
|
||||
remoteImages[i] = new RemoteImageInfo
|
||||
{
|
||||
Url = _tmdbClientManager.GetPosterUrl(image.FilePath),
|
||||
CommunityRating = image.VoteAverage,
|
||||
VoteCount = image.VoteCount,
|
||||
Width = image.Width,
|
||||
Height = image.Height,
|
||||
Language = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, language),
|
||||
ProviderName = Name,
|
||||
Type = ImageType.Primary,
|
||||
RatingType = RatingType.Score
|
||||
};
|
||||
}
|
||||
var remoteImages = new List<RemoteImageInfo>(posters.Count);
|
||||
|
||||
_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages);
|
||||
|
||||
return remoteImages;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ using MediaBrowser.Common.Net;
|
|||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
|
||||
|
@ -70,41 +69,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
|||
|
||||
var posters = series.Images.Posters;
|
||||
var backdrops = series.Images.Backdrops;
|
||||
var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count);
|
||||
|
||||
var remoteImages = new RemoteImageInfo[posters.Count + backdrops.Count];
|
||||
|
||||
for (var i = 0; i < posters.Count; i++)
|
||||
{
|
||||
var poster = posters[i];
|
||||
remoteImages[i] = new RemoteImageInfo
|
||||
{
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
for (var i = 0; i < backdrops.Count; i++)
|
||||
{
|
||||
var backdrop = series.Images.Backdrops[i];
|
||||
remoteImages[posters.Count + i] = new RemoteImageInfo
|
||||
{
|
||||
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
|
||||
};
|
||||
}
|
||||
_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages);
|
||||
_tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language, remoteImages);
|
||||
|
||||
return remoteImages;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
#nullable disable
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
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;
|
||||
|
@ -482,6 +485,22 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
|||
return searchResults.Results;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles bad path checking and builds the absolute url.
|
||||
/// </summary>
|
||||
/// <param name="size">The image size to fetch.</param>
|
||||
/// <param name="path">The relative URL of the image.</param>
|
||||
/// <returns>The absolute URL.</returns>
|
||||
private string GetUrl(string size, string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _tmDbClient.GetImageUrl(size, path).ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the absolute URL of the poster.
|
||||
/// </summary>
|
||||
|
@ -489,27 +508,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
|||
/// <returns>The absolute URL.</returns>
|
||||
public string GetPosterUrl(string posterPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(posterPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _tmDbClient.GetImageUrl(_tmDbClient.Config.Images.PosterSizes[^1], posterPath).ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the absolute URL of the backdrop image.
|
||||
/// </summary>
|
||||
/// <param name="posterPath">The relative URL of the backdrop image.</param>
|
||||
/// <returns>The absolute URL.</returns>
|
||||
public string GetBackdropUrl(string posterPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(posterPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _tmDbClient.GetImageUrl(_tmDbClient.Config.Images.BackdropSizes[^1], posterPath).ToString();
|
||||
return GetUrl(_tmDbClient.Config.Images.PosterSizes[^1], posterPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -519,27 +518,79 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
|||
/// <returns>The absolute URL.</returns>
|
||||
public string GetProfileUrl(string actorProfilePath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(actorProfilePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _tmDbClient.GetImageUrl(_tmDbClient.Config.Images.ProfileSizes[^1], actorProfilePath).ToString();
|
||||
return GetUrl(_tmDbClient.Config.Images.ProfileSizes[^1], actorProfilePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the absolute URL of the still image.
|
||||
/// Converts poster <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 ConvertPostersToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ConvertToRemoteImageInfo(images, _tmDbClient.Config.Images.PosterSizes[^1], ImageType.Primary, requestLanguage, results);
|
||||
}
|
||||
|
||||
return _tmDbClient.GetImageUrl(_tmDbClient.Config.Images.StillSizes[^1], filePath).ToString();
|
||||
/// <summary>
|
||||
/// Converts backdrop <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 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)
|
||||
{
|
||||
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()
|
||||
|
@ -554,7 +605,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
|||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Releases unmanaged and - optionally - managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
|
||||
|
|
|
@ -23,5 +23,18 @@ namespace Jellyfin.Providers.Tests.Tmdb
|
|||
{
|
||||
Assert.Equal(expected, TmdbUtils.NormalizeLanguage(input!));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, null, null)]
|
||||
[InlineData(null, "en-US", null)]
|
||||
[InlineData("en", null, "en")]
|
||||
[InlineData("en", "en-US", "en-US")]
|
||||
[InlineData("fr-CA", "fr-BE", "fr-CA")]
|
||||
[InlineData("fr-CA", "fr", "fr-CA")]
|
||||
[InlineData("de", "en-US", "de")]
|
||||
public static void AdjustImageLanguage_Valid_Success(string imageLanguage, string requestLanguage, string expected)
|
||||
{
|
||||
Assert.Equal(expected, TmdbUtils.AdjustImageLanguage(imageLanguage, requestLanguage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user