Adjust language for image results from TMDB when querying complex language codes (> 2 chars, qualified by country)

This commit is contained in:
softworkz 2016-06-25 01:53:38 +02:00
parent 0181dd5a33
commit 06f5af783b
6 changed files with 47 additions and 16 deletions

View File

@ -83,7 +83,7 @@ namespace MediaBrowser.Providers.BoxSets
VoteCount = i.vote_count,
Width = i.width,
Height = i.height,
Language = i.iso_639_1,
Language = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language),
ProviderName = Name,
Type = ImageType.Primary,
RatingType = RatingType.Score

View File

@ -63,6 +63,8 @@ namespace MediaBrowser.Providers.Movies
{
var list = new List<RemoteImageInfo>();
var language = item.GetPreferredMetadataLanguage();
var results = await FetchImages((BaseItem)item, null, _jsonSerializer, cancellationToken).ConfigureAwait(false);
if (results == null)
@ -85,7 +87,7 @@ namespace MediaBrowser.Providers.Movies
VoteCount = i.vote_count,
Width = i.width,
Height = i.height,
Language = i.iso_639_1,
Language = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language),
ProviderName = Name,
Type = ImageType.Primary,
RatingType = RatingType.Score
@ -107,8 +109,6 @@ namespace MediaBrowser.Providers.Movies
}));
}
var language = item.GetPreferredMetadataLanguage();
var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase);
return list.OrderByDescending(i =>

View File

@ -267,9 +267,21 @@ namespace MediaBrowser.Providers.Movies
if (!string.IsNullOrEmpty(preferredLanguage))
{
preferredLanguage = NormalizeLanguage(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");
if (!string.Equals(preferredLanguage, "en", StringComparison.OrdinalIgnoreCase))
{
languages.Add("en");
@ -280,18 +292,35 @@ namespace MediaBrowser.Providers.Movies
public static string NormalizeLanguage(string language)
{
// They require this to be uppercase
// https://emby.media/community/index.php?/topic/32454-fr-follow-tmdbs-new-language-api-update/?p=311148
var parts = language.Split('-');
if (parts.Length == 2)
if (!string.IsNullOrEmpty(language))
{
language = parts[0] + "-" + parts[1].ToUpper();
// They require this to be uppercase
// https://emby.media/community/index.php?/topic/32454-fr-follow-tmdbs-new-language-api-update/?p=311148
var parts = language.Split('-');
if (parts.Length == 2)
{
language = parts[0] + "-" + parts[1].ToUpper();
}
}
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>
/// Fetches the main result.
/// </summary>

View File

@ -57,8 +57,10 @@ namespace MediaBrowser.Providers.TV
return list;
}
var language = item.GetPreferredMetadataLanguage();
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);
@ -71,12 +73,12 @@ namespace MediaBrowser.Providers.TV
VoteCount = i.vote_count,
Width = i.width,
Height = i.height,
Language = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language),
ProviderName = Name,
Type = ImageType.Primary,
RatingType = RatingType.Score
}));
var language = item.GetPreferredMetadataLanguage();
var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase);

View File

@ -151,7 +151,7 @@ namespace MediaBrowser.Providers.TV
public string file_path { get; set; }
public int height { 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 int vote_count { get; set; }
public int width { get; set; }

View File

@ -66,6 +66,8 @@ namespace MediaBrowser.Providers.TV
var tmdbImageUrl = tmdbSettings.images.secure_base_url + "original";
var language = item.GetPreferredMetadataLanguage();
list.AddRange(GetPosters(results).Select(i => new RemoteImageInfo
{
Url = tmdbImageUrl + i.file_path,
@ -73,7 +75,7 @@ namespace MediaBrowser.Providers.TV
VoteCount = i.vote_count,
Width = i.width,
Height = i.height,
Language = i.iso_639_1,
Language = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language),
ProviderName = Name,
Type = ImageType.Primary,
RatingType = RatingType.Score
@ -91,8 +93,6 @@ namespace MediaBrowser.Providers.TV
RatingType = RatingType.Score
}));
var language = item.GetPreferredMetadataLanguage();
var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase);
return list.OrderByDescending(i =>