Created
June 6, 2023 19:44
-
-
Save jabbalaci/574840aad6c1ceee893616eb50b26212 to your computer and use it in GitHub Desktop.
Fetch data of a YouTube video in JSON format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
This code belongs to this video: https://www.youtube.com/watch?v=ldaUV6-hvOQ (in Hungarian)