@@ -9,29 +9,20 @@ sub init()
9
9
m .captionList = []
10
10
m .reader = createObject ("roUrlTransfer " )
11
11
m .font = CreateObject ("roSGNode " , "Font" )
12
- fetchFont ()
12
+ m .tags = CreateObject ("roRegex " , "{\\an\d*}|<.*?>|<.*?>" , "s" )
13
+ setFont ()
13
14
end sub
14
15
15
16
16
- sub fetchFont ()
17
+ sub setFont ()
17
18
fs = CreateObject ("roFileSystem " )
18
- fontlist = fs .Find ("tmp:/" , ".*\.(otf|ttf)" )
19
- if fontlist .count () = 0
20
- re = CreateObject ("roRegex " , "Name.:.(.*?).,.Size" , "s" )
21
- m .filename = APIRequest ("FallbackFont/Fonts" ).GetToString ()
22
- m .filename = re .match (m .filename )
23
- if m .filename .count () <> 0
24
- m .filename = m .filename [1 ]
25
- APIRequest ("FallbackFont/Fonts/" + m .filename ).gettofile ("tmp:/" + m .filename )
26
- m .font .uri = "tmp:/" + m .filename
27
- m .font .size = 60
28
- else
29
- m .font = "font:LargeBoldSystemFont"
30
- end if
31
- else
19
+ fontlist = fs .Find ("tmp:/" , "font\.(otf|ttf)" )
20
+ if fontlist .count () > 0
32
21
m .font .uri = "tmp:/" + fontlist [0 ]
33
- m .font .size = 60
22
+ else
23
+ m .font = "font:LargeBoldSystemFont"
34
24
end if
25
+ m .font .size = 60
35
26
end sub
36
27
37
28
sub fetchCaption ()
@@ -79,8 +70,9 @@ sub updateCaption ()
79
70
m .top .currentPos = m .top .currentPos + 100
80
71
texts = []
81
72
for each entry in m .captionList
82
- if entry ["start" ] <= m .top .currentPos and m .top .currentPos <= entry ["end" ]
83
- texts .push (entry ["text" ])
73
+ if entry ["start" ] <= m .top .currentPos and m .top .currentPos < entry ["end" ]
74
+ t = m .tags .replaceAll (entry ["text" ], "" )
75
+ texts .push (t )
84
76
end if
85
77
end for
86
78
labels = []
@@ -99,45 +91,45 @@ sub updateCaption ()
99
91
lglist [8 ].getchild (q ).color = & HFFFFFFFF
100
92
end for
101
93
m .top .currentCaption = lglist
102
- else if m .top .playerState = "playingOnWait "
94
+ else if right ( m .top .playerState , 4 ) = "Wait "
103
95
m .top .playerState = "playingOn"
104
96
else
105
97
m .top .currentCaption = []
106
98
end if
107
99
end sub
108
100
109
101
function ms (t ) as integer
110
- r = CreateObject ("roRegex " , ":|\." , "" )
111
- l = r .split (t )
112
- return 3600000 * val (l [0 ]) + 60000 * val (l [1 ]) + 1000 * val (l [2 ]) + val (l [3 ])
102
+ tt = t .tokenize (":" )
103
+ return 3600000 * val (tt [0 ]) + 60000 * val (tt [1 ]) + 1000 * val (tt [2 ]) + val (t .right (3 ))
113
104
end function
114
105
115
- function splitLines (text )
116
- r = CreateObject ("roRegex " , chr (10 ), "" )
117
- return r .split (text )
106
+
107
+
108
+ function getstart (text )
109
+ return ms (text .left (12 ))
118
110
end function
119
111
120
- function strip (text ) as string
121
- leading = CreateObject ( " roRegex " , "^\s+" , "" )
122
- trailing = CreateObject ( " roRegex " , "\s+$" , "" )
123
- text = leading . replaceall ( text , "" )
124
- text = trailing . replaceall (text , "" )
125
- return text
112
+ function getend (text )
113
+ return ms ( text )
114
+ end function
115
+
116
+ function isTime (text )
117
+ return text . mid ( 13 , 3 ) = "-->"
126
118
end function
127
119
128
120
function parseVTT (text )
129
- timestamp = "(\d\d:\d\d:\d\d\.\d\d\d) --> (\d\d:\d\d:\d\d\.\d\d\d)"
130
- re = CreateObject ("roRegex " , timestamp + " region.*" , "" )
131
- timeList = re .matchall (text )
132
- textList = re .split (text )
133
- textList .shift ()
134
121
captionList = []
135
- for i = 0 to textList .count () - 1
136
- textLines = splitLines (strip (textList [i ]))
137
- for each line in textLines
138
- entry = { "start" : ms (timeList [i ][1 ]), "end" : ms (timeList [i ][2 ]), "text" : strip (line ), "color" : "" }
122
+ lines = text .tokenize (Chr (0 ))[0 ]
123
+ lines = lines .tokenize (Chr (10 ))
124
+ size = lines .count ()
125
+ for i = 2 to size - 1
126
+ if isTime (lines [i ])
127
+ curStart = ms (lines [i ].left (12 ))
128
+ curEnd = ms (lines [i ].mid (17 , 12 ))
129
+ else
130
+ entry = { "start" : curStart , "end" : curEnd , "text" : lines [i ].trim () }
139
131
captionList .push (entry )
140
- end for
132
+ end if
141
133
end for
142
134
return captionList
143
135
end function
0 commit comments