Fix subtitle playback: vtt format, track elements, fast disk scan

- Convert subs to .vtt (was .srt which browsers don't support in <track>)
- Add GET /subtitle-files endpoint: instant disk scan for .vtt sidecar files,
  no yt-dlp call needed
- Inject <track> elements into the video player for each .vtt on disk;
  browser CC button appears automatically
- Before download: CC chip triggers YouTube availability check (slow, on demand)
- After download with subs: shows "CC ✓" — subtitles live in the player controls

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-26 21:11:58 +02:00
parent 97ebcd6c1d
commit 27f17c16ef
4 changed files with 54 additions and 7 deletions

View File

@@ -662,10 +662,31 @@ def get_available_subs(
youtube_video_id: str,
current_user: User = Depends(get_current_user),
):
"""Return subtitle languages available on YouTube for a video."""
"""Return subtitle languages available on YouTube for a video (yt-dlp call, slow)."""
return ytdlp.fetch_available_subs(youtube_video_id)
@router.get("/by-yt/{youtube_video_id}/subtitle-files")
def list_subtitle_files(
youtube_video_id: str,
current_user: User = Depends(get_current_user),
):
"""List .vtt subtitle files already on disk for a downloaded video (instant)."""
import re as _re
from pathlib import Path
from ..config import settings as _cfg
pat = _re.compile(rf'^{_re.escape(youtube_video_id)}\.(.+)\.vtt$')
subs = []
try:
for f in Path(_cfg.download_path).iterdir():
m = pat.match(f.name)
if m:
subs.append({"lang": m.group(1), "url": f"/files/{f.name}"})
except Exception:
pass
return sorted(subs, key=lambda s: s["lang"])
@router.get("/by-yt/{youtube_video_id}/comments")
def get_comments(
youtube_video_id: str,

View File

@@ -662,7 +662,7 @@ def start_download(
fmt = QUALITY_FORMATS.get(quality, QUALITY_FORMATS["best"])
subtitle_args = (
["--write-subs", "--write-auto-subs", "--sub-langs", subtitle_langs, "--convert-subs", "srt"]
["--write-subs", "--write-auto-subs", "--sub-langs", subtitle_langs, "--convert-subs", "vtt"]
if subtitle_langs else []
)