jellyfin/MediaBrowser.MediaEncoding/Subtitles/VttWriter.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2014-05-10 21:47:48 -07:00
using System;
using System.IO;
2014-06-13 07:24:14 -07:00
using System.Text.RegularExpressions;
using System.Threading;
2014-05-10 21:47:48 -07:00
namespace MediaBrowser.MediaEncoding.Subtitles
{
public class VttWriter : ISubtitleWriter
{
public void Write(SubtitleTrackInfo info, Stream stream, CancellationToken cancellationToken)
{
var writer = new StreamWriter(stream);
try
2014-05-10 23:29:44 -07:00
{
writer.WriteLine("WEBVTT");
writer.WriteLine(string.Empty);
foreach (var trackEvent in info.TrackEvents)
{
cancellationToken.ThrowIfCancellationRequested();
2014-05-10 23:29:44 -07:00
writer.WriteLine(@"{0:hh\:mm\:ss\.fff} --> {1:hh\:mm\:ss\.fff}", TimeSpan.FromTicks(trackEvent.StartPositionTicks), TimeSpan.FromTicks(trackEvent.EndPositionTicks));
2014-06-13 07:24:14 -07:00
var text = Regex.Replace(trackEvent.Text, @"\\N", "<br />", RegexOptions.IgnoreCase);
writer.WriteLine(text);
2014-05-10 23:29:44 -07:00
writer.WriteLine(string.Empty);
}
}
catch
{
writer.Dispose();
throw;
}
2014-05-10 21:47:48 -07:00
}
}
}