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
{
[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
{
/// <summary>
@ -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")]

View File

@ -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,

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))";
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;

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+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;

View File

@ -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;

View File

@ -59,6 +59,7 @@
<Compile Include="Subtitles\ISubtitleParser.cs" />
<Compile Include="Subtitles\ISubtitleWriter.cs" />
<Compile Include="Subtitles\SrtParser.cs" />
<Compile Include="Subtitles\SrtWriter.cs" />
<Compile Include="Subtitles\SsaParser.cs" />
<Compile Include="Subtitles\SubtitleEncoder.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");
}
if (string.Equals(format, SubtitleFormat.SRT, StringComparison.OrdinalIgnoreCase))
{
return new SrtWriter();
}
if (string.Equals(format, SubtitleFormat.VTT, StringComparison.OrdinalIgnoreCase))
{
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>
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;
}
}
/// <summary>
/// Gets or sets the filename.
/// </summary>

View File

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

View File

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