diff options
Diffstat (limited to 'MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs')
| -rw-r--r-- | MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs | 133 |
1 files changed, 99 insertions, 34 deletions
diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs b/MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs index 4de4bf4db..cb644c8ca 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TmdbClientManager.cs @@ -1,8 +1,13 @@ -using System; +#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; @@ -55,11 +60,17 @@ namespace MediaBrowser.Providers.Plugins.Tmdb await EnsureClientConfigAsync().ConfigureAwait(false); + var extraMethods = MovieMethods.Credits | MovieMethods.Releases | MovieMethods.Images | MovieMethods.Videos; + if (!(Plugin.Instance?.Configuration.ExcludeTagsMovies).GetValueOrDefault()) + { + extraMethods |= MovieMethods.Keywords; + } + movie = await _tmDbClient.GetMovieAsync( tmdbId, TmdbUtils.NormalizeLanguage(language), imageLanguages, - MovieMethods.Credits | MovieMethods.Releases | MovieMethods.Images | MovieMethods.Keywords | MovieMethods.Videos, + extraMethods, cancellationToken).ConfigureAwait(false); if (movie != null) @@ -121,11 +132,17 @@ namespace MediaBrowser.Providers.Plugins.Tmdb await EnsureClientConfigAsync().ConfigureAwait(false); + var extraMethods = TvShowMethods.Credits | TvShowMethods.Images | TvShowMethods.ExternalIds | TvShowMethods.Videos | TvShowMethods.ContentRatings | TvShowMethods.EpisodeGroups; + if (!(Plugin.Instance?.Configuration.ExcludeTagsSeries).GetValueOrDefault()) + { + extraMethods |= TvShowMethods.Keywords; + } + series = await _tmDbClient.GetTvShowAsync( tmdbId, language: TmdbUtils.NormalizeLanguage(language), includeImageLanguage: imageLanguages, - extraMethods: TvShowMethods.Credits | TvShowMethods.Images | TvShowMethods.Keywords | TvShowMethods.ExternalIds | TvShowMethods.Videos | TvShowMethods.ContentRatings | TvShowMethods.EpisodeGroups, + extraMethods: extraMethods, cancellationToken: cancellationToken).ConfigureAwait(false); if (series != null) @@ -358,7 +375,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb await EnsureClientConfigAsync().ConfigureAwait(false); var searchResults = await _tmDbClient - .SearchTvShowAsync(name, TmdbUtils.NormalizeLanguage(language), firstAirDateYear: year, cancellationToken: cancellationToken) + .SearchTvShowAsync(name, TmdbUtils.NormalizeLanguage(language), includeAdult: Plugin.Instance.Configuration.IncludeAdult, firstAirDateYear: year, cancellationToken: cancellationToken) .ConfigureAwait(false); if (searchResults.Results.Count > 0) @@ -386,7 +403,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb await EnsureClientConfigAsync().ConfigureAwait(false); var searchResults = await _tmDbClient - .SearchPersonAsync(name, cancellationToken: cancellationToken) + .SearchPersonAsync(name, includeAdult: Plugin.Instance.Configuration.IncludeAdult, cancellationToken: cancellationToken) .ConfigureAwait(false); if (searchResults.Results.Count > 0) @@ -428,7 +445,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb await EnsureClientConfigAsync().ConfigureAwait(false); var searchResults = await _tmDbClient - .SearchMovieAsync(name, TmdbUtils.NormalizeLanguage(language), year: year, cancellationToken: cancellationToken) + .SearchMovieAsync(name, TmdbUtils.NormalizeLanguage(language), includeAdult: Plugin.Instance.Configuration.IncludeAdult, year: year, cancellationToken: cancellationToken) .ConfigureAwait(false); if (searchResults.Results.Count > 0) @@ -469,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> @@ -505,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); + } + + /// <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); + } - return _tmDbClient.GetImageUrl(_tmDbClient.Config.Images.ProfileSizes[^1], actorProfilePath).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> - /// Gets the absolute URL of the still image. + /// Converts profile <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 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) { - if (string.IsNullOrEmpty(filePath)) + 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() @@ -540,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> |
