Skip to content

Commit 45d297f

Browse files
committed
ssa: treat \N as \n
1 parent 719a501 commit 45d297f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

ssa.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ func NewFromSSA(s string) (res Subtitle, err error) {
6363
continue
6464
}
6565

66+
// some ass/ssa files use \N as a line break in captions
67+
text = strings.ReplaceAll(text, "\\N", "\\n")
68+
6669
o.Text = strings.Split(text, "\\n")
6770

6871
if len(o.Text) > 0 {

ssa_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ func TestNewFromSsa(t *testing.T) {
1010
in := "[Events]\n" +
1111
"Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text\n" +
1212
"Dialogue: 0,0:01:06.37,0:01:08.04,Default,,0000,0000,0000,,Honey, I'm home!\n" +
13-
"Dialogue: 0,0:01:09.05,0:01:10.69,Default,,0000,0000,0000,,Hi.\\n- Hi, love.\n"
13+
"Dialogue: 0,0:01:09.05,0:01:10.69,Default,,0000,0000,0000,,Hi.\\n- Hi, love.\n" +
14+
"Dialogue: 0,0:02:41.77,0:02:43.74,dazed,,0000,0000,0000,,- I'm headed this way.\\N- Oh.\n"
1415
expected := Subtitle{[]Caption{{
1516
1,
1617
makeTime(0, 1, 6, 370),
@@ -21,6 +22,11 @@ func TestNewFromSsa(t *testing.T) {
2122
makeTime(0, 1, 9, 50),
2223
makeTime(0, 1, 10, 690),
2324
[]string{"Hi.", "- Hi, love."},
25+
}, {
26+
3,
27+
makeTime(0, 2, 41, 770),
28+
makeTime(0, 2, 43, 740),
29+
[]string{"- I'm headed this way.", "- Oh."},
2430
}}}
2531
res, err := NewFromSSA(in)
2632
assert.Equal(t, nil, err)

0 commit comments

Comments
 (0)