mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-07 11:57:55 +02:00
Merge pull request #1877 from softworkz/TmdbLanguageQueries
Adjust language for image results from TMDB when querying complex language codes (> 2 chars, qualified by country)
This commit is contained in:
commit
a4027bf2db
6 changed files with 47 additions and 16 deletions
|
@ -83,7 +83,7 @@ namespace MediaBrowser.Providers.BoxSets
|
||||||
VoteCount = i.vote_count,
|
VoteCount = i.vote_count,
|
||||||
Width = i.width,
|
Width = i.width,
|
||||||
Height = i.height,
|
Height = i.height,
|
||||||
Language = i.iso_639_1,
|
Language = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language),
|
||||||
ProviderName = Name,
|
ProviderName = Name,
|
||||||
Type = ImageType.Primary,
|
Type = ImageType.Primary,
|
||||||
RatingType = RatingType.Score
|
RatingType = RatingType.Score
|
||||||
|
|
|
@ -63,6 +63,8 @@ namespace MediaBrowser.Providers.Movies
|
||||||
{
|
{
|
||||||
var list = new List<RemoteImageInfo>();
|
var list = new List<RemoteImageInfo>();
|
||||||
|
|
||||||
|
var language = item.GetPreferredMetadataLanguage();
|
||||||
|
|
||||||
var results = await FetchImages((BaseItem)item, null, _jsonSerializer, cancellationToken).ConfigureAwait(false);
|
var results = await FetchImages((BaseItem)item, null, _jsonSerializer, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
if (results == null)
|
if (results == null)
|
||||||
|
@ -85,7 +87,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
VoteCount = i.vote_count,
|
VoteCount = i.vote_count,
|
||||||
Width = i.width,
|
Width = i.width,
|
||||||
Height = i.height,
|
Height = i.height,
|
||||||
Language = i.iso_639_1,
|
Language = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language),
|
||||||
ProviderName = Name,
|
ProviderName = Name,
|
||||||
Type = ImageType.Primary,
|
Type = ImageType.Primary,
|
||||||
RatingType = RatingType.Score
|
RatingType = RatingType.Score
|
||||||
|
@ -107,8 +109,6 @@ namespace MediaBrowser.Providers.Movies
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
var language = item.GetPreferredMetadataLanguage();
|
|
||||||
|
|
||||||
var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase);
|
var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
return list.OrderByDescending(i =>
|
return list.OrderByDescending(i =>
|
||||||
|
|
|
@ -267,9 +267,21 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(preferredLanguage))
|
if (!string.IsNullOrEmpty(preferredLanguage))
|
||||||
{
|
{
|
||||||
|
preferredLanguage = NormalizeLanguage(preferredLanguage);
|
||||||
|
|
||||||
languages.Add(preferredLanguage);
|
languages.Add(preferredLanguage);
|
||||||
|
|
||||||
|
if (preferredLanguage.Length == 5) // like en-US
|
||||||
|
{
|
||||||
|
// Currenty, TMDB supports 2-letter language codes only
|
||||||
|
// They are planning to change this in the future, thus we're
|
||||||
|
// supplying both codes if we're having a 5-letter code.
|
||||||
|
languages.Add(preferredLanguage.Substring(0, 2));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
languages.Add("null");
|
languages.Add("null");
|
||||||
|
|
||||||
if (!string.Equals(preferredLanguage, "en", StringComparison.OrdinalIgnoreCase))
|
if (!string.Equals(preferredLanguage, "en", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
languages.Add("en");
|
languages.Add("en");
|
||||||
|
@ -279,6 +291,8 @@ namespace MediaBrowser.Providers.Movies
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string NormalizeLanguage(string language)
|
public static string NormalizeLanguage(string language)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(language))
|
||||||
{
|
{
|
||||||
// They require this to be uppercase
|
// They require this to be uppercase
|
||||||
// https://emby.media/community/index.php?/topic/32454-fr-follow-tmdbs-new-language-api-update/?p=311148
|
// https://emby.media/community/index.php?/topic/32454-fr-follow-tmdbs-new-language-api-update/?p=311148
|
||||||
|
@ -288,10 +302,25 @@ namespace MediaBrowser.Providers.Movies
|
||||||
{
|
{
|
||||||
language = parts[0] + "-" + parts[1].ToUpper();
|
language = parts[0] + "-" + parts[1].ToUpper();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return language;
|
return language;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string AdjustImageLanguage(string imageLanguage, string requestLanguage)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(imageLanguage)
|
||||||
|
&& !string.IsNullOrEmpty(requestLanguage)
|
||||||
|
&& requestLanguage.Length > 2
|
||||||
|
&& imageLanguage.Length == 2
|
||||||
|
&& requestLanguage.StartsWith(imageLanguage, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return requestLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
|
return imageLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fetches the main result.
|
/// Fetches the main result.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -57,8 +57,10 @@ namespace MediaBrowser.Providers.TV
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var language = item.GetPreferredMetadataLanguage();
|
||||||
|
|
||||||
var response = await GetEpisodeInfo(seriesId, seasonNumber.Value, episodeNumber.Value,
|
var response = await GetEpisodeInfo(seriesId, seasonNumber.Value, episodeNumber.Value,
|
||||||
item.GetPreferredMetadataLanguage(), cancellationToken).ConfigureAwait(false);
|
language, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
|
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
@ -71,12 +73,12 @@ namespace MediaBrowser.Providers.TV
|
||||||
VoteCount = i.vote_count,
|
VoteCount = i.vote_count,
|
||||||
Width = i.width,
|
Width = i.width,
|
||||||
Height = i.height,
|
Height = i.height,
|
||||||
|
Language = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language),
|
||||||
ProviderName = Name,
|
ProviderName = Name,
|
||||||
Type = ImageType.Primary,
|
Type = ImageType.Primary,
|
||||||
RatingType = RatingType.Score
|
RatingType = RatingType.Score
|
||||||
}));
|
}));
|
||||||
|
|
||||||
var language = item.GetPreferredMetadataLanguage();
|
|
||||||
|
|
||||||
var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase);
|
var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
public string file_path { get; set; }
|
public string file_path { get; set; }
|
||||||
public int height { get; set; }
|
public int height { get; set; }
|
||||||
public string id { get; set; }
|
public string id { get; set; }
|
||||||
public object iso_639_1 { get; set; }
|
public string iso_639_1 { get; set; }
|
||||||
public double vote_average { get; set; }
|
public double vote_average { get; set; }
|
||||||
public int vote_count { get; set; }
|
public int vote_count { get; set; }
|
||||||
public int width { get; set; }
|
public int width { get; set; }
|
||||||
|
|
|
@ -66,6 +66,8 @@ namespace MediaBrowser.Providers.TV
|
||||||
|
|
||||||
var tmdbImageUrl = tmdbSettings.images.secure_base_url + "original";
|
var tmdbImageUrl = tmdbSettings.images.secure_base_url + "original";
|
||||||
|
|
||||||
|
var language = item.GetPreferredMetadataLanguage();
|
||||||
|
|
||||||
list.AddRange(GetPosters(results).Select(i => new RemoteImageInfo
|
list.AddRange(GetPosters(results).Select(i => new RemoteImageInfo
|
||||||
{
|
{
|
||||||
Url = tmdbImageUrl + i.file_path,
|
Url = tmdbImageUrl + i.file_path,
|
||||||
|
@ -73,7 +75,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
VoteCount = i.vote_count,
|
VoteCount = i.vote_count,
|
||||||
Width = i.width,
|
Width = i.width,
|
||||||
Height = i.height,
|
Height = i.height,
|
||||||
Language = i.iso_639_1,
|
Language = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language),
|
||||||
ProviderName = Name,
|
ProviderName = Name,
|
||||||
Type = ImageType.Primary,
|
Type = ImageType.Primary,
|
||||||
RatingType = RatingType.Score
|
RatingType = RatingType.Score
|
||||||
|
@ -91,8 +93,6 @@ namespace MediaBrowser.Providers.TV
|
||||||
RatingType = RatingType.Score
|
RatingType = RatingType.Score
|
||||||
}));
|
}));
|
||||||
|
|
||||||
var language = item.GetPreferredMetadataLanguage();
|
|
||||||
|
|
||||||
var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase);
|
var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
return list.OrderByDescending(i =>
|
return list.OrderByDescending(i =>
|
||||||
|
|
Loading…
Reference in a new issue