字幕校准脚本

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

  1. cme
    Posted 2018年11月9日 at 下午2:34 | Permalink

    其中字幕文件内容如下格式:
    ###############################
    1
    00:00:00,857 –> 00:00:04,324
    假设你想要做一个实验。

    2
    00:00:05,000 –> 00:00:06,151
    在这个实验中,

    3
    00:00:06,175 –> 00:00:09,571
    你随机分配人们住在爆破区内

    4
    00:00:10,133 –> 00:00:15,276
    或者在一些爆炸物不会飞过他们头顶的控制区内。

    5
    00:00:16,300 –> 00:00:18,072
    他们在社区生活了多年,
    ###############################################