6e3c187493
SubtitleEncoder.ConvertSubtitles parsed subtitles with libse's static Subtitle.Parse, which iterates a statically cached list of shared SubtitleFormat instances. Format parsers keep mutable per-parse state on the instance, so concurrent subtitle requests corrupted each other's output (cues mixed across streams and languages, truncated files) or failed with NullReferenceException when format detection broke down and Subtitle.Parse returned null. Parse through the injected ISubtitleParser instead. SubtitleEditParser instantiates a fresh format parser per call, so requests no longer share state. Its Parse method now returns the libse Subtitle directly (the SubtitleTrackInfo flattening was unused since the SubtitleEdit writer rework) so the writers keep full fidelity such as ASS styling.
28 lines
1.0 KiB
C#
28 lines
1.0 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using MediaBrowser.MediaEncoding.Subtitles;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Xunit;
|
|
|
|
namespace Jellyfin.MediaEncoding.Subtitles.Tests
|
|
{
|
|
public class AssParserTests
|
|
{
|
|
[Fact]
|
|
public void Parse_Valid_Success()
|
|
{
|
|
using var stream = File.OpenRead("Test Data/example.ass");
|
|
|
|
var parsed = new SubtitleEditParser(new NullLogger<SubtitleEditParser>()).Parse(stream, "ass");
|
|
Assert.Single(parsed.Paragraphs);
|
|
var paragraph = parsed.Paragraphs[0];
|
|
|
|
Assert.Equal(1, paragraph.Number);
|
|
Assert.Equal(TimeSpan.Parse("00:00:01.18", CultureInfo.InvariantCulture).Ticks, paragraph.StartTime.TimeSpan.Ticks);
|
|
Assert.Equal(TimeSpan.Parse("00:00:06.85", CultureInfo.InvariantCulture).Ticks, paragraph.EndTime.TimeSpan.Ticks);
|
|
Assert.Equal("{\\pos(400,570)}Like an Angel with pity on nobody" + Environment.NewLine + "The second line in subtitle", paragraph.Text);
|
|
}
|
|
}
|
|
}
|