diff --git a/ox/srt.py b/ox/srt.py index 5191a55..c29ae8b 100644 --- a/ox/srt.py +++ b/ox/srt.py @@ -63,10 +63,6 @@ def load(filename, offset=0): Returns list with dicts that have in, out, value and id ''' srt = [] - - def parse_time(t): - return offset + ox.time2ms(t.replace(',', '.')) / 1000 - with open(filename, 'rb') as f: encoding = _detect_encoding(f) data = f.read() @@ -77,7 +73,21 @@ def load(filename, offset=0): data = data.decode('latin-1') except: 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') if not data.endswith('\n\n'):