korean
This commit is contained in:
parent
d4a78ebbd1
commit
14b278fdd1
1 changed files with 12 additions and 3 deletions
13
subtitles.py
13
subtitles.py
|
@ -80,7 +80,7 @@ def render_subtitles(item_json, output_json, output_srt):
|
||||||
clip_subtitles.sort(key=lambda c: (c['in'], c['out'], c['id']))
|
clip_subtitles.sort(key=lambda c: (c['in'], c['out'], c['id']))
|
||||||
|
|
||||||
for sub in clip_subtitles:
|
for sub in clip_subtitles:
|
||||||
sub_in = float('%0.3f'% (sub['in'] + position))
|
sub_in = float('%0.3f' % (sub['in'] + position))
|
||||||
sub_out = float('%0.3f' % (sub['out'] + position))
|
sub_out = float('%0.3f' % (sub['out'] + position))
|
||||||
sub_id = '%0.3f-%0.3f' % (sub_in, sub_out)
|
sub_id = '%0.3f-%0.3f' % (sub_in, sub_out)
|
||||||
if sub_id not in subs:
|
if sub_id not in subs:
|
||||||
|
@ -90,7 +90,15 @@ def render_subtitles(item_json, output_json, output_srt):
|
||||||
'value': [],
|
'value': [],
|
||||||
'ids': []
|
'ids': []
|
||||||
}
|
}
|
||||||
subs[sub_id]['value'].append(sub['value'].replace('<br>', ''))
|
is_korean = 'lang="ko"' in sub['value']
|
||||||
|
value = sub['value'].replace('<br>', '')
|
||||||
|
value = value.replace('<span lang="ko">', '').replace('</span>', '').strip()
|
||||||
|
# just use strip_tags?
|
||||||
|
# value = ox.strip_tags(ox.decode_html(sub['value']))
|
||||||
|
if is_korean:
|
||||||
|
subs[sub_id]['value'].append(value)
|
||||||
|
else:
|
||||||
|
subs[sub_id]['value'].insert(0, value)
|
||||||
subs[sub_id]['ids'].append(sub['id'])
|
subs[sub_id]['ids'].append(sub['id'])
|
||||||
position += clip['duration']
|
position += clip['duration']
|
||||||
subs = sorted(subs.values(), key=lambda c: (c['in'], c['out']))
|
subs = sorted(subs.values(), key=lambda c: (c['in'], c['out']))
|
||||||
|
@ -103,6 +111,7 @@ def render_subtitles(item_json, output_json, output_srt):
|
||||||
with open(output_json, 'w') as fd:
|
with open(output_json, 'w') as fd:
|
||||||
json.dump(subtitles, fd, indent=4, ensure_ascii=False)
|
json.dump(subtitles, fd, indent=4, ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if os.path.exists('subtitles.json'):
|
if os.path.exists('subtitles.json'):
|
||||||
items = json.load(open('subtitles.json'))
|
items = json.load(open('subtitles.json'))
|
||||||
|
|
Loading…
Reference in a new issue