[utils] Support alternative timestamp format in TTML

Fixes #7608
This commit is contained in:
Yen Chi Hsuan 2015-12-19 19:29:51 +08:00
parent d631d5f9f2
commit db2fe38b55
2 changed files with 3 additions and 2 deletions

View File

@ -667,6 +667,7 @@ def test_parse_dfxp_time_expr(self):
self.assertEqual(parse_dfxp_time_expr('0.1s'), 0.1) self.assertEqual(parse_dfxp_time_expr('0.1s'), 0.1)
self.assertEqual(parse_dfxp_time_expr('00:00:01'), 1.0) self.assertEqual(parse_dfxp_time_expr('00:00:01'), 1.0)
self.assertEqual(parse_dfxp_time_expr('00:00:01.100'), 1.1) self.assertEqual(parse_dfxp_time_expr('00:00:01.100'), 1.1)
self.assertEqual(parse_dfxp_time_expr('00:00:01:100'), 1.1)
def test_dfxp2srt(self): def test_dfxp2srt(self):
dfxp_data = '''<?xml version="1.0" encoding="UTF-8"?> dfxp_data = '''<?xml version="1.0" encoding="UTF-8"?>

View File

@ -1982,9 +1982,9 @@ def parse_dfxp_time_expr(time_expr):
if mobj: if mobj:
return float(mobj.group('time_offset')) return float(mobj.group('time_offset'))
mobj = re.match(r'^(\d+):(\d\d):(\d\d(?:\.\d+)?)$', time_expr) mobj = re.match(r'^(\d+):(\d\d):(\d\d(?:(?:\.|:)\d+)?)$', time_expr)
if mobj: if mobj:
return 3600 * int(mobj.group(1)) + 60 * int(mobj.group(2)) + float(mobj.group(3)) return 3600 * int(mobj.group(1)) + 60 * int(mobj.group(2)) + float(mobj.group(3).replace(':', '.'))
def srt_subtitles_timecode(seconds): def srt_subtitles_timecode(seconds):