feat: Hinweis, wenn ein Zeitbereich über das Ende der Untertitel reicht

„-z 0-05:00“ bedeutet fünf Stunden und bearbeitete bisher stillschweigend
das ganze Video. vtt2txt.py (und damit extract_text.py und
abschrift_korrigieren.py) nennt jetzt das Ende der Untertitel, bei
Bereichen ab einer Stunde mit dem Tipp „Minute 5 ist 00:05“.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dieter Schlüter 2026-10-11 21:58:12 +02:00
commit d9512bcedc

View file

@ -307,18 +307,42 @@ def range_label(start, end):
return f"{left} – {right}"
def end_hint(start, end, captions_end):
"""Note for a range reaching past the last caption, else ""; two numbers
are hours:minutes, so "05:00" for minute 5 is a likely slip."""
if captions_end is None:
return ""
past_end = (end is not None and end > captions_end) or (
start is not None and start >= captions_end
)
if not past_end:
return ""
hint = f" (die Untertitel enden bei {format_time(captions_end)}"
if max(start or 0, end or 0) >= 3600 > captions_end:
hint += "; zwei Zahlen wie 05:00 sind Stunden:Minuten, Minute 5 ist 00:05"
return hint + ")"
def excerpts(timed, ranges, exact=False):
"""Return (start, end in seconds, lines) of the text block of each time range.
Blocks that overlap after growing to whole sentences are merged; ranges
without captions are skipped with a note.
without captions are skipped with a note, ranges reaching past the last
caption get one.
"""
captions_end = max((end for _, end, _ in timed if end is not None), default=None)
bounds = []
for start, end in ranges:
found = excerpt_bounds(timed, start, end, exact)
hint = end_hint(start, end, captions_end)
if found is None:
print(f"Hinweis: keine Untertitel im Bereich {range_label(start, end)}")
print(f"Hinweis: keine Untertitel im Bereich {range_label(start, end)}{hint}")
continue
if hint:
print(
f"Hinweis: Bereich {range_label(start, end)} reicht über das Ende "
f"der Untertitel hinaus{hint}"
)
if bounds and found[0] < bounds[-1][1]:
bounds[-1] = (bounds[-1][0], max(bounds[-1][1], found[1]))
else: