"""Download captions with yt-dlp, optionally with cookies. pip install yt-dlp""" import sys import yt_dlp def download_subs(url, cookiefile=None, langs=("en",)): opts = { "skip_download": True, "writesubtitles": True, "writeautomaticsub": True, "subtitleslangs": list(langs), "subtitlesformat": "vtt", "outtmpl": "%(id)s.%(ext)s", "quiet": True, } if cookiefile: opts["cookiefile"] = cookiefile with yt_dlp.YoutubeDL(opts) as ydl: return ydl.extract_info(url, download=True) if __name__ == "__main__": try: info = download_subs(sys.argv[1], cookiefile=(sys.argv[2] if len(sys.argv) > 2 else None)) print("saved:", list((info.get("requested_subtitles") or {}).keys())) except yt_dlp.utils.DownloadError as e: if "not a bot" in str(e): print("BLOCKED: YouTube wants sign-in from this IP (bot check)") else: raise