diff options
Diffstat (limited to 'MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs')
| -rw-r--r-- | MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs | 109 |
1 files changed, 80 insertions, 29 deletions
diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs b/MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs index f161a1c12..cb644c8ca 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs @@ -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; @@ -483,33 +486,29 @@ namespace MediaBrowser.Providers.Plugins.Tmdb } /// <summary> - /// Gets the absolute URL of the poster. + /// Handles bad path checking and builds the absolute url. /// </summary> - /// <param name="posterPath">The relative URL of the poster.</param> + /// <param name="size">The image size to fetch.</param> + /// <param name="path">The relative URL of the image.</param> /// <returns>The absolute URL.</returns> - public string GetPosterUrl(string posterPath) + private string GetUrl(string size, string path) { - if (string.IsNullOrEmpty(posterPath)) + if (string.IsNullOrEmpty(path)) { return null; } - return _tmDbClient.GetImageUrl(_tmDbClient.Config.Images.PosterSizes[^1], posterPath).ToString(); + return _tmDbClient.GetImageUrl(size, path).ToString(); } /// <summary> - /// Gets the absolute URL of the backdrop image. + /// Gets the absolute URL of the poster. /// </summary> - /// <param name="posterPath">The relative URL of the backdrop image.</param> + /// <param name="posterPath">The relative URL of the poster.</param> /// <returns>The absolute URL.</returns> - public string GetBackdropUrl(string posterPath) + public string GetPosterUrl(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 GetUrl(_tmDbClient.Config.Images.ProfileSizes[^1], actorProfilePath); + } - return _tmDbClient.GetImageUrl(_tmDbClient.Config.Images.ProfileSizes[^1], actorProfilePath).ToString(); + /// <summary> + /// Converts poster <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 ConvertPostersToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results) + { + 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) { - if (string.IsNullOrEmpty(filePath)) + 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++) { - return null; + 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 + }); } - - return _tmDbClient.GetImageUrl(_tmDbClient.Config.Images.StillSizes[^1], filePath).ToString(); } 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> |
