From be070a0bfee798071a66ad012622ba6a80a37b3e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 2 Feb 2015 13:14:02 -0500 Subject: [PATCH] subtitle profile fixes --- MediaBrowser.Model/Dlna/StreamBuilder.cs | 33 +++++++++++++++------- MediaBrowser.Model/Entities/MediaStream.cs | 18 +++++++----- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index 721da54a80..117d738f31 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -10,8 +10,6 @@ namespace MediaBrowser.Model.Dlna { public class StreamBuilder { - private readonly string[] _serverTextSubtitleOutputs = { "srt", "vtt", "ttml" }; - public StreamInfo BuildAudioItem(AudioOptions options) { ValidateAudioInput(options); @@ -544,16 +542,18 @@ namespace MediaBrowser.Model.Dlna private SubtitleProfile GetSubtitleProfile(MediaStream subtitleStream, VideoOptions options) { + // Look for an external profile that matches the stream type (text/graphical) + foreach (SubtitleProfile profile in options.Profile.SubtitleProfiles) + { + if (profile.Method == SubtitleDeliveryMethod.External && subtitleStream.IsTextSubtitleStream == MediaStream.IsTextFormat(profile.Format)) + { + return profile; + } + } + if (subtitleStream.IsTextSubtitleStream) { - SubtitleProfile externalProfile = GetSubtitleProfile(options.Profile.SubtitleProfiles, SubtitleDeliveryMethod.External, _serverTextSubtitleOutputs); - - if (externalProfile != null) - { - return externalProfile; - } - - SubtitleProfile embedProfile = GetSubtitleProfile(options.Profile.SubtitleProfiles, SubtitleDeliveryMethod.Embed, _serverTextSubtitleOutputs); + SubtitleProfile embedProfile = GetSubtitleProfile(options.Profile.SubtitleProfiles, SubtitleDeliveryMethod.Embed); if (embedProfile != null) { @@ -581,6 +581,19 @@ namespace MediaBrowser.Model.Dlna return null; } + private SubtitleProfile GetSubtitleProfile(SubtitleProfile[] profiles, SubtitleDeliveryMethod method) + { + foreach (SubtitleProfile profile in profiles) + { + if (method == profile.Method) + { + return profile; + } + } + + return null; + } + private bool IsAudioEligibleForDirectPlay(MediaSourceInfo item, int? maxBitrate) { // Honor the max bitrate setting diff --git a/MediaBrowser.Model/Entities/MediaStream.cs b/MediaBrowser.Model/Entities/MediaStream.cs index 4a9b765c23..db4a68cffb 100644 --- a/MediaBrowser.Model/Entities/MediaStream.cs +++ b/MediaBrowser.Model/Entities/MediaStream.cs @@ -141,16 +141,20 @@ namespace MediaBrowser.Model.Entities { if (Type != MediaStreamType.Subtitle) return false; - string codec = Codec ?? string.Empty; - - // sub = external .sub file - - return StringHelper.IndexOfIgnoreCase(codec, "pgs") == -1 && - StringHelper.IndexOfIgnoreCase(codec, "dvd") == -1 && - !StringHelper.EqualsIgnoreCase(codec, "sub"); + return IsTextFormat(Codec); } } + public static bool IsTextFormat(string format) + { + string codec = format ?? string.Empty; + + // sub = external .sub file + + return StringHelper.IndexOfIgnoreCase(codec, "pgs") == -1 && + StringHelper.IndexOfIgnoreCase(codec, "dvd") == -1 && + !StringHelper.EqualsIgnoreCase(codec, "sub"); + } /// /// Gets or sets the filename.