subs
This commit is contained in:
parent
09ef40893b
commit
55c55d8498
1 changed files with 19 additions and 5 deletions
24
subtitles.py
24
subtitles.py
|
@ -71,18 +71,32 @@ def render_subtitles(item_json, output_json, output_srt):
|
||||||
|
|
||||||
subtitles = []
|
subtitles = []
|
||||||
position = 0
|
position = 0
|
||||||
|
subs = {}
|
||||||
for clip in item['vocals']:
|
for clip in item['vocals']:
|
||||||
if not clip.get('blank'):
|
if not clip.get('blank'):
|
||||||
# vocals/A/A4_chaton.wav
|
# vocals/A/A4_chaton.wav
|
||||||
id = clip['path'].split('/')[-1][:2]
|
id = clip['path'].split('/')[-1][:2]
|
||||||
clip_subtitles = get_subtitles(items, id)
|
clip_subtitles = get_subtitles(items, id)
|
||||||
|
clip_subtitles.sort(key=lambda c: (c['in'], c['out'], c['id']))
|
||||||
|
|
||||||
for sub in clip_subtitles:
|
for sub in clip_subtitles:
|
||||||
srt = {}
|
sub_in = float('%0.3f'% (sub['in'] + position))
|
||||||
srt['in'] = sub['in'] + position
|
sub_out = float('%0.3f' % (sub['out'] + position))
|
||||||
srt['out'] = sub['out'] + position
|
sub_id = '%0.3f-%0.3f' % (sub_in, sub_out)
|
||||||
srt['value'] = sub['value'].replace('<br>', '')
|
if sub_id not in subs:
|
||||||
subtitles.append(srt)
|
subs[sub_id] = {
|
||||||
|
'in': sub_in,
|
||||||
|
'out': sub_out,
|
||||||
|
'value': [],
|
||||||
|
'ids': []
|
||||||
|
}
|
||||||
|
subs[sub_id]['value'].append(sub['value'].replace('<br>', ''))
|
||||||
|
subs[sub_id]['ids'].append(sub['id'])
|
||||||
position += clip['duration']
|
position += clip['duration']
|
||||||
|
subs = sorted(subs.values(), key=lambda c: (c['in'], c['out']))
|
||||||
|
for sub in subs:
|
||||||
|
sub['value'] = '\n'.join(sub['value'])
|
||||||
|
subtitles.append(sub)
|
||||||
|
|
||||||
with open(output_srt, 'wb') as fd:
|
with open(output_srt, 'wb') as fd:
|
||||||
fd.write(ox.srt.encode(subtitles))
|
fd.write(ox.srt.encode(subtitles))
|
||||||
|
|
Loading…
Reference in a new issue