基本功能: 双语字幕中英文分离, 各自成一行
避免srtedit在合并某些字幕后中英文各占不止一行, 导致最终生成的字幕占4行的尴尬情况.
基本示例:
源文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
1 00:01:06,107 --> 00:01:07,483 This is a test 这是一个测试 2 00:01:12,906 --> 00:01:16,450 测试! 快测试呀 3 00:01:18,703 --> 00:01:19,953 测试好了没有? 我问你好了没有? Is the test OK? What's the result? |
处理后:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
1 00:01:06,107 --> 00:01:07,483 这是一个测试 This is a test 2 00:01:12,906 --> 00:01:16,450 测试! 快测试呀 3 00:01:18,703 --> 00:01:19,953 测试好了没有? 我问你好了没有? Is the test OK? What's the result? |
基本功能完好,细节有些小毛病…
以下是所有代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#coding:utf-8 import re import sys if len(sys.argv)<2: exit(); filename = sys.argv[1] f=file(filename,'r') a=f.read() try: a=a.decode('utf8') except: pass aa=a.split('\n\n') f.close() k=[] for a in aa: if len(a.split('\n'))<2: for m in a.split('\n'): k.append(m.replace('- ','-')) continue time = "\n".join(a.split('\n')[:2]) chi = [x for x in a.split('\n')[2:] if x != x.encode('unicode-escape')] eng = [x for x in a.split('\n')[2:] if x == x.encode('unicode-escape')] k.append(time) if len(chi)>0: k.append(" ".join(chi).replace('- ','-')) if len(eng)>0: k.append(" ".join(eng).replace('- ','-')) k.append('') f=open(filename+"_fixed.srt","w") for m in k: f.write(m.encode(sys.getfilesystemencoding())+'\n') f.close() |
请问可不可以做成文件呢?
特别想要这样的脚本~谢谢~
用写了一个把多行转换成单行 srt 的 sed 脚本…
不能用 pre 标签?
嗯, 我帮乃编辑上了…
顺便膜拜 #大大大大大大大大大大大大
火星猫菊苣快把 > 改成 >
> 改成 >
看看现在对了么?
这功能不错哦
想到了我以前物理老师:
“这是一个题。”
“快做啊,做好了没?”
“好了没有? 我问你做好了没有?”
囧= =||||
我也谢过类似的脚本不过合并双字幕功能直接cat起来用mplayer的“-overlapsub”解决。
字幕组众大大用srtedit通常能合并,但是就是遗留下来了这么一个很讨厌的问题,呵呵
都有vps了,给apache装个mod_python就可以直接上线跑了
这个要问楼下的moja要…
写个程序用我更喜欢~
能改成 php 上传字幕去修改的么?
额,其实我没懂您的意思…
笨哦~