This commit is contained in:
Niklas 2020-10-04 02:10:50 -04:00 committed by GitHub
commit 3081a00e93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 10 deletions

View File

@ -1263,18 +1263,15 @@ The first line
srt_data = '''1
00:00:02,080 --> 00:00:05,839
<font color="white" face="sansSerif" size="16">default style<font color="red">custom style</font></font>
2
00:00:02,080 --> 00:00:05,839
<b><font color="cyan" face="sansSerif" size="16"><font color="lime">part 1
</font>part 2</font></b>
3
2
00:00:05,839 --> 00:00:09,560
<u><font color="lime">line 3
part 3</font></u>
4
3
00:00:09,560 --> 00:00:12,359
<i><u><font color="yellow"><font color="lime">inner
</font>style</font></u></i>

View File

@ -4560,6 +4560,10 @@ def dfxp2srt(dfxp_data):
continue
default_style.update(style)
last_begin_time = None
last_end_time = None
index_offset = 0
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'))
@ -4570,12 +4574,23 @@ 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:
index_offset += 1
out.append('%s\n' % (parse_node(para)))
else:
if out:
out.append('\n')
out.append('%d\n%s --> %s\n%s\n' % (
index - index_offset,
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)