diff options
| author | Mathieu Velten <matmaul@gmail.com> | 2018-12-14 10:40:55 +0100 |
|---|---|---|
| committer | Mathieu Velten <matmaul@gmail.com> | 2018-12-14 17:32:54 +0100 |
| commit | 1d7d52ff9e42c3efb4bb2c65e82a4a82faf9decb (patch) | |
| tree | 00a3f529458b5e3afa42c97ec4f46e1b65c3cf8e /MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs | |
| parent | 64805410c21b1e4717a7f030f619bb2e7bd33d2a (diff) | |
Port MediaEncoding and Api.Playback from 10e57ce8d21b4516733894075001819f3cd6db6b
Diffstat (limited to 'MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs')
| -rw-r--r-- | MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs b/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs new file mode 100644 index 000000000..c05929fde --- /dev/null +++ b/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs @@ -0,0 +1,39 @@ +using System; +using System.Globalization; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using MediaBrowser.Model.MediaInfo; + +namespace MediaBrowser.MediaEncoding.Subtitles +{ + public class SrtWriter : ISubtitleWriter + { + public void Write(SubtitleTrackInfo info, Stream stream, CancellationToken cancellationToken) + { + using (var writer = new StreamWriter(stream, Encoding.UTF8, 1024, true)) + { + var index = 1; + + foreach (var trackEvent in info.TrackEvents) + { + cancellationToken.ThrowIfCancellationRequested(); + + writer.WriteLine(index.ToString(CultureInfo.InvariantCulture)); + writer.WriteLine(@"{0:hh\:mm\:ss\,fff} --> {1:hh\:mm\:ss\,fff}", TimeSpan.FromTicks(trackEvent.StartPositionTicks), TimeSpan.FromTicks(trackEvent.EndPositionTicks)); + + var text = trackEvent.Text; + + // TODO: Not sure how to handle these + text = Regex.Replace(text, @"\\n", " ", RegexOptions.IgnoreCase); + + writer.WriteLine(text); + writer.WriteLine(string.Empty); + + index++; + } + } + } + } +} |
