Fix Tmdb person language

This commit is contained in:
David Ullmer 2021-05-12 14:48:45 +02:00
parent 138c564e8f
commit c584d36fd4
4 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,5 @@
#pragma warning disable CS1591 #pragma warning disable CS1591
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
@ -48,6 +47,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken) public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{ {
var language = item.GetPreferredMetadataLanguage();
var person = (Person)item; var person = (Person)item;
if (!person.TryGetProviderId(MetadataProvider.Tmdb, out var personTmdbId)) if (!person.TryGetProviderId(MetadataProvider.Tmdb, out var personTmdbId))
@ -55,14 +55,13 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
return Enumerable.Empty<RemoteImageInfo>(); return Enumerable.Empty<RemoteImageInfo>();
} }
var personResult = await _tmdbClientManager.GetPersonAsync(int.Parse(personTmdbId, CultureInfo.InvariantCulture), cancellationToken).ConfigureAwait(false); var personResult = await _tmdbClientManager.GetPersonAsync(int.Parse(personTmdbId, CultureInfo.InvariantCulture), language, cancellationToken).ConfigureAwait(false);
if (personResult?.Images?.Profiles == null) if (personResult?.Images?.Profiles == null)
{ {
return Enumerable.Empty<RemoteImageInfo>(); return Enumerable.Empty<RemoteImageInfo>();
} }
var remoteImages = new RemoteImageInfo[personResult.Images.Profiles.Count]; var remoteImages = new RemoteImageInfo[personResult.Images.Profiles.Count];
var language = item.GetPreferredMetadataLanguage();
for (var i = 0; i < personResult.Images.Profiles.Count; i++) for (var i = 0; i < personResult.Images.Profiles.Count; i++)
{ {

View File

@ -3,7 +3,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -32,7 +31,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
{ {
if (searchInfo.TryGetProviderId(MetadataProvider.Tmdb, out var personTmdbId)) if (searchInfo.TryGetProviderId(MetadataProvider.Tmdb, out var personTmdbId))
{ {
var personResult = await _tmdbClientManager.GetPersonAsync(int.Parse(personTmdbId, CultureInfo.InvariantCulture), cancellationToken).ConfigureAwait(false); var personResult = await _tmdbClientManager.GetPersonAsync(int.Parse(personTmdbId, CultureInfo.InvariantCulture), searchInfo.MetadataLanguage, cancellationToken).ConfigureAwait(false);
if (personResult != null) if (personResult != null)
{ {
@ -96,7 +95,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
if (personTmdbId > 0) if (personTmdbId > 0)
{ {
var person = await _tmdbClientManager.GetPersonAsync(personTmdbId, cancellationToken).ConfigureAwait(false); var person = await _tmdbClientManager.GetPersonAsync(personTmdbId, id.MetadataLanguage, cancellationToken).ConfigureAwait(false);
result.HasMetadata = true; result.HasMetadata = true;

View File

@ -276,9 +276,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// Gets a person eg. cast or crew member from the TMDb API based on its TMDb id. /// Gets a person eg. cast or crew member from the TMDb API based on its TMDb id.
/// </summary> /// </summary>
/// <param name="personTmdbId">The person's TMDb id.</param> /// <param name="personTmdbId">The person's TMDb id.</param>
/// <param name="language">The episode's language.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The TMDb person information or null if not found.</returns> /// <returns>The TMDb person information or null if not found.</returns>
public async Task<Person> GetPersonAsync(int personTmdbId, CancellationToken cancellationToken) public async Task<Person> GetPersonAsync(int personTmdbId, string language, CancellationToken cancellationToken)
{ {
var key = $"person-{personTmdbId.ToString(CultureInfo.InvariantCulture)}"; var key = $"person-{personTmdbId.ToString(CultureInfo.InvariantCulture)}";
if (_memoryCache.TryGetValue(key, out Person person)) if (_memoryCache.TryGetValue(key, out Person person))
@ -290,6 +291,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
person = await _tmDbClient.GetPersonAsync( person = await _tmDbClient.GetPersonAsync(
personTmdbId, personTmdbId,
TmdbUtils.NormalizeLanguage(language),
PersonMethods.TvCredits | PersonMethods.MovieCredits | PersonMethods.Images | PersonMethods.ExternalIds, PersonMethods.TvCredits | PersonMethods.MovieCredits | PersonMethods.Images | PersonMethods.ExternalIds,
cancellationToken).ConfigureAwait(false); cancellationToken).ConfigureAwait(false);

View File

@ -148,6 +148,12 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
if (parts.Length == 2) if (parts.Length == 2)
{ {
// TMDB doesn't support Switzerland (de-CH, it-CH or fr-CH) so use the language (de, it or fr) without country code
if (string.Equals(parts[1], "ch", StringComparison.Ordinal))
{
return parts[0];
}
language = parts[0] + "-" + parts[1].ToUpperInvariant(); language = parts[0] + "-" + parts[1].ToUpperInvariant();
} }