From 7dff03636a843a6990e52200edb3ecca1246b3df Mon Sep 17 00:00:00 2001 From: Yen Chi Hsuan Date: Tue, 12 May 2015 12:47:37 +0800 Subject: [PATCH] [utils] Support 'dur' field in TTML --- test/test_utils.py | 2 +- youtube_dl/utils.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/test/test_utils.py b/test/test_utils.py index 86b110a7d..b40107037 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -600,7 +600,7 @@ def test_dfxp2srt(self):

The following line contains Chinese characters and special symbols

第二行
♪♪

-

Third
Line

+

Third
Line

''' diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index d73efcf25..5439fcb35 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1866,10 +1866,14 @@ def parse_node(node): paras = dfxp.findall(_x('.//ttml:p')) for para, index in zip(paras, itertools.count(1)): + begin_time = parse_dfxp_time_expr(para.attrib['begin']) + end_time = parse_dfxp_time_expr(para.attrib.get('end')) + if not end_time: + end_time = begin_time + parse_dfxp_time_expr(para.attrib['dur']) out.append('%d\n%s --> %s\n%s\n\n' % ( index, - format_srt_time(parse_dfxp_time_expr(para.attrib.get('begin'))), - format_srt_time(parse_dfxp_time_expr(para.attrib.get('end'))), + format_srt_time(begin_time), + format_srt_time(end_time), parse_node(para))) return ''.join(out)