mirror of
https://codeberg.org/polarisfm/youtube-dl
synced 2024-11-26 10:24:33 +01:00
Merge TTML subtitle cues with same timecodes while converting to SRT
This commit is contained in:
parent
66d106f270
commit
cbb5155060
@ -2831,6 +2831,9 @@ def dfxp2srt(dfxp_data):
|
||||
continue
|
||||
default_style.update(style)
|
||||
|
||||
last_begin_time = None
|
||||
last_end_time = None
|
||||
|
||||
for para, index in zip(paras, itertools.count(1)):
|
||||
begin_time = parse_dfxp_time_expr(para.attrib.get('begin'))
|
||||
end_time = parse_dfxp_time_expr(para.attrib.get('end'))
|
||||
@ -2841,12 +2844,20 @@ def dfxp2srt(dfxp_data):
|
||||
if not dur:
|
||||
continue
|
||||
end_time = begin_time + dur
|
||||
out.append('%d\n%s --> %s\n%s\n\n' % (
|
||||
index,
|
||||
srt_subtitles_timecode(begin_time),
|
||||
srt_subtitles_timecode(end_time),
|
||||
parse_node(para)))
|
||||
|
||||
if begin_time == last_begin_time and end_time == last_end_time:
|
||||
out.append('%s\n' % (parse_node(para)))
|
||||
else:
|
||||
out.append('\n%d\n%s --> %s\n%s\n' % (
|
||||
index,
|
||||
srt_subtitles_timecode(begin_time),
|
||||
srt_subtitles_timecode(end_time),
|
||||
parse_node(para)))
|
||||
|
||||
last_begin_time = begin_time
|
||||
last_end_time = end_time
|
||||
|
||||
out.append('\n')
|
||||
return ''.join(out)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user