字幕校准脚本

1 先在编辑器把时间补充上,内容写上特殊字符,如 OOO
2 然后下载字幕文件如 srt, 拷贝到 linux 下,存成 v.txt
3 运行 ad.py 会把 OOO 杭内容过滤掉,后面的内容依次往上提。
代码如下:

#!/usr/bin/env python

if name == 'main':
f=open("v.txt", "r")
plist=[]
mlist=[]
tlist=[]
while True:
ptr1 = f.readline()
tm1 = f.readline()
msg1 = f.readline()
blank = f.readline()
ptr = ptr1.strip('\n')
if not ptr:
break
tm = tm1.strip('\n')
msg = msg1.strip('\n')
plist.append(ptr)
mlist.append(msg)
tlist.append(tm)
diff=0
for i in range(0, len(mlist)):
if(i+diff >= len(mlist)):
break
print "%s\n%s" % (plist[i], tlist[i])
while(mlist[i+diff] == "ooo"):
diff = diff + 1
print "%s\n" % mlist[i+diff]

        #print "%s\n%s\n%s\n" % (ptr, tm, msg)

This entry was posted in DEVOPS. Bookmark the permalink. Follow any comments here with the RSS feed for this post. Both comments and trackbacks are currently closed.

1 Comment