2023-01-27 00:03:09 +00:00
|
|
|
sub init()
|
|
|
|
m.top.observeField("url", "fetchCaption")
|
2023-02-02 03:16:25 +00:00
|
|
|
m.top.currentCaption = []
|
2023-01-27 00:03:09 +00:00
|
|
|
m.top.currentPos = 0
|
|
|
|
|
|
|
|
m.captionTimer = m.top.findNode("captionTimer")
|
|
|
|
m.captionTimer.ObserveField("fire", "updateCaption")
|
|
|
|
|
|
|
|
m.captionList = []
|
|
|
|
m.reader = createObject("roUrlTransfer")
|
|
|
|
m.font = CreateObject("roSGNode", "Font")
|
2023-02-04 16:41:00 +00:00
|
|
|
m.tags = CreateObject("roRegex", "{\\an\d*}|<.*?>|<.*?>", "s")
|
|
|
|
setFont()
|
2023-01-31 23:26:20 +00:00
|
|
|
end sub
|
|
|
|
|
|
|
|
|
2023-02-04 16:41:00 +00:00
|
|
|
sub setFont()
|
2023-01-31 23:26:20 +00:00
|
|
|
fs = CreateObject("roFileSystem")
|
2023-02-04 16:41:00 +00:00
|
|
|
fontlist = fs.Find("tmp:/", "font\.(otf|ttf)")
|
|
|
|
if fontlist.count() > 0
|
2023-02-03 00:27:20 +00:00
|
|
|
m.font.uri = "tmp:/" + fontlist[0]
|
2023-02-04 16:41:00 +00:00
|
|
|
else
|
|
|
|
m.font = "font:LargeBoldSystemFont"
|
2023-01-31 23:26:20 +00:00
|
|
|
end if
|
2023-02-04 16:41:00 +00:00
|
|
|
m.font.size = 60
|
2023-01-27 00:03:09 +00:00
|
|
|
end sub
|
|
|
|
|
|
|
|
sub fetchCaption()
|
2023-02-02 03:16:25 +00:00
|
|
|
m.captionTimer.control = "stop"
|
2023-01-27 00:03:09 +00:00
|
|
|
re = CreateObject("roRegex", "(http.*?\.vtt)", "s")
|
|
|
|
url = re.match(m.top.url)[0]
|
2023-01-30 00:52:10 +00:00
|
|
|
if url <> invalid
|
2023-01-27 00:03:09 +00:00
|
|
|
m.reader.setUrl(url)
|
|
|
|
text = m.reader.GetToString()
|
|
|
|
m.captionList = parseVTT(text)
|
|
|
|
m.captionTimer.control = "start"
|
|
|
|
else
|
|
|
|
m.captionTimer.control = "stop"
|
|
|
|
end if
|
|
|
|
end sub
|
|
|
|
|
2023-01-31 23:26:20 +00:00
|
|
|
function newlabel(txt):
|
|
|
|
label = CreateObject("roSGNode", "Label")
|
|
|
|
label.text = txt
|
|
|
|
label.font = m.font
|
|
|
|
label.color = &H000000FF
|
|
|
|
label.height = 108
|
|
|
|
return label
|
|
|
|
end function
|
|
|
|
|
|
|
|
function newlayout(labels)
|
|
|
|
invis = CreateObject("roSGNode", "Label")
|
|
|
|
invis.visible = False
|
|
|
|
l = labels.count()
|
|
|
|
newlg = CreateObject("roSGNode", "LayoutGroup")
|
|
|
|
for i = 0 to 7 - l
|
|
|
|
newlg.appendchild(invis.clone(True))
|
|
|
|
end for
|
|
|
|
newlg.appendchildren(labels)
|
|
|
|
newlg.horizalignment = "center"
|
|
|
|
newlg.vertalignment = "bottom"
|
|
|
|
|
|
|
|
return newlg
|
|
|
|
end function
|
|
|
|
|
|
|
|
|
2023-01-27 00:03:09 +00:00
|
|
|
sub updateCaption ()
|
2023-02-02 03:16:25 +00:00
|
|
|
m.top.currentCaption = []
|
|
|
|
if m.top.playerState = "playingOn"
|
2023-01-27 00:03:09 +00:00
|
|
|
m.top.currentPos = m.top.currentPos + 100
|
2023-01-31 23:26:20 +00:00
|
|
|
texts = []
|
2023-01-27 00:03:09 +00:00
|
|
|
for each entry in m.captionList
|
2023-02-04 16:41:00 +00:00
|
|
|
if entry["start"] <= m.top.currentPos and m.top.currentPos < entry["end"]
|
|
|
|
t = m.tags.replaceAll(entry["text"], "")
|
|
|
|
texts.push(t)
|
2023-01-27 00:03:09 +00:00
|
|
|
end if
|
|
|
|
end for
|
2023-01-31 23:26:20 +00:00
|
|
|
labels = []
|
|
|
|
for each text in texts
|
|
|
|
labels.push(newlabel (text))
|
|
|
|
end for
|
|
|
|
lg = newlayout(labels)
|
|
|
|
lglist = []
|
|
|
|
coords = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1], [0, 0]]
|
|
|
|
for p = 0 to 8
|
|
|
|
lgg = lg.clone(True)
|
|
|
|
lgg.translation = [coords[p][0] * 5, coords[p][1] * 5]
|
|
|
|
lglist.push(lgg)
|
|
|
|
end for
|
|
|
|
for q = 0 to 7
|
|
|
|
lglist[8].getchild(q).color = &HFFFFFFFF
|
|
|
|
end for
|
|
|
|
m.top.currentCaption = lglist
|
2023-02-04 16:41:00 +00:00
|
|
|
else if right(m.top.playerState, 4) = "Wait"
|
2023-02-02 03:16:25 +00:00
|
|
|
m.top.playerState = "playingOn"
|
|
|
|
else
|
|
|
|
m.top.currentCaption = []
|
2023-01-27 00:03:09 +00:00
|
|
|
end if
|
|
|
|
end sub
|
|
|
|
|
|
|
|
function ms(t) as integer
|
2023-02-04 16:41:00 +00:00
|
|
|
tt = t.tokenize(":")
|
|
|
|
return 3600000 * val(tt[0]) + 60000 * val(tt[1]) + 1000 * val(tt[2]) + val(t.right(3))
|
2023-01-27 00:03:09 +00:00
|
|
|
end function
|
|
|
|
|
2023-02-04 16:41:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
function getstart(text)
|
|
|
|
return ms(text.left(12))
|
2023-01-27 00:03:09 +00:00
|
|
|
end function
|
|
|
|
|
2023-02-04 16:41:00 +00:00
|
|
|
function getend(text)
|
|
|
|
return ms(text)
|
|
|
|
end function
|
|
|
|
|
|
|
|
function isTime(text)
|
|
|
|
return text.mid(13, 3) = "-->"
|
2023-01-27 00:03:09 +00:00
|
|
|
end function
|
|
|
|
|
|
|
|
function parseVTT(text)
|
|
|
|
captionList = []
|
2023-02-04 16:41:00 +00:00
|
|
|
lines = text.tokenize(Chr(0))[0]
|
|
|
|
lines = lines.tokenize(Chr(10))
|
|
|
|
size = lines.count()
|
2023-02-04 21:54:05 +00:00
|
|
|
curStart = 0
|
|
|
|
curEnd = 0
|
|
|
|
for i = 0 to size - 1
|
2023-02-04 16:41:00 +00:00
|
|
|
if isTime(lines[i])
|
|
|
|
curStart = ms (lines[i].left(12))
|
|
|
|
curEnd = ms(lines[i].mid(17, 12))
|
|
|
|
else
|
|
|
|
entry = { "start": curStart, "end": curEnd, "text": lines[i].trim() }
|
2023-01-27 00:03:09 +00:00
|
|
|
captionList.push(entry)
|
2023-02-04 16:41:00 +00:00
|
|
|
end if
|
2023-01-27 00:03:09 +00:00
|
|
|
end for
|
|
|
|
return captionList
|
2023-01-30 00:52:10 +00:00
|
|
|
end function
|