mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 11:34:57 +02:00
Merge pull request #6033 from Ullmie02/tmdb-person-language
This commit is contained in:
commit
95b909546d
6 changed files with 44 additions and 11 deletions
|
@ -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;
|
||||||
|
@ -55,14 +54,14 @@ 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 language = item.GetPreferredMetadataLanguage();
|
||||||
|
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++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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.
|
/// 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)}-{language}";
|
||||||
if (_memoryCache.TryGetValue(key, out Person person))
|
if (_memoryCache.TryGetValue(key, out Person person))
|
||||||
{
|
{
|
||||||
return person;
|
return 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);
|
||||||
|
|
||||||
|
|
|
@ -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.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return parts[0];
|
||||||
|
}
|
||||||
|
|
||||||
language = parts[0] + "-" + parts[1].ToUpperInvariant();
|
language = parts[0] + "-" + parts[1].ToUpperInvariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,14 +10,14 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<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="Moq" Version="4.16.1" />
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</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>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="../../MediaBrowser.Providers\MediaBrowser.Providers.csproj" />
|
<ProjectReference Include="../../MediaBrowser.Providers/MediaBrowser.Providers.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
27
tests/Jellyfin.Providers.Tests/Tmdb/TmdbUtilsTests.cs
Normal file
27
tests/Jellyfin.Providers.Tests/Tmdb/TmdbUtilsTests.cs
Normal 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!));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue