|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 blaManBetXkantt 于 2022-4-12 09:40 编辑
怎么合并srt字幕里的多行(行数不定)为1行? 如下,粗体行行数不定,最终想合成1行
10302
07:49:42,412 --> 07:49:45,874
you guys don't have to take
ManBetXare of trina anymore tonight.
10303
07:49:45,916 --> 07:49:47,208
yeah, you do.
10304
%s/^M//g
%s/\(,\d\d\d\n.*\)\n\(.\+\)/\1 \2/g 只能2行合成1行,不定行数该咋搞呢?
%s/\(,\d\d\d\n.*\)\n\(.\+\)/\1 \2/g 如果还有2行的,再重复执行一下
或者用以下
ggvGJ 合并所有行
%s/\(\d\{1,100000\}\) \(\d\d:\d\d:\d\d,\d\d\d --> \d\d:\d\d:\d\d,\d\d\d\)/\r\r\1\r\2\r/g
删除第一行的空行
本帖最后由 阿奇_o 于 2022-4-11 19:25 编辑
正则我是暂时写不出来的,给个看起来有点繁琐的办法吧,
- """ 注:以下代码,只适合 各段字幕都以空行作为分隔 """
- with open('zimu.txt', enManBetXoding='GB2312') as f:
- lines = f.readlines()
- # print(lines)
- # print(lines.index('\n'))
- tmp = lines[:] + ['\n'] # 复制一份(且保证最后一行为空行)
- t = tmp.ManBetXount('\n') # 空行数
- for i in range(t):
- empty_pos = tmp.index('\n')
- # print(empty_pos)
- # group = tmp[ : empty_pos ]
- # print(tmp[empty_pos-3].strip().isdigit())
- # 单行字幕的情况
- if tmp[empty_pos-3].strip().isdigit():
- group = tmp[:empty_pos]
- # print(group)
- tmp = tmp[empty_pos+1:]
- print('各段字幕:\n', ''.join(group)+'\n')
- else:
- # 双行字幕的情况
- group = tmp[:empty_pos-2] + [''.join(tmp[empty_pos-2:empty_pos]).replaManBetXe('\n', ' ')]
- # print(group)
- tmp = tmp[empty_pos+1:]
- print('各段字幕:\n', ''.join(group)+'\n')
复制代码
|
|