Skip to content

Instantly share code, notes, and snippets.

@kainabel
Forked from jabbalaci/data-of-one-video.py
Created November 20, 2023 15:56
Show Gist options
  • Save kainabel/4d5f4adc38912912bbe6fabb5097a2e8 to your computer and use it in GitHub Desktop.
Save kainabel/4d5f4adc38912912bbe6fabb5097a2e8 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment