1 # -*- coding: UTF-8 -*- 2 3 ‘‘‘ 4 只适用于下面这种形式的ass文件 5 [Events] 6 Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text 7 Dialogue: 0,0:1:30.19,0:1:32.89,Default,,0000,0000,0000,,{\t(1308,2700,\1c&H000000&\3c&H000000&\4c&H000000&)}没有啊... 8 ‘‘‘ 9 10 # t1:t2:t3.t4 11 # 00:01:30.19 12 def trans(s, t1, t2, t3, t4): 13 s1 = s.split(‘:‘) 14 time1, time2 = int(s1[0]), int(s1[1]) 15 time3, time4 = map(int, s1[2].split(‘.‘)) 16 17 time1 += t1 18 time2 += t2 19 time3 += t3 20 time4 += t4 21 22 while time4 >= 100: 23 time4 -= 100 24 time3 += 1 25 while time4 < 0: 26 time4 += 100 27 time3 -= 1 28 29 while time3 >= 60: 30 time3 -= 60 31 time2 += 1 32 while time3 < 0: 33 time3 += 60 34 time2 -= 1 35 36 while time2 >= 60: 37 time2 -= 60 38 time1 += 1 39 while time2 < 0: 40 time2 += 60 41 time1 -= 1 42 43 return str(time1) + ‘:‘ + str(time2) + ‘:‘ + str(time3) + ‘.‘ + str(time4) 44 45 # 修改字幕文件名称 46 f = open(‘src.ass‘, ‘r‘, encoding=‘UTF-8‘) 47 fo = open(‘des.ass‘, ‘w‘, encoding=‘UTF-8‘) 48 lines = f.readlines() 49 for line in lines: 50 if line[:8] == ‘Dialogue‘: 51 lis = line.split(‘,‘) 52 st = lis[1] 53 ed = lis[2] 54 # 修改时间差 55 new_st = trans(st, 0, 0, 10, 0) 56 new_ed = trans(ed, 0, 0, 10, 0) 57 lis[1] = new_st 58 lis[2] = new_ed 59 new_line = ‘,‘.join(lis) 60 fo.write(new_line) 61 else: 62 fo.write(line) 63 f.close() 64 fo.close()
原文地址:https://www.cnblogs.com/hexsix/p/11221961.html
时间: 2024-10-24 15:35:05