File size: 810 Bytes
f752c8d
 
 
 
 
 
5af1a37
 
 
 
 
f752c8d
 
 
 
 
 
 
 
767dc8f
f752c8d
767dc8f
f752c8d
 
 
 
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
import ass
import os
import sys

SUB_NAME = sys.argv[1]

fname_base = os.path.splitext(os.path.split(SUB_NAME)[1])[0]
# cn_name = os.path.splitext(SUB_NAME)[0] + ".cn.txt"
cn_name = "data/" + fname_base + ".cn.txt"
# en_name = os.path.splitext(SUB_NAME)[0] + ".en.txt"
en_name = "data/" + fname_base + ".en.txt"

with open(SUB_NAME, "r", encoding='utf-8-sig') as f:
    doc = ass.parse(f)

cn_file = open(cn_name, "w")
en_file = open(en_name, "w")

for e in doc.events:
    if e.style == '英' or e.style == '英 - Tipped':
        en_file.write(f"[{e.start.total_seconds()}] {e.text.strip()} [{e.end.total_seconds()}]\n")
    elif e.style == '中' or e.style == '中 - Tipped':
        cn_file.write(f"[{e.start.total_seconds()}] {e.text.strip()} [{e.end.total_seconds()}]\n")

cn_file.close()
en_file.close()