support multipart items
This commit is contained in:
parent
f28d37e33e
commit
eb2d12a905
1 changed files with 15 additions and 7 deletions
|
@ -150,15 +150,23 @@ def extract_subtitles(item, user, layer, translate, gpu=False, join_sentences=Fa
|
||||||
if not item.streams():
|
if not item.streams():
|
||||||
logger.error("skip item without media %s: %s", item.public_id)
|
logger.error("skip item without media %s: %s", item.public_id)
|
||||||
return False
|
return False
|
||||||
src = item.streams()[0].media.path
|
|
||||||
|
offset = 0
|
||||||
|
annotations = []
|
||||||
|
for stream in item.streams():
|
||||||
|
src = stream.media.path
|
||||||
response = run_whisper(src, language, translate, gpu, model)
|
response = run_whisper(src, language, translate, gpu, model)
|
||||||
if not response:
|
if not response:
|
||||||
logger.error("extract failed for %s", item.public_id)
|
logger.error("extract failed for %s", item.public_id)
|
||||||
return False
|
return False
|
||||||
annotations = prepare_annotations(response, join_sentences=join_sentences)
|
for annotation in prepare_annotations(response, join_sentences=join_sentences):
|
||||||
|
if offset:
|
||||||
|
annotation['in'] += offset
|
||||||
|
annotation['out'] += offset
|
||||||
|
annotations.append(annotation)
|
||||||
|
offset += stream.duration
|
||||||
if not annotations:
|
if not annotations:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if language and language != "en":
|
if language and language != "en":
|
||||||
for annotation in annotations:
|
for annotation in annotations:
|
||||||
annotation["value"] = '<span lang="%s">%s</span>' % (
|
annotation["value"] = '<span lang="%s">%s</span>' % (
|
||||||
|
|
Loading…
Add table
Reference in a new issue