import json import yt_dlp with yt_dlp.YoutubeDL({ "flat-playlist": True, "extract_flat": "flat-playlist", # 'proxy': 'socks://127.0.0.1:8889', 'nocheckcertificate': True }) as ydl: info = ydl.extract_info("https://www.youtube.com/watch?v=JByDbPn6A1o", download=False) formats = [] for item in info["formats"]: if item.get("resolution") != "audio only" and item.get("url") and item.get("acodec") and item.get( "acodec") != "none" and item.get("vcodec"): formats.append(item) print(json.dumps(formats, ensure_ascii=False))