diff --git a/subtitles.py b/subtitles.py index b9d590b..b0d0bb7 100755 --- a/subtitles.py +++ b/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))