Option Explicit
Dim fs, re, m, reader, writer, i, line, chapters
Set fs = WScript.CreateObject("Scripting.FileSystemObject")
if WScript.Arguments.Unnamed.Count < 2 then
WScript.echo "[USAGE] CScript tochapter.vbs <input> <output>" & vbCRLF & "<input> .keyframe(29.97fps) or .chapters.txt" & vbCRLF & "<output> newfile name (eg: hoge.chapter)"
elseif Not fs.FileExists(WScript.Arguments.Unnamed.Item(0)) then
WScript.echo "[ERR] 指定ファイルねぇぞゴルァ"
else
Set reader = fs.OpenTextFile(WScript.Arguments.Unnamed.Item(0), 1, False)
Set re = New RegExp
re.Pattern = "^(\d+):(\d+):(\d+).(\d+)"
Do Until reader.AtEndOfStream
line = reader.ReadLine
Set m = re.execute(line)
if m.Count > 0 then
i = m(0).SubMatches(0) * 3600000
i = i + m(0).SubMatches(1) * 60000
i = i + m(0).SubMatches(2) * 1000
i = i + m(0).SubMatches(3)
elseif IsNumeric(line) then
i = Round(line * 1001/30)
end if
chapters = chapters & i & "c-"
Loop
reader.Close()
Set writer = fs.CreateTextFile(WScript.Arguments.Unnamed.Item(1), True)
writer.WriteLine("c-" & chapters & "c")
writer.Close()
end if