## @booker_duan ## This programe translate Simplified Chinese to Tranditional Chinese ## Copy this script to ASS files directoy and run
import glob import os import opencc import sys
# Set python encoding reload(sys) sys.setdefaultencoding('utf-8')
# Find ASS files from run-dir and sub run-dir match=glob.glob(r'*.ass') match_sub=glob.glob(r'*/*.ass') match[-1:-1]=match_sub match.sort()
if match: # Print file message print"Find matched ASS file, TOTAL:\t"+str(len(match)) match_count=0 for fname in match: print'['+str(match_count)+']\t'+fname match_count=match_count+1
for fname in match: print"***Handling \t[ " + fname + " ]***"
# Read ASS file content fread=open(fname,"r") lines=fread.readlines() fread.close()
# Backup origin file if no .bak file bak_match=glob.glob(fname+".bak") ifnot bak_match: os.rename(fname, fname+".bak")
# Operate ASS file content line by line fwrite=open(fname,"w") for line in lines: if line: #line.rstrip("\r\n") line=opencc.convert(line, config='s2t.json') #print line line.encode('utf-8') fwrite.write(line) fwrite.close()
print"***Complete \t[ " + fname + " ]***"
# No matching else: print"[STOP]: No matched ASS file"