k
This commit is contained in:
33
MPV/lyric.py
33
MPV/lyric.py
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user