diff options
| author | Bond_009 <bond.009@outlook.com> | 2026-05-08 21:29:13 +0200 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2026-05-30 21:09:10 +0200 |
| commit | 941298ee8108d79bd2f9bc010415103fddf54b0e (patch) | |
| tree | 91a659c3a60858a2ed8748261135df79caf574c9 /MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs | |
| parent | 99e9b2310f8a2c2a8bc630b31243df63507b1e17 (diff) | |
Write subtitles using SubtitleEdit
We've been using SubtitleEdit to parse since 2021
https://github.com/jellyfin/jellyfin/pull/4984
I think it's time we start using it to write too
Diffstat (limited to 'MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs')
| -rw-r--r-- | MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs b/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs deleted file mode 100644 index 86f77aa067..0000000000 --- a/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs +++ /dev/null @@ -1,49 +0,0 @@ -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 -{ - /// <summary> - /// SRT subtitle writer. - /// </summary> - public partial class SrtWriter : ISubtitleWriter - { - [GeneratedRegex(@"\\n", RegexOptions.IgnoreCase)] - private static partial Regex NewLineEscapedRegex(); - - /// <inheritdoc /> - public void Write(SubtitleTrackInfo info, Stream stream, CancellationToken cancellationToken) - { - using (var writer = new StreamWriter(stream, Encoding.UTF8, 1024, true)) - { - var trackEvents = info.TrackEvents; - - for (int i = 0; i < trackEvents.Count; i++) - { - cancellationToken.ThrowIfCancellationRequested(); - - var trackEvent = trackEvents[i]; - - writer.WriteLine((i + 1).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 = NewLineEscapedRegex().Replace(text, " "); - - writer.WriteLine(text); - writer.WriteLine(); - } - } - } - } -} |
