Last active
July 28, 2018 06:22
-
-
Save chawyehsu/9b1d8f4e88a7cdc45cb3 to your computer and use it in GitHub Desktop.
自用小脚本:对从ch9下载的字幕文件进行自动化整理,去除无用行方便导入Aegisub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, glob | |
keys = [ | |
"WEBVTT", | |
"-->" | |
] | |
def hasKey(array, line): | |
for item in array: | |
if item in line: | |
return True | |
return False | |
for files in glob.glob(os.path.abspath(os.curdir)+'\\*.txt'): | |
if not ".Cleaned.txt" in files: | |
with open(files, 'r') as f: | |
with open(files+".Cleaned.txt", 'w') as g: | |
for line in f.readlines(): | |
if not hasKey(keys, line): | |
g.write(line) | |
os.remove(files) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment