From 9e842641484b41f621da55cba3ae9e2f935b13f1 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 26 Dec 2015 03:07:24 -0500 Subject: [PATCH] update subtitles --- .../MediaEncoding/MediaStreamSelector.cs | 37 +++++++++++++++++++ .../Configuration/SubtitlePlaybackMode.cs | 3 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.Controller/MediaEncoding/MediaStreamSelector.cs b/MediaBrowser.Controller/MediaEncoding/MediaStreamSelector.cs index a006a1723..52199c5a2 100644 --- a/MediaBrowser.Controller/MediaEncoding/MediaStreamSelector.cs +++ b/MediaBrowser.Controller/MediaEncoding/MediaStreamSelector.cs @@ -50,6 +50,22 @@ namespace MediaBrowser.Controller.MediaEncoding if (mode == SubtitlePlaybackMode.Default) { + // Prefer embedded metadata over smart logic + + stream = streams.FirstOrDefault(s => s.IsForced && string.Equals(s.Language, audioTrackLanguage, StringComparison.OrdinalIgnoreCase)) ?? + streams.FirstOrDefault(s => s.IsForced) ?? + streams.FirstOrDefault(s => s.IsDefault); + + // if the audio language is not understood by the user, load their preferred subs, if there are any + if (stream == null && !ContainsOrdinal(preferredLanguages, audioTrackLanguage)) + { + stream = streams.Where(s => !s.IsForced).FirstOrDefault(s => ContainsOrdinal(preferredLanguages, s.Language)); + } + } + else if (mode == SubtitlePlaybackMode.Smart) + { + // Prefer smart logic over embedded metadata + // if the audio language is not understood by the user, load their preferred subs, if there are any if (!ContainsOrdinal(preferredLanguages, audioTrackLanguage)) { @@ -61,6 +77,12 @@ namespace MediaBrowser.Controller.MediaEncoding // always load the most suitable full subtitles stream = streams.FirstOrDefault(s => !s.IsForced); } + else if (mode == SubtitlePlaybackMode.OnlyForced) + { + // always load the most suitable full subtitles + stream = streams.FirstOrDefault(s => s.IsForced && string.Equals(s.Language, audioTrackLanguage, StringComparison.OrdinalIgnoreCase)) ?? + streams.FirstOrDefault(s => s.IsForced); + } // load forced subs if we have found no suitable full subtitles stream = stream ?? streams.FirstOrDefault(s => s.IsForced && string.Equals(s.Language, audioTrackLanguage, StringComparison.OrdinalIgnoreCase)); @@ -112,6 +134,15 @@ namespace MediaBrowser.Controller.MediaEncoding if (mode == SubtitlePlaybackMode.Default) { + // Prefer embedded metadata over smart logic + + filteredStreams = streams.Where(s => s.IsForced || s.IsDefault) + .ToList(); + } + else if (mode == SubtitlePlaybackMode.Smart) + { + // Prefer smart logic over embedded metadata + // if the audio language is not understood by the user, load their preferred subs, if there are any if (!ContainsOrdinal(preferredLanguages, audioTrackLanguage)) { @@ -125,6 +156,11 @@ namespace MediaBrowser.Controller.MediaEncoding filteredStreams = streams.Where(s => !s.IsForced) .ToList(); } + else if (mode == SubtitlePlaybackMode.OnlyForced) + { + // always load the most suitable full subtitles + filteredStreams = streams.Where(s => s.IsForced).ToList(); + } // load forced subs if we have found no suitable full subtitles if (filteredStreams.Count == 0) @@ -148,6 +184,7 @@ namespace MediaBrowser.Controller.MediaEncoding values.Add(index == -1 ? 0 : 100 - index); + values.Add(stream.IsForced ? 1 : 0); values.Add(stream.IsDefault ? 1 : 0); values.Add(stream.SupportsExternalStream ? 1 : 0); values.Add(stream.IsTextSubtitleStream ? 1 : 0); diff --git a/MediaBrowser.Model/Configuration/SubtitlePlaybackMode.cs b/MediaBrowser.Model/Configuration/SubtitlePlaybackMode.cs index e6a3c3091..fbee912d9 100644 --- a/MediaBrowser.Model/Configuration/SubtitlePlaybackMode.cs +++ b/MediaBrowser.Model/Configuration/SubtitlePlaybackMode.cs @@ -5,6 +5,7 @@ Default = 0, Always = 1, OnlyForced = 2, - None = 3 + None = 3, + Smart = 4 } } \ No newline at end of file