Merge pull request #2788 from ThatNerdyPikachu/more-track-titles

Use embedded title for other track types
This commit is contained in:
Anthony Lavado 2020-07-23 17:47:54 -07:00 committed by GitHub
commit 83509e99cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 129 additions and 90 deletions

View File

@ -112,18 +112,20 @@ namespace MediaBrowser.Model.Entities
{
get
{
if (Type == MediaStreamType.Audio)
switch (Type)
{
case MediaStreamType.Audio:
{
// if (!string.IsNullOrEmpty(Title))
//{
// return AddLanguageIfNeeded(Title);
//}
var attributes = new List<string>();
if (!string.IsNullOrEmpty(Language))
{
attributes.Add(StringHelper.FirstToUpper(Language));
// Get full language string i.e. eng -> English. Will not work for some languages which use ISO 639-2/B instead of /T codes.
string fullLanguage = CultureInfo
.GetCultures(CultureTypes.NeutralCultures)
.FirstOrDefault(r => r.ThreeLetterISOLanguageName.Equals(Language, StringComparison.OrdinalIgnoreCase))
?.DisplayName;
attributes.Add(StringHelper.FirstToUpper(fullLanguage ?? Language));
}
if (!string.IsNullOrEmpty(Codec) && !string.Equals(Codec, "dca", StringComparison.OrdinalIgnoreCase))
@ -137,7 +139,7 @@ namespace MediaBrowser.Model.Entities
if (!string.IsNullOrEmpty(ChannelLayout))
{
attributes.Add(ChannelLayout);
attributes.Add(StringHelper.FirstToUpper(ChannelLayout));
}
else if (Channels.HasValue)
{
@ -146,13 +148,28 @@ namespace MediaBrowser.Model.Entities
if (IsDefault)
{
attributes.Add("Default");
attributes.Add(string.IsNullOrEmpty(localizedDefault) ? "Default" : localizedDefault);
}
return string.Join(" ", attributes);
if (!string.IsNullOrEmpty(Title))
{
var result = new StringBuilder(Title);
foreach (var tag in attributes)
{
// Keep Tags that are not already in Title.
if (Title.IndexOf(tag, StringComparison.OrdinalIgnoreCase) == -1)
{
result.Append(" - ").Append(tag);
}
}
if (Type == MediaStreamType.Video)
return result.ToString();
}
return string.Join(" - ", attributes);
}
case MediaStreamType.Video:
{
var attributes = new List<string>();
@ -168,17 +185,36 @@ namespace MediaBrowser.Model.Entities
attributes.Add(Codec.ToUpperInvariant());
}
return string.Join(" ", attributes);
if (!string.IsNullOrEmpty(Title))
{
var result = new StringBuilder(Title);
foreach (var tag in attributes)
{
// Keep Tags that are not already in Title.
if (Title.IndexOf(tag, StringComparison.OrdinalIgnoreCase) == -1)
{
result.Append(" - ").Append(tag);
}
}
if (Type == MediaStreamType.Subtitle)
{
return result.ToString();
}
return string.Join(' ', attributes);
}
case MediaStreamType.Subtitle:
{
var attributes = new List<string>();
if (!string.IsNullOrEmpty(Language))
{
attributes.Add(StringHelper.FirstToUpper(Language));
// Get full language string i.e. eng -> English. Will not work for some languages which use ISO 639-2/B instead of /T codes.
string fullLanguage = CultureInfo
.GetCultures(CultureTypes.NeutralCultures)
.FirstOrDefault(r => r.ThreeLetterISOLanguageName.Equals(Language, StringComparison.OrdinalIgnoreCase))
?.DisplayName;
attributes.Add(StringHelper.FirstToUpper(fullLanguage ?? Language));
}
else
{
@ -197,24 +233,27 @@ namespace MediaBrowser.Model.Entities
if (!string.IsNullOrEmpty(Title))
{
return attributes.AsEnumerable()
// keep Tags that are not already in Title
.Where(tag => Title.IndexOf(tag, StringComparison.OrdinalIgnoreCase) == -1)
// attributes concatenation, starting with Title
.Aggregate(new StringBuilder(Title), (builder, attr) => builder.Append(" - ").Append(attr))
.ToString();
var result = new StringBuilder(Title);
foreach (var tag in attributes)
{
// Keep Tags that are not already in Title.
if (Title.IndexOf(tag, StringComparison.OrdinalIgnoreCase) == -1)
{
result.Append(" - ").Append(tag);
}
}
return result.ToString();
}
return string.Join(" - ", attributes.ToArray());
}
if (Type == MediaStreamType.Video)
{
}
default:
return null;
}
}
}
private string GetResolutionText()
{