fix(subtitles): recover canonical lines from ASS animation (#207)

This commit is contained in:
2026-08-18 00:30:48 -07:00
committed by GitHub
parent 14c0086520
commit 273652f781
26 changed files with 1844 additions and 124 deletions
+13
View File
@@ -1424,6 +1424,19 @@ test('subtitle annotation CSS underlines JLPT tokens without changing token colo
);
});
test('prepareSecondarySubtitleLines drops layered duplicate lines in short stacks', () => {
// A word-level animation stacks one event per layer copy; the stack is too short for
// the karaoke heuristic but the duplicates are still never distinct content.
assert.deepEqual(prepareSecondarySubtitleLines('Your\\NYour\\NYour\\NYour\\Nmosaic'), [
'Your',
'mosaic',
]);
assert.deepEqual(prepareSecondarySubtitleLines('One line\\NAnother line'), [
'One line',
'Another line',
]);
});
test('prepareSecondarySubtitleLines collapses karaoke syllable spam into one deduped line', () => {
// Karaoke-typeset OP/ED: one ASS event per syllable, duplicated across layers,
// joined with \N by mpv's secondary-sub-text.
+9 -3
View File
@@ -677,10 +677,12 @@ export function prepareSecondarySubtitleLines(text: string): string[] {
.split('\n')
.map((line) => line.trim())
.filter((line) => line.length > 0);
if (!isKaraokeLikeLineSet(lines)) {
return lines;
}
// Identical lines in one render are layered copies of the same event (animation
// scripts stack several per glyph), never distinct content -- always drop them, so a
// short stack like "Your ×4 / mosaic" collapses without needing the karaoke
// heuristic. Karaoke-likeness is still judged on the raw stack, where the layered
// repetition is the signal.
const seen = new Set<string>();
const unique: string[] = [];
for (const line of lines) {
@@ -688,6 +690,10 @@ export function prepareSecondarySubtitleLines(text: string): string[] {
seen.add(line);
unique.push(line);
}
if (!isKaraokeLikeLineSet(lines)) {
return unique;
}
return [unique.join(' ')];
}