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

View File

@ -112,107 +112,146 @@ namespace MediaBrowser.Model.Entities
{
get
{
if (Type == MediaStreamType.Audio)
switch (Type)
{
// if (!string.IsNullOrEmpty(Title))
//{
// return AddLanguageIfNeeded(Title);
//}
var attributes = new List<string>();
if (!string.IsNullOrEmpty(Language))
case MediaStreamType.Audio:
{
attributes.Add(StringHelper.FirstToUpper(Language));
var attributes = new List<string>();
if (!string.IsNullOrEmpty(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))
{
attributes.Add(AudioCodec.GetFriendlyName(Codec));
}
else if (!string.IsNullOrEmpty(Profile) && !string.Equals(Profile, "lc", StringComparison.OrdinalIgnoreCase))
{
attributes.Add(Profile);
}
if (!string.IsNullOrEmpty(ChannelLayout))
{
attributes.Add(StringHelper.FirstToUpper(ChannelLayout));
}
else if (Channels.HasValue)
{
attributes.Add(Channels.Value.ToString(CultureInfo.InvariantCulture) + " ch");
}
if (IsDefault)
{
attributes.Add(string.IsNullOrEmpty(localizedDefault) ? "Default" : localizedDefault);
}
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);
}
}
return result.ToString();
}
return string.Join(" - ", attributes);
}
if (!string.IsNullOrEmpty(Codec) && !string.Equals(Codec, "dca", StringComparison.OrdinalIgnoreCase))
case MediaStreamType.Video:
{
attributes.Add(AudioCodec.GetFriendlyName(Codec));
}
else if (!string.IsNullOrEmpty(Profile) && !string.Equals(Profile, "lc", StringComparison.OrdinalIgnoreCase))
{
attributes.Add(Profile);
var attributes = new List<string>();
var resolutionText = GetResolutionText();
if (!string.IsNullOrEmpty(resolutionText))
{
attributes.Add(resolutionText);
}
if (!string.IsNullOrEmpty(Codec))
{
attributes.Add(Codec.ToUpperInvariant());
}
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);
}
}
return result.ToString();
}
return string.Join(' ', attributes);
}
if (!string.IsNullOrEmpty(ChannelLayout))
case MediaStreamType.Subtitle:
{
attributes.Add(ChannelLayout);
}
else if (Channels.HasValue)
{
attributes.Add(Channels.Value.ToString(CultureInfo.InvariantCulture) + " ch");
var attributes = new List<string>();
if (!string.IsNullOrEmpty(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
{
attributes.Add(string.IsNullOrEmpty(localizedUndefined) ? "Und" : localizedUndefined);
}
if (IsDefault)
{
attributes.Add(string.IsNullOrEmpty(localizedDefault) ? "Default" : localizedDefault);
}
if (IsForced)
{
attributes.Add(string.IsNullOrEmpty(localizedForced) ? "Forced" : localizedForced);
}
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);
}
}
return result.ToString();
}
return string.Join(" - ", attributes.ToArray());
}
if (IsDefault)
{
attributes.Add("Default");
}
return string.Join(" ", attributes);
default:
return null;
}
if (Type == MediaStreamType.Video)
{
var attributes = new List<string>();
var resolutionText = GetResolutionText();
if (!string.IsNullOrEmpty(resolutionText))
{
attributes.Add(resolutionText);
}
if (!string.IsNullOrEmpty(Codec))
{
attributes.Add(Codec.ToUpperInvariant());
}
return string.Join(" ", attributes);
}
if (Type == MediaStreamType.Subtitle)
{
var attributes = new List<string>();
if (!string.IsNullOrEmpty(Language))
{
attributes.Add(StringHelper.FirstToUpper(Language));
}
else
{
attributes.Add(string.IsNullOrEmpty(localizedUndefined) ? "Und" : localizedUndefined);
}
if (IsDefault)
{
attributes.Add(string.IsNullOrEmpty(localizedDefault) ? "Default" : localizedDefault);
}
if (IsForced)
{
attributes.Add(string.IsNullOrEmpty(localizedForced) ? "Forced" : localizedForced);
}
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();
}
return string.Join(" - ", attributes.ToArray());
}
if (Type == MediaStreamType.Video)
{
}
return null;
}
}