Skip to content

Instantly share code, notes, and snippets.

@jabbalaci
Created June 6, 2023 19:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jabbalaci/574840aad6c1ceee893616eb50b26212 to your computer and use it in GitHub Desktop.
Save jabbalaci/574840aad6c1ceee893616eb50b26212 to your computer and use it in GitHub Desktop.
Fetch data of a YouTube video in JSON format
#!/usr/bin/env python3
"""
using the yt-dlp package
"""
import json
from pprint import pprint
import yt_dlp
def get_detailed_info(video_url: str) -> dict:
ydl = yt_dlp.YoutubeDL()
info: dict = ydl.extract_info(video_url, download=False) # type: ignore
return info
def save_to_file(info: dict) -> None:
with open("info.json", "w") as f:
json.dump(info, f, indent=4)
def main():
url = "https://www.youtube.com/watch?v=YbZZ9X-jFog"
info = get_detailed_info(url)
save_to_file(info)
# pprint(info)
# print(type(info))
print("done")
##############################################################################
if __name__ == "__main__":
main()
@jabbalaci
Copy link
Author

This code belongs to this video: https://www.youtube.com/watch?v=ldaUV6-hvOQ (in Hungarian)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment