Merge pull request #6033 from Ullmie02/tmdb-person-language

This commit is contained in:
Bond-009 2021-05-20 22:50:42 +02:00 committed by GitHub
commit 95b909546d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 11 deletions

View File

@ -1,6 +1,5 @@
#pragma warning disable CS1591
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
@ -55,14 +54,14 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
return Enumerable.Empty<RemoteImageInfo>();
}
var personResult = await _tmdbClientManager.GetPersonAsync(int.Parse(personTmdbId, CultureInfo.InvariantCulture), cancellationToken).ConfigureAwait(false);
var language = item.GetPreferredMetadataLanguage();
var personResult = await _tmdbClientManager.GetPersonAsync(int.Parse(personTmdbId, CultureInfo.InvariantCulture), language, cancellationToken).ConfigureAwait(false);
if (personResult?.Images?.Profiles == null)
{
return Enumerable.Empty<RemoteImageInfo>();
}
var remoteImages = new RemoteImageInfo[personResult.Images.Profiles.Count];
var language = item.GetPreferredMetadataLanguage();
for (var i = 0; i < personResult.Images.Profiles.Count; i++)
{

View File

@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
@ -32,7 +31,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
{
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)
{
@ -96,7 +95,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
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;

View File

@ -276,11 +276,12 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// Gets a person eg. cast or crew member from the TMDb API based on its TMDb id.
/// </summary>
/// <param name="personTmdbId">The person's TMDb id.</param>
/// <param name="language">The episode's language.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <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)}-{language}";
if (_memoryCache.TryGetValue(key, out Person person))
{
return person;
@ -290,6 +291,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
person = await _tmDbClient.GetPersonAsync(
personTmdbId,
TmdbUtils.NormalizeLanguage(language),
PersonMethods.TvCredits | PersonMethods.MovieCredits | PersonMethods.Images | PersonMethods.ExternalIds,
cancellationToken).ConfigureAwait(false);

View File

@ -148,6 +148,12 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
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.OrdinalIgnoreCase))
{
return parts[0];
}
language = parts[0] + "-" + parts[1].ToUpperInvariant();
}

View File

@ -10,14 +10,14 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<PackageReference Include="coverlet.collector" Version="3.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
@ -31,7 +31,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../MediaBrowser.Providers\MediaBrowser.Providers.csproj" />
<ProjectReference Include="../../MediaBrowser.Providers/MediaBrowser.Providers.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,27 @@
using MediaBrowser.Providers.Plugins.Tmdb;
using Xunit;
namespace Jellyfin.Providers.Tests.Tmdb
{
public static class TmdbUtilsTests
{
[Theory]
[InlineData("de", "de")]
[InlineData("En", "En")]
[InlineData("de-de", "de-DE")]
[InlineData("en-US", "en-US")]
[InlineData("de-CH", "de")]
public static void NormalizeLanguage_Valid_Success(string input, string expected)
{
Assert.Equal(expected, TmdbUtils.NormalizeLanguage(input));
}
[Theory]
[InlineData(null, null)]
[InlineData("", "")]
public static void NormalizeLanguage_Invalid_Equal(string? input, string? expected)
{
Assert.Equal(expected, TmdbUtils.NormalizeLanguage(input!));
}
}
}