srt fixes

This commit is contained in:
j 2019-12-21 20:18:19 +02:00
parent 03c1191550
commit 75cfe74877

View file

@ -63,10 +63,6 @@ def load(filename, offset=0):
Returns list with dicts that have in, out, value and id Returns list with dicts that have in, out, value and id
''' '''
srt = [] srt = []
def parse_time(t):
return offset + ox.time2ms(t.replace(',', '.')) / 1000
with open(filename, 'rb') as f: with open(filename, 'rb') as f:
encoding = _detect_encoding(f) encoding = _detect_encoding(f)
data = f.read() data = f.read()
@ -77,7 +73,21 @@ def load(filename, offset=0):
data = data.decode('latin-1') data = data.decode('latin-1')
except: except:
print("failed to detect encoding, giving up") print("failed to detect encoding, giving up")
return srt return []
return loads(data, offset)
def loads(data, offset=0):
'''Parses an srt file
filename: path to an srt file
offset (float, seconds): shift all in/out points by offset
Returns list with dicts that have in, out, value and id
'''
srt = []
def parse_time(t):
return offset + ox.time2ms(t.replace(',', '.')) / 1000
data = data.replace('\r\n', '\n') data = data.replace('\r\n', '\n')
if not data.endswith('\n\n'): if not data.endswith('\n\n'):