]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[utils] Support 'dur' field in TTML
authorYen Chi Hsuan <yan12125@gmail.com>
Tue, 12 May 2015 04:47:37 +0000 (12:47 +0800)
committerYen Chi Hsuan <yan12125@gmail.com>
Tue, 12 May 2015 04:47:37 +0000 (12:47 +0800)
test/test_utils.py
youtube_dl/utils.py

index 86b110a7d87d7eed8811d971f221e4944dfea5b2..b401070371bfcea183abc2b08419ddd0c75dd3fe 100644 (file)
@@ -600,7 +600,7 @@ ffmpeg version 2.4.4 Copyright (c) 2000-2014 the FFmpeg ...'''), '2.4.4')
                 <div xml:lang="en">
                     <p begin="0" end="1">The following line contains Chinese characters and special symbols</p>
                     <p begin="1" end="2">第二行<br/>♪♪</p>
-                    <p begin="2" end="3"><span>Third<br/>Line</span></p>
+                    <p begin="2" dur="1"><span>Third<br/>Line</span></p>
                 </div>
             </body>
             </tt>'''
index d73efcf25c6acbdd34a5412ab3b559895e2312a6..5439fcb35d3212fc6ea66f31b6eab9d86bda2301 100644 (file)
@@ -1866,10 +1866,14 @@ def dfxp2srt(dfxp_data):
     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)