Skip to content

Commit

Permalink
[utils] Support 'dur' field in TTML
Browse files Browse the repository at this point in the history
  • Loading branch information
Yen Chi Hsuan committed May 12, 2015
1 parent 5332fd9 commit 7dff036
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/test_utils.py
Expand Up @@ -600,7 +600,7 @@ def test_dfxp2srt(self):
<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>'''
Expand Down
8 changes: 6 additions & 2 deletions youtube_dl/utils.py
Expand Up @@ -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)
Expand Down

0 comments on commit 7dff036

Please sign in to comment.