import ass import os import sys SUB_NAME = sys.argv[1] cn_name = os.path.splitext(SUB_NAME)[0] + ".cn.txt" en_name = os.path.splitext(SUB_NAME)[0] + ".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()