OrbiSubs TR: drop cut <think> replies; reset written cues on queue truncation; survive a deleted queue
Revisión externa 1.2, 1.3 y 1.6. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JAUCv2ADyD2NSg4ub9YPr1
This commit is contained in:
+36
-8
@@ -55,12 +55,25 @@ class Traductor:
|
|||||||
return None, time.time() - t
|
return None, time.time() - t
|
||||||
dt = time.time() - t
|
dt = time.time() - t
|
||||||
self.tiempos.append(dt)
|
self.tiempos.append(dt)
|
||||||
if "<think>" in en: # por si el server ignora enable_thinking
|
en = sin_think(en)
|
||||||
en = en.split("</think>")[-1].strip()
|
if not en:
|
||||||
|
return None, time.time() - t
|
||||||
self.prev_es, self.prev_en = es, en
|
self.prev_es, self.prev_en = es, en
|
||||||
return en, dt
|
return en, dt
|
||||||
|
|
||||||
|
|
||||||
|
def sin_think(en):
|
||||||
|
"""Saca el razonamiento si el server ignora enable_thinking. Un <think> sin </think>
|
||||||
|
es una respuesta cortada por max_tokens: es razonamiento, no traducción, y antes salía
|
||||||
|
entero como subtítulo en inglés (revisión externa, 1.3). Se descarta."""
|
||||||
|
if "<think>" not in en:
|
||||||
|
return en
|
||||||
|
if "</think>" not in en:
|
||||||
|
log("translate_cut", chars=len(en))
|
||||||
|
return ""
|
||||||
|
return en.split("</think>")[-1].strip()
|
||||||
|
|
||||||
|
|
||||||
def repartir(t0, t1, en, max_chars=84):
|
def repartir(t0, t1, en, max_chars=84):
|
||||||
"""Corta el inglés en cues y les da tiempo proporcional a su largo."""
|
"""Corta el inglés en cues y les da tiempo proporcional a su largo."""
|
||||||
palabras, trozos, cur = en.split(), [], ""
|
palabras, trozos, cur = en.split(), [], ""
|
||||||
@@ -121,13 +134,28 @@ def main():
|
|||||||
inicial = False # True recién abierta la cola, hasta saltear la historia
|
inicial = False # True recién abierta la cola, hasta saltear la historia
|
||||||
while True:
|
while True:
|
||||||
# Seguir la cola como tail -f; si orbisubs.py reinicia la trunca y se reabre.
|
# 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:
|
# getsize va dentro del try: si se borra la cola (canal borrado o reinstalado) se
|
||||||
try:
|
# espera a que vuelva en vez de caerse; y el archivo viejo se cierra al reabrir
|
||||||
f = open(cola_path)
|
# (revisión externa, 1.6).
|
||||||
except FileNotFoundError:
|
try:
|
||||||
time.sleep(1)
|
reabrir = f is None or os.path.getsize(cola_path) < pos
|
||||||
continue
|
if reabrir:
|
||||||
|
nuevo = open(cola_path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
if f is not None:
|
||||||
|
f.close()
|
||||||
|
f = None
|
||||||
|
time.sleep(1)
|
||||||
|
continue
|
||||||
|
if reabrir:
|
||||||
|
if f is not None:
|
||||||
|
f.close()
|
||||||
|
f = nuevo
|
||||||
pos, segs, pend, en_cues, hecho, hecho_s1 = 0, {}, [], [], -1, None
|
pos, segs, pend, en_cues, hecho, hecho_s1 = 0, {}, [], [], -1, None
|
||||||
|
# Cola truncada = el ASR reinició con PTS nuevos: los inicios de cue ya escritos
|
||||||
|
# son de la línea de tiempo vieja y podían dejar afuera un cue nuevo con el
|
||||||
|
# mismo inicio (revisión externa, 1.2).
|
||||||
|
escritos.clear()
|
||||||
inicial = True
|
inicial = True
|
||||||
f.seek(pos)
|
f.seek(pos)
|
||||||
lineas = f.readlines()
|
lineas = f.readlines()
|
||||||
|
|||||||
Reference in New Issue
Block a user