This commit is contained in:
2026-01-12 12:18:42 -05:00
parent 2a7878ddad
commit 8ea92ea842
8 changed files with 27 additions and 4 deletions
@@ -22,6 +22,11 @@ def translate_via_ollama(source_srt_content, target_language="English", model="l
# Using tqdm for progress bar
for line in tqdm(subs, desc=" Ollama Progress", unit="line"):
text = line.text.strip()
# Skip empty, numeric-only, or extremely short non-word text
if not text or text.isdigit() or len(text) < 2:
continue
if text:
prompt = (
f"Translate this subtitle text to {target_language}. Output ONLY the translation.\n"
@@ -54,6 +59,11 @@ def translate_fallback_mymemory(source_srt_content, target_language="en"):
for line in tqdm(subs, desc=" MyMemory Progress", unit="line"):
text = line.text.strip()
# Skip empty, numeric-only, or extremely short non-word text
if not text or text.isdigit() or len(text) < 2:
continue
if text:
if len(text) > 500: # MyMemory has stricter limits often
continue
@@ -89,6 +99,11 @@ def translate_fallback_free(source_srt_content, target_language="en"):
# Simple line-by-line translation
for line in tqdm(subs, desc=" DeepTranslate Progress", unit="line"):
text = line.text.strip()
# Skip empty, numeric-only, or extremely short non-word text
if not text or text.isdigit() or len(text) < 2:
continue
if text:
# Sanity check: Skip lines that are too long
if len(text) > 4000: