aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-06-18 11:15:21 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-06-18 11:15:21 -0400
commitfc6af0506cc1ba5c4f62d7fb8e2d6c9fac151e2a (patch)
tree2a98542c31e09264a33c2a975983992eed58f37d
parentf98b619b643a9af7b892ce8a591972fac5bb21d4 (diff)
implement srt writer
-rw-r--r--MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs33
1 files changed, 32 insertions, 1 deletions
diff --git a/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs b/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs
index 5da838911..657aa17b3 100644
--- a/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs
+++ b/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs
@@ -1,5 +1,7 @@
using System;
+using System.Globalization;
using System.IO;
+using System.Text.RegularExpressions;
using System.Threading;
namespace MediaBrowser.MediaEncoding.Subtitles
@@ -8,7 +10,36 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
public void Write(SubtitleTrackInfo info, Stream stream, CancellationToken cancellationToken)
{
- throw new NotImplementedException();
+ var writer = new StreamWriter(stream);
+
+ try
+ {
+ 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++;
+ }
+ }
+ catch
+ {
+ writer.Dispose();
+
+ throw;
+ }
}
}
}