2
0
Luke Pulverenti 11 жил өмнө
parent
commit
fc6af0506c

+ 32 - 1
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;
+            }
         }
     }
 }