OrbiSubs translator: skip queue history on start, keep existing English VTTs

On (re)open the translator read cues.jsonl from the start and sent the whole
channel history to the shared gpu02 LLM (~250 requests at once on T13,
2026-11-17), and rewrote already translated en/*.vtt with empty cues. Now it
only translates the last --historia seconds (15 by default) and leaves older
English VTTs as they are. Tested against a fake LLM: 53 -> 3 requests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
guy
2026-11-16 23:44:12 -05:00
parent 2e28f7a695
commit d1ee89cef5
+25
View File
@@ -90,6 +90,8 @@ def main():
ap.add_argument("--max-frase", type=float, default=6.0)
ap.add_argument("--pausa", type=float, default=0.8)
ap.add_argument("--metrics", default=None)
# Al abrir la cola, solo se traduce lo último: ver "historia" en el bucle.
ap.add_argument("--historia", type=float, default=15.0)
a = ap.parse_args()
cola_path = os.path.join(a.dir, "cues.jsonl")
@@ -104,6 +106,7 @@ def main():
listo_es = None # PTS hasta donde el español está confirmado
hecho = -1 # último seq con en/<seq>.vtt
f, pos = None, 0
inicial = False # True recién abierta la cola, hasta saltear la historia
while True:
# Seguir la cola como tail -f; si orbisubs.py reinicia la trunca y se reabre.
if f is None or os.path.getsize(cola_path) < pos:
@@ -113,6 +116,7 @@ def main():
time.sleep(1)
continue
pos, segs, pend, en_cues, hecho = 0, {}, [], [], -1
inicial = True
f.seek(pos)
lineas = f.readlines()
pos = f.tell()
@@ -128,6 +132,27 @@ def main():
pend += d["cues"]
listo_es = d["listo"]
if inicial and segs:
inicial = False
# Caso real (T13, 2026-11-17 04:39 UTC): al reiniciar el traductor se leía la
# cola entera y se mandaba a traducir TODA la historia del canal (~250 frases de
# golpe) al Qwen compartido de gpu02, que también usa batman. Ahora la historia
# solo sirve para ubicarse: se traducen los últimos --historia segundos.
corte = listo_es - a.historia
antes = len(pend)
pend = [c for c in pend if c[1] > corte]
viejos = [k for k, (s0, s1, _) in segs.items() if s1 <= corte]
if viejos:
# Los .vtt en inglés de esos segmentos se dejan como están: reescribirlos
# con en_cues vacío borraría lo ya traducido. Si falta alguno (en.m3u8 lo
# va a nombrar), se escribe vacío para que el player no reciba un 404.
hecho = max(viejos)
for k in viejos:
p = os.path.join(en_dir, f"{k}.vtt")
if not os.path.exists(p):
escribir_atomico(p, "WEBVTT\nX-TIMESTAMP-MAP=MPEGTS:0,LOCAL:00:00:00.000\n\n")
log("history_skipped", cues_skipped=antes - len(pend), segs_kept=len(viejos), from_seg=hecho)
# Frases cerradas: termina en . ? !, o viene una pausa, o pasó el máximo.
while pend:
fin = None