test.py 591 B

1234567891011121314151617
  1. import json
  2. import yt_dlp
  3. with yt_dlp.YoutubeDL({
  4. "flat-playlist": True,
  5. "extract_flat": "flat-playlist",
  6. # 'proxy': 'socks://127.0.0.1:8889',
  7. 'nocheckcertificate': True
  8. }) as ydl:
  9. info = ydl.extract_info("https://www.youtube.com/watch?v=JByDbPn6A1o", download=False)
  10. formats = []
  11. for item in info["formats"]:
  12. if item.get("resolution") != "audio only" and item.get("url") and item.get("acodec") and item.get(
  13. "acodec") != "none" and item.get("vcodec"):
  14. formats.append(item)
  15. print(json.dumps(formats, ensure_ascii=False))