Skip to content

Instantly share code, notes, and snippets.

@chawyehsu
Last active July 28, 2018 06:22
Show Gist options
  • Save chawyehsu/9b1d8f4e88a7cdc45cb3 to your computer and use it in GitHub Desktop.
Save chawyehsu/9b1d8f4e88a7cdc45cb3 to your computer and use it in GitHub Desktop.
自用小脚本:对从ch9下载的字幕文件进行自动化整理,去除无用行方便导入Aegisub
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