This commit is contained in:
j 2017-05-21 11:55:48 +00:00
parent 09ef40893b
commit 55c55d8498

View file

@ -71,18 +71,32 @@ def render_subtitles(item_json, output_json, output_srt):
subtitles = []
position = 0
subs = {}
for clip in item['vocals']:
if not clip.get('blank'):
# vocals/A/A4_chaton.wav
id = clip['path'].split('/')[-1][:2]
clip_subtitles = get_subtitles(items, id)
clip_subtitles.sort(key=lambda c: (c['in'], c['out'], c['id']))
for sub in clip_subtitles:
srt = {}
srt['in'] = sub['in'] + position
srt['out'] = sub['out'] + position
srt['value'] = sub['value'].replace('<br>', '')
subtitles.append(srt)
sub_in = float('%0.3f'% (sub['in'] + position))
sub_out = float('%0.3f' % (sub['out'] + position))
sub_id = '%0.3f-%0.3f' % (sub_in, sub_out)
if sub_id not in subs:
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']
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:
fd.write(ox.srt.encode(subtitles))