页次: 1
用py3进行字幕合并的脚本,新手测试,高手勿拍
import os
def read_srt(file_name):
ddict = {}
lst = open(file_name, "r").readlines()
lines = [lst[i:i+4] for i in range(0,len(lst),4)]
for ln in lines:
ddict[ln[0]] = [ln[1], ln[2]]
return ddict
en_srt = read_srt("en_srt_file_name.srt")
zh_srt = read_srt("zh_srt_file_name.srt")
with open("out_file_name.srt", "w") as out_file:
for i in range(1, len(en_srt.keys())+1):
srtkey = "%s\n"%i
en_value = en_srt[srtkey]
zh_value = zh_srt[srtkey]
out_file.write(srtkey + en_value[0] + en_value[1] + zh_value[1] + "\n")
注意替换中英文字幕的文件名,以及输出文件名就好了
页次: 1