diff --git a/MediaBrowser.Api/Library/SubtitleService.cs b/MediaBrowser.Api/Library/SubtitleService.cs index 7f283b715..62c7ac7c0 100644 --- a/MediaBrowser.Api/Library/SubtitleService.cs +++ b/MediaBrowser.Api/Library/SubtitleService.cs @@ -15,8 +15,7 @@ using System.Threading.Tasks; namespace MediaBrowser.Api.Library { - [Route("/Videos/{Id}/Subtitles/{Index}", "GET", Summary = "Gets an external subtitle file")] - [Route("/Videos/{Id}/Subtitles/{Index}/Stream.{Format}", "GET", Summary = "Gets subtitles in a specified format (vtt).")] + [Route("/Videos/{Id}/{MediaSourceId}/Subtitles/{Index}/Stream.{Format}", "GET", Summary = "Gets subtitles in a specified format (vtt).")] public class GetSubtitle { /// @@ -26,7 +25,7 @@ namespace MediaBrowser.Api.Library [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] public string Id { get; set; } - [ApiMember(Name = "MediaSourceId", Description = "MediaSourceId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] + [ApiMember(Name = "MediaSourceId", Description = "MediaSourceId", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] public string MediaSourceId { get; set; } [ApiMember(Name = "Index", Description = "The subtitle stream index", IsRequired = true, DataType = "int", ParameterType = "path", Verb = "GET")] diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 1460ceb60..baf389168 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -451,7 +451,7 @@ namespace MediaBrowser.Api.Playback var pts = string.Empty; - if (state.SubtitleStream != null && !state.SubtitleStream.IsGraphicalSubtitleStream) + if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream) { var seconds = TimeSpan.FromTicks(state.Request.StartTimeTicks ?? 0).TotalSeconds; @@ -486,7 +486,7 @@ namespace MediaBrowser.Api.Playback var request = state.VideoRequest; - if (state.SubtitleStream != null && !state.SubtitleStream.IsGraphicalSubtitleStream) + if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream) { assSubtitleParam = GetTextSubtitleParam(state, cancellationToken); copyTsParam = " -copyts"; @@ -590,7 +590,6 @@ namespace MediaBrowser.Api.Playback } // TODO: Perhaps also use original_size=1920x800 - return string.Format(",subtitles=filename='{0}'{1},setpts=PTS -{2}/TB", subtitlePath.Replace('\\', '/').Replace(":/", "\\:/"), charsetParam, diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index bd8201c41..13e858aa5 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -276,7 +276,7 @@ namespace MediaBrowser.Api.Playback.Hls const string keyFrameArg = " -force_key_frames expr:if(isnan(prev_forced_t),gte(t,.1),gte(t,prev_forced_t+5))"; - var hasGraphicalSubs = state.SubtitleStream != null && state.SubtitleStream.IsGraphicalSubtitleStream; + var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream; var args = "-codec:v:0 " + codec + " " + GetVideoQualityParam(state, "libx264", true) + keyFrameArg; diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index 8d0a4d14b..337cd88f2 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -170,7 +170,7 @@ namespace MediaBrowser.Api.Playback.Hls " -force_key_frames expr:if(isnan(prev_forced_t),gte(t,.1),gte(t,prev_forced_t+1))" : " -force_key_frames expr:if(isnan(prev_forced_t),gte(t,.1),gte(t,prev_forced_t+5))"; - var hasGraphicalSubs = state.SubtitleStream != null && state.SubtitleStream.IsGraphicalSubtitleStream; + var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream; var args = "-codec:v:0 " + codec + " " + GetVideoQualityParam(state, "libx264", true) + keyFrameArg; diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs index 8f5ebcf36..ca4947426 100644 --- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs +++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs @@ -147,7 +147,7 @@ namespace MediaBrowser.Api.Playback.Progressive args += keyFrameArg; - var hasGraphicalSubs = state.SubtitleStream != null && state.SubtitleStream.IsGraphicalSubtitleStream; + var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream; var request = state.VideoRequest; diff --git a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj index 882e211d4..d2c21639c 100644 --- a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj +++ b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj @@ -59,6 +59,7 @@ + diff --git a/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs b/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs new file mode 100644 index 000000000..5da838911 --- /dev/null +++ b/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs @@ -0,0 +1,14 @@ +using System; +using System.IO; +using System.Threading; + +namespace MediaBrowser.MediaEncoding.Subtitles +{ + public class SrtWriter : ISubtitleWriter + { + public void Write(SubtitleTrackInfo info, Stream stream, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + } +} diff --git a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs index 461f95174..5d066ee65 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs @@ -253,6 +253,10 @@ namespace MediaBrowser.MediaEncoding.Subtitles throw new ArgumentNullException("format"); } + if (string.Equals(format, SubtitleFormat.SRT, StringComparison.OrdinalIgnoreCase)) + { + return new SrtWriter(); + } if (string.Equals(format, SubtitleFormat.VTT, StringComparison.OrdinalIgnoreCase)) { return new VttWriter(); diff --git a/MediaBrowser.Model/Entities/MediaStream.cs b/MediaBrowser.Model/Entities/MediaStream.cs index 4de183bf9..838095832 100644 --- a/MediaBrowser.Model/Entities/MediaStream.cs +++ b/MediaBrowser.Model/Entities/MediaStream.cs @@ -130,19 +130,20 @@ namespace MediaBrowser.Model.Entities /// true if this instance is external; otherwise, false. public bool IsExternal { get; set; } - public bool IsGraphicalSubtitleStream + public bool IsTextSubtitleStream { get { - if (IsExternal) return false; + if (Type != MediaStreamType.Subtitle) return false; var codec = Codec ?? string.Empty; - return StringHelper.IndexOfIgnoreCase(codec, "pgs") != -1 || - StringHelper.IndexOfIgnoreCase(codec, "dvd") != -1; + return StringHelper.IndexOfIgnoreCase(codec, "pgs") == -1 && + StringHelper.IndexOfIgnoreCase(codec, "dvd") == -1; } } + /// /// Gets or sets the filename. /// diff --git a/MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs b/MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs index 0df2b24f5..9b9883ac1 100644 --- a/MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs +++ b/MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs @@ -110,7 +110,7 @@ namespace MediaBrowser.Providers.MediaInfo // There's an internal subtitle stream for this language if (skipIfGraphicalSubtitlesPresent && - internalMediaStreams.Any(i => i.Type == MediaStreamType.Subtitle && i.IsGraphicalSubtitleStream && string.Equals(i.Language, language, StringComparison.OrdinalIgnoreCase))) + internalMediaStreams.Any(i => i.Type == MediaStreamType.Subtitle && !i.IsTextSubtitleStream && string.Equals(i.Language, language, StringComparison.OrdinalIgnoreCase))) { return false; } diff --git a/MediaBrowser.Server.Implementations/Dto/MediaStreamSelector.cs b/MediaBrowser.Server.Implementations/Dto/MediaStreamSelector.cs index 12e70598f..c2dc1ef24 100644 --- a/MediaBrowser.Server.Implementations/Dto/MediaStreamSelector.cs +++ b/MediaBrowser.Server.Implementations/Dto/MediaStreamSelector.cs @@ -94,7 +94,7 @@ namespace MediaBrowser.Server.Implementations.Dto return index == -1 ? 100 : index; }) .ThenBy(i => i.IsDefault) - .ThenBy(i => !i.IsGraphicalSubtitleStream) + .ThenBy(i => i.IsTextSubtitleStream) .ThenBy(i => i.IsExternal) .ThenBy(i => i.Index) .ToList();