Files
pgsql-jellyfin/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs
T
wjones af1152b001 Refactor: standardize namespace and using directive style
Refactored all C# test files to use explicit namespace declarations and moved all using directives inside the namespace block for consistency. Updated assembly info and cache files to reflect the new build. Adjusted MvcTestingAppManifest.json to use fully qualified assembly names. No functional changes; all updates are related to code style, organization, and project metadata.
2026-02-20 16:26:53 -05:00

54 lines
1.7 KiB
C#

// <copyright file="SrtWriter.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace MediaBrowser.MediaEncoding.Subtitles
{
using System;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using MediaBrowser.Model.MediaInfo;
/// <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();
}
}
}
}
}