def load(data, encoding=None): """ Load subtitle """ pattern = re.compile(r"\{(?P<start>\d*)\}\{(?P<stop>\d*)\}(?P<text>.*)") result = [] lines = data.splitlines() for line in lines: line = line.strip() if line == '' or line.startswith('#'): continue m = pattern.match(to_unicode(line, encoding)) if m is None: raise SubtitlesFormatError #print 'invalid line %r', line #continue d = m.groupdict() start = Time.from_seconds(int(d['start'])) try: stop = Time.from_seconds(int(d['stop'])) except: stop = None text = d['text'].replace('|', '\n') result.append(Verse(start, stop, text)) return result, True
def load(data, encoding=None): """ Load subtitle """ pattern = re.compile(r"\[(?P<start>\d+)\]\[(?P<stop>\d*)\](?P<text>.*)") result = [] lines = data.splitlines() for line in lines: m = pattern.match(to_unicode(line, encoding)) #if m is None: # raise SubtitlesFormatError g = m.groupdict() start = Time.from_seconds(int(g['start']), 1) try: stop = Time.from_seconds(int(g['stop']), 1) except ValueError: stop = None text = g['text'].replace('|', '\n') result.append(Verse(start, stop, text)) return result, False