added IsTextSubtitleStream

This commit is contained in:
Luke Pulverenti 2014-06-11 16:57:18 -04:00
parent dd7825f6c8
commit a18f4e37ac
11 changed files with 33 additions and 15 deletions

View File

@ -15,8 +15,7 @@ using System.Threading.Tasks;
namespace MediaBrowser.Api.Library namespace MediaBrowser.Api.Library
{ {
[Route("/Videos/{Id}/Subtitles/{Index}", "GET", Summary = "Gets an external subtitle file")] [Route("/Videos/{Id}/{MediaSourceId}/Subtitles/{Index}/Stream.{Format}", "GET", Summary = "Gets subtitles in a specified format (vtt).")]
[Route("/Videos/{Id}/Subtitles/{Index}/Stream.{Format}", "GET", Summary = "Gets subtitles in a specified format (vtt).")]
public class GetSubtitle public class GetSubtitle
{ {
/// <summary> /// <summary>
@ -26,7 +25,7 @@ namespace MediaBrowser.Api.Library
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get; set; } 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; } public string MediaSourceId { get; set; }
[ApiMember(Name = "Index", Description = "The subtitle stream index", IsRequired = true, DataType = "int", ParameterType = "path", Verb = "GET")] [ApiMember(Name = "Index", Description = "The subtitle stream index", IsRequired = true, DataType = "int", ParameterType = "path", Verb = "GET")]

View File

@ -451,7 +451,7 @@ namespace MediaBrowser.Api.Playback
var pts = string.Empty; 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; var seconds = TimeSpan.FromTicks(state.Request.StartTimeTicks ?? 0).TotalSeconds;
@ -486,7 +486,7 @@ namespace MediaBrowser.Api.Playback
var request = state.VideoRequest; var request = state.VideoRequest;
if (state.SubtitleStream != null && !state.SubtitleStream.IsGraphicalSubtitleStream) if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream)
{ {
assSubtitleParam = GetTextSubtitleParam(state, cancellationToken); assSubtitleParam = GetTextSubtitleParam(state, cancellationToken);
copyTsParam = " -copyts"; copyTsParam = " -copyts";
@ -590,7 +590,6 @@ namespace MediaBrowser.Api.Playback
} }
// TODO: Perhaps also use original_size=1920x800 // TODO: Perhaps also use original_size=1920x800
return string.Format(",subtitles=filename='{0}'{1},setpts=PTS -{2}/TB", return string.Format(",subtitles=filename='{0}'{1},setpts=PTS -{2}/TB",
subtitlePath.Replace('\\', '/').Replace(":/", "\\:/"), subtitlePath.Replace('\\', '/').Replace(":/", "\\:/"),
charsetParam, charsetParam,

View File

@ -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))"; 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; var args = "-codec:v:0 " + codec + " " + GetVideoQualityParam(state, "libx264", true) + keyFrameArg;

View File

@ -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+1))" :
" -force_key_frames expr:if(isnan(prev_forced_t),gte(t,.1),gte(t,prev_forced_t+5))"; " -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; var args = "-codec:v:0 " + codec + " " + GetVideoQualityParam(state, "libx264", true) + keyFrameArg;

View File

@ -147,7 +147,7 @@ namespace MediaBrowser.Api.Playback.Progressive
args += keyFrameArg; args += keyFrameArg;
var hasGraphicalSubs = state.SubtitleStream != null && state.SubtitleStream.IsGraphicalSubtitleStream; var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream;
var request = state.VideoRequest; var request = state.VideoRequest;

View File

@ -59,6 +59,7 @@
<Compile Include="Subtitles\ISubtitleParser.cs" /> <Compile Include="Subtitles\ISubtitleParser.cs" />
<Compile Include="Subtitles\ISubtitleWriter.cs" /> <Compile Include="Subtitles\ISubtitleWriter.cs" />
<Compile Include="Subtitles\SrtParser.cs" /> <Compile Include="Subtitles\SrtParser.cs" />
<Compile Include="Subtitles\SrtWriter.cs" />
<Compile Include="Subtitles\SsaParser.cs" /> <Compile Include="Subtitles\SsaParser.cs" />
<Compile Include="Subtitles\SubtitleEncoder.cs" /> <Compile Include="Subtitles\SubtitleEncoder.cs" />
<Compile Include="Subtitles\SubtitleTrackInfo.cs" /> <Compile Include="Subtitles\SubtitleTrackInfo.cs" />

View File

@ -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();
}
}
}

View File

@ -253,6 +253,10 @@ namespace MediaBrowser.MediaEncoding.Subtitles
throw new ArgumentNullException("format"); throw new ArgumentNullException("format");
} }
if (string.Equals(format, SubtitleFormat.SRT, StringComparison.OrdinalIgnoreCase))
{
return new SrtWriter();
}
if (string.Equals(format, SubtitleFormat.VTT, StringComparison.OrdinalIgnoreCase)) if (string.Equals(format, SubtitleFormat.VTT, StringComparison.OrdinalIgnoreCase))
{ {
return new VttWriter(); return new VttWriter();

View File

@ -130,19 +130,20 @@ namespace MediaBrowser.Model.Entities
/// <value><c>true</c> if this instance is external; otherwise, <c>false</c>.</value> /// <value><c>true</c> if this instance is external; otherwise, <c>false</c>.</value>
public bool IsExternal { get; set; } public bool IsExternal { get; set; }
public bool IsGraphicalSubtitleStream public bool IsTextSubtitleStream
{ {
get get
{ {
if (IsExternal) return false; if (Type != MediaStreamType.Subtitle) return false;
var codec = Codec ?? string.Empty; var codec = Codec ?? string.Empty;
return StringHelper.IndexOfIgnoreCase(codec, "pgs") != -1 || return StringHelper.IndexOfIgnoreCase(codec, "pgs") == -1 &&
StringHelper.IndexOfIgnoreCase(codec, "dvd") != -1; StringHelper.IndexOfIgnoreCase(codec, "dvd") == -1;
} }
} }
/// <summary> /// <summary>
/// Gets or sets the filename. /// Gets or sets the filename.
/// </summary> /// </summary>

View File

@ -110,7 +110,7 @@ namespace MediaBrowser.Providers.MediaInfo
// There's an internal subtitle stream for this language // There's an internal subtitle stream for this language
if (skipIfGraphicalSubtitlesPresent && 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; return false;
} }

View File

@ -94,7 +94,7 @@ namespace MediaBrowser.Server.Implementations.Dto
return index == -1 ? 100 : index; return index == -1 ? 100 : index;
}) })
.ThenBy(i => i.IsDefault) .ThenBy(i => i.IsDefault)
.ThenBy(i => !i.IsGraphicalSubtitleStream) .ThenBy(i => i.IsTextSubtitleStream)
.ThenBy(i => i.IsExternal) .ThenBy(i => i.IsExternal)
.ThenBy(i => i.Index) .ThenBy(i => i.Index)
.ToList(); .ToList();