This commit is contained in:
2026-03-26 23:00:25 -07:00
parent 562acd809c
commit 37bb4ca685
8 changed files with 368 additions and 123 deletions

View File

@@ -71,6 +71,7 @@ _NOTES_CACHE_VERSION = 1
_DEFAULT_NOTES_CACHE_TTL_S = 900.0
_DEFAULT_NOTES_CACHE_WAIT_S = 1.5
_DEFAULT_NOTES_PENDING_WAIT_S = 12.0
_SUBTITLE_NOTE_ALIASES = ("subtitle", "subtitles", "transcript", "transcription")
def _single_instance_lock_path(ipc_path: str) -> Path:
@@ -794,16 +795,42 @@ def _extract_lrc_from_notes(notes: Dict[str, str]) -> Optional[str]:
return _extract_note_text(notes, "lyric")
def _looks_like_subtitle_text(text: str) -> bool:
t = (text or "").lstrip("\ufeff\r\n").lstrip()
if not t:
return False
upper = t.upper()
if upper.startswith("WEBVTT"):
return True
if upper.startswith("[SCRIPT INFO]"):
return True
if "-->" in t:
return True
if re.search(r"(?m)^Dialogue:\s*", t):
return True
return False
def _extract_sub_from_notes(notes: Dict[str, str]) -> Optional[str]:
"""Return raw subtitle text from the note named 'sub'."""
return _extract_note_text(notes, "sub")
"""Return raw subtitle text from note-backed subtitle/transcript keys."""
primary = _extract_note_text(notes, "sub")
if primary:
return primary
for note_name in _SUBTITLE_NOTE_ALIASES:
candidate = _extract_note_text(notes, note_name)
if candidate and _looks_like_subtitle_text(candidate):
return candidate
return None
def _infer_sub_extension(text: str) -> str:
# Best-effort: mpv generally understands SRT/VTT; choose based on content.
t = (text or "").lstrip("\ufeff\r\n").lstrip()
if t.upper().startswith("WEBVTT"):
upper = t.upper()
if upper.startswith("WEBVTT"):
return ".vtt"
if upper.startswith("[SCRIPT INFO]") or re.search(r"(?m)^Dialogue:\s*", t):
return ".ass"
if "-->" in t:
# SRT typically uses commas for milliseconds, VTT uses dots.
if re.search(r"\d\d:\d\d:\d\d,\d\d\d\s*-->\s*\d\d:\d\d:\d\d,\d\d\d", t):