-
Notifications
You must be signed in to change notification settings - Fork 0
/
srt_test.go
109 lines (101 loc) · 1.9 KB
/
srt_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"encoding/json"
"fmt"
"testing"
)
func ExampleSrtParse() {
pp(ParseSRT(`
1
00:00:02,360 --> 00:00:05,360
EINE NETFLIX ORIGINAL SERIE
2
00:00:05,440 --> 00:00:07,560
[ernste Musik]
3
00:00:12,000 --> 00:00:15.080
[Mann] Ich wusste immer,
dass der Tag meiner Abrechnung kommt.
`))
// Output:
// {
// "Sub": [
// {
// "Number": 1,
// "From": 2360000000,
// "To": 5360000000,
// "Lines": [
// "EINE NETFLIX ORIGINAL SERIE"
// ]
// },
// {
// "Number": 2,
// "From": 5440000000,
// "To": 7560000000,
// "Lines": [
// "[ernste Musik]"
// ]
// },
// {
// "Number": 3,
// "From": 12000000000,
// "To": 15080000000,
// "Lines": [
// "[Mann] Ich wusste immer,",
// "dass der Tag meiner Abrechnung kommt."
// ]
// }
// ]
// }
}
func ExampleSrtParse2() {
pp(ParseSRT(`
1
00:00:31.520 --> 00:00:32.640 position:50.00%,middle align:middle size:80.00% line:84.67%
[sopla el viento]
2
00:00:32.720 --> 00:00:35.240 position:50.00%,middle align:middle size:80.00% line:84.67%
[hojas que crujen]
`))
// Output:
// {
// "Sub": [
// {
// "Number": 1,
// "From": 31520000000,
// "To": 32640000000,
// "Lines": [
// "[sopla el viento]"
// ]
// },
// {
// "Number": 2,
// "From": 32720000000,
// "To": 35240000000,
// "Lines": [
// "[hojas que crujen]"
// ]
// }
// ]
// }
}
func TestParseTimespan(t *testing.T) {
s := `00:00:31.520 --> 00:00:32.640 position:50.00%,middle align:middle size:80.00% line:84.67%
[sopla el viento]`
t0, t1, i, _ := parseTimespan(s, 0)
fmt.Println("t0", t0, "t1", t1)
if s[i:] != "[sopla el viento]" {
t.Fatal("bad", s[i:])
}
}
func pp(x interface{}, e error) {
if e != nil {
fmt.Println(e)
return
}
b, e := json.MarshalIndent(x, "", "\t")
if e != nil {
fmt.Println(e)
}
fmt.Println(string(b))
}