diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-06-11 10:42:03 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-06-11 10:42:03 -0400 |
| commit | 77ad0fc3365d9e880a47472f5780796570a06cab (patch) | |
| tree | 3b9d99d272e6119f4e7d1e7510498a468632009a /MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs | |
| parent | 437062b29e3e3456c15659666d6015356695913c (diff) | |
fixes #674 - Support converting subtitles to webvtt
Diffstat (limited to 'MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs')
| -rw-r--r-- | MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs index 09bc52df4..80fd0d602 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs @@ -3,25 +3,35 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text.RegularExpressions; +using System.Threading; namespace MediaBrowser.MediaEncoding.Subtitles { public class SrtParser : ISubtitleParser { private readonly CultureInfo _usCulture = new CultureInfo("en-US"); - public SubtitleTrackInfo Parse(Stream stream) { + public SubtitleTrackInfo Parse(Stream stream, CancellationToken cancellationToken) + { var trackInfo = new SubtitleTrackInfo(); using ( var reader = new StreamReader(stream)) { string line; while ((line = reader.ReadLine()) != null) { + cancellationToken.ThrowIfCancellationRequested(); + if (string.IsNullOrWhiteSpace(line)) { continue; } var subEvent = new SubtitleTrackEvent {Id = line}; line = reader.ReadLine(); + + if (string.IsNullOrWhiteSpace(line)) + { + continue; + } + var time = Regex.Split(line, @"[\t ]*-->[\t ]*"); subEvent.StartPositionTicks = GetTicks(time[0]); var endTime = time[1]; |
