if no language is set, try without

This commit is contained in:
j 2024-07-08 15:33:03 +01:00
parent a4a60537f1
commit 1788f4bac6

View file

@ -23,11 +23,9 @@ logger = logging.getLogger(__name__)
def extract_subtitles(item, user, layer, translate, gpu=False): def extract_subtitles(item, user, layer, translate, gpu=False):
if "language" not in item.data: if "language" not in item.data:
logger.error("skip item without language %s", item.public_id) logger.error("skip item without language %s", item.public_id)
return False language = None
language = ox.iso.langTo2Code(item.data["language"][0]) else:
if not language: language = ox.iso.langTo2Code(item.data["language"][0])
logger.error("skip item with unknown language %s: %s", item.public_id, item.data["language"])
return False
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
@ -36,13 +34,16 @@ def extract_subtitles(item, user, layer, translate, gpu=False):
tmp = tempfile.mkdtemp() tmp = tempfile.mkdtemp()
cmd = [ cmd = [
"/opt/whisper-timestamped/bin/whisper_timestamped", "/opt/whisper-timestamped/bin/whisper_timestamped",
"--language", language,
] ]
if translate and language in translate: if language:
cmd += [ cmd += [
'--task', 'translate' "--language", language
] ]
language = 'en' if translate and language in translate:
cmd += [
'--task', 'translate'
]
language = 'en'
if not gpu: if not gpu:
cmd += [ cmd += [
"--fp16", "False", "--fp16", "False",