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

Use embedded title for other track types
pull/3677/head
Anthony Lavado 5 years ago committed by GitHub
commit 83509e99cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -112,107 +112,146 @@ namespace MediaBrowser.Model.Entities
{ {
get get
{ {
if (Type == MediaStreamType.Audio) switch (Type)
{ {
// if (!string.IsNullOrEmpty(Title)) case MediaStreamType.Audio:
//{
// return AddLanguageIfNeeded(Title);
//}
var attributes = new List<string>();
if (!string.IsNullOrEmpty(Language))
{
attributes.Add(StringHelper.FirstToUpper(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(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));
}
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 (IsDefault) case MediaStreamType.Video:
{ {
attributes.Add("Default"); 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);
} }
return string.Join(" ", attributes); case MediaStreamType.Subtitle:
}
if (Type == MediaStreamType.Video)
{
var attributes = new List<string>();
var resolutionText = GetResolutionText();
if (!string.IsNullOrEmpty(resolutionText))
{ {
attributes.Add(resolutionText); 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 (!string.IsNullOrEmpty(Codec)) default:
{ return null;
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;
} }
} }

Loading…
Cancel
Save