merge subs
This commit is contained in:
parent
e25fb42d2d
commit
4df413841b
1 changed files with 21 additions and 0 deletions
21
subtitles.py
21
subtitles.py
|
@ -137,6 +137,8 @@ def render_subtitles(item_json, output_json, output_srt, lang):
|
|||
'ids': [],
|
||||
'languages': []
|
||||
}
|
||||
if not sub['value']:
|
||||
continue
|
||||
if set(subs[sub_id]['languages']) != set(lang):
|
||||
if not subs[sub_id]['languages']:
|
||||
subs[sub_id]['value'] += sub['value']
|
||||
|
@ -172,6 +174,25 @@ def render_subtitles(item_json, output_json, output_srt, lang):
|
|||
if sub['value'].strip():
|
||||
subtitles.append(sub)
|
||||
|
||||
merged = []
|
||||
p = None
|
||||
for sub in subtitles:
|
||||
if not p:
|
||||
merged.append(sub)
|
||||
p = sub
|
||||
else:
|
||||
if p['out'] > sub['in']:
|
||||
if p['value'] == sub['value']:
|
||||
p['out'] = max(p['out'], sub['out'])
|
||||
else:
|
||||
p['out'] = sub['in']
|
||||
merged.append(sub)
|
||||
p = sub
|
||||
else:
|
||||
merged.append(sub)
|
||||
p = sub
|
||||
subtitles = merged
|
||||
|
||||
if output_srt:
|
||||
with open(output_srt, 'wb') as fd:
|
||||
fd.write(ox.srt.encode(subtitles))
|
||||
|
|
Loading…
Reference in a new issue