-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript2sami.py
40 lines (35 loc) · 1.17 KB
/
script2sami.py
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
from xml.etree.ElementTree import parse
from jinja2 import Template,Environment,FileSystemLoader
import os
import sys
def mkSami(script):
vlist = parse(script).getroot().getiterator("data")
plist = [
{
"time":d.findtext("time"),
"kor":d.findtext("kor"),
"eng":d.findtext("eng")
}
for d in vlist
]
for phrase in plist:
phrase['time'] = str(int(phrase['time'])*1000) # sec --> milli sec
if phrase['kor'] == "...":
phrase['kor'] = " "
if phrase['eng'] == "...":
phrase['eng'] = " "
currFileDirPath = os.path.dirname(os.path.abspath(__file__))
env = Environment(
loader=FileSystemLoader(currFileDirPath)
)
template = env.get_template('sami_template.txt')
result = template.render(title="SAMI Subtitles", plist=plist)
return result
def main():
if len(sys.argv) == 2:
inputPath = sys.argv[1]
else:
inputPath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "script_sample.xml")
print(mkSami(inputPath))
if __name__ == "__main__":
main()