Add subtitle-only download for already-downloaded videos
- download_subs_only(): yt-dlp --skip-download to fetch just .vtt sidecar
- POST /by-yt/{ytId}/download-subs endpoint
- CC chip now visible on downloaded videos; clicking checks YouTube,
shows lang picker with "Add subtitles" button separate from re-download
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -666,6 +666,22 @@ def get_available_subs(
|
||||
return ytdlp.fetch_available_subs(youtube_video_id)
|
||||
|
||||
|
||||
@router.post("/by-yt/{youtube_video_id}/download-subs")
|
||||
def download_subs(
|
||||
youtube_video_id: str,
|
||||
body: dict,
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""Download subtitle file(s) only for an already-downloaded video."""
|
||||
langs = (body.get("subtitle_langs") or "").strip()
|
||||
if not langs:
|
||||
raise HTTPException(status_code=400, detail="subtitle_langs required")
|
||||
ok = ytdlp.download_subs_only(youtube_video_id, langs)
|
||||
if not ok:
|
||||
raise HTTPException(status_code=500, detail="Subtitle download failed")
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@router.get("/by-yt/{youtube_video_id}/subtitle-files")
|
||||
def list_subtitle_files(
|
||||
youtube_video_id: str,
|
||||
|
||||
@@ -384,6 +384,22 @@ def fetch_channel_links(channel_id: str) -> list[str]:
|
||||
return list(channel_ids)
|
||||
|
||||
|
||||
def download_subs_only(video_id: str, subtitle_langs: str) -> bool:
|
||||
"""Download subtitle files only (no video) for an already-downloaded video."""
|
||||
url = f"https://www.youtube.com/watch?v={video_id}"
|
||||
output_template = str(Path(settings.download_path) / f"{video_id}.%(ext)s")
|
||||
_, _, code = _run([
|
||||
"yt-dlp", url,
|
||||
"--skip-download", "--no-playlist",
|
||||
"--write-subs", "--write-auto-subs",
|
||||
"--sub-langs", subtitle_langs,
|
||||
"--convert-subs", "vtt",
|
||||
"-o", output_template,
|
||||
*_cookie_args(),
|
||||
], timeout=60)
|
||||
return code == 0
|
||||
|
||||
|
||||
def fetch_available_subs(video_id: str) -> dict:
|
||||
"""Return subtitle languages available on YouTube for a video.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user