diff options
| author | Anthony Lavado <anthony@lavado.ca> | 2020-07-23 17:47:54 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-23 17:47:54 -0700 |
| commit | 83509e99cb5672c0da10191dac7e5e459b343dde (patch) | |
| tree | 3e7374ab66bcbebf45c6431d86fdce7ae169bec6 | |
| parent | 845ee21ddce8ed91d8c3c1463d0d7a06bb769635 (diff) | |
| parent | 7331c02a2137a68cb97339e86fee30d8752f9324 (diff) | |
Merge pull request #2788 from ThatNerdyPikachu/more-track-titles
Use embedded title for other track types
| -rw-r--r-- | MediaBrowser.Model/Entities/MediaStream.cs | 219 |
1 files changed, 129 insertions, 90 deletions
diff --git a/MediaBrowser.Model/Entities/MediaStream.cs b/MediaBrowser.Model/Entities/MediaStream.cs index 7a488005e..569c9cacd 100644 --- a/MediaBrowser.Model/Entities/MediaStream.cs +++ b/MediaBrowser.Model/Entities/MediaStream.cs @@ -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)) - { - 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) + case MediaStreamType.Audio: { - 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); - } - - if (Type == MediaStreamType.Video) - { - var attributes = new List<string>(); - - var resolutionText = GetResolutionText(); - - if (!string.IsNullOrEmpty(resolutionText)) + case MediaStreamType.Subtitle: { - 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)) - { - attributes.Add(Codec.ToUpperInvariant()); - } - - return string.Join(" ", attributes); + default: + return null; } - - 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; } } |
