{"library":"yt-dlp","code":"import yt_dlp\n\ndef download_video(url):\n    ydl_opts = {\n        'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best',\n        'outtmpl': '%(title)s.%(ext)s',\n        'merge_output_format': 'mp4'\n    }\n    with yt_dlp.YoutubeDL(ydl_opts) as ydl:\n        info_dict = ydl.extract_info(url, download=False)\n        video_title = info_dict.get('title', 'Unknown Title')\n        print(f\"Downloading: {video_title}\")\n        ydl.download([url])\n    print(\"Download complete!\")\n\nif __name__ == '__main__':\n    # Replace with a real video URL for testing. Use an anonymous public video.\n    # For authenticated downloads, configure 'cookiefile' in ydl_opts.\n    video_url = \"https://www.youtube.com/watch?v=dQw4w9WgXcQ\" # Example URL\n    download_video(video_url)\n","lang":"python","description":"This quickstart demonstrates how to use `yt-dlp` as a Python library to download a video. It configures options to download the best quality MP4 video and audio, then merges them, saving the file with the video's title. For more advanced options like specifying output directories, proxies, or authentication, the `ydl_opts` dictionary should be extended.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}