Last active
May 2, 2021 07:09
-
-
Save krashanoff/85bc51e6ba08312e85d526b367fe824f to your computer and use it in GitHub Desktop.
Simple program to pretty-print a request to YouTube's `get_video_info` endpoint.
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/python3 | |
# Leo Krashanoff | |
# (c) 2021 | |
# Subject to contents of MIT License | |
# | |
# Originally written for maguro: https://github.com/krashanoff/maguro | |
from urllib.parse import parse_qs, unquote | |
from requests import get | |
from argparse import ArgumentParser | |
from json import dumps, loads | |
ENDPOINT = "https://www.youtube.com/get_video_info?video_id=" | |
FIELD_NAME = "player_response=" | |
if __name__ == "__main__": | |
parser = ArgumentParser( | |
"getinfo", | |
description="Write the output of a request to `/get_video_info?video_id=...` to stdout.", | |
) | |
parser.add_argument( | |
"ID", type=str, help="ID of the video to reference." | |
) | |
args = parser.parse_args() | |
res = get(f"{ENDPOINT}{args.ID}") | |
if res.status_code != 200: | |
exit(1) | |
readable = parse_qs(str(res.content, 'utf-8'))["player_response"][0].replace("\"", "\"") | |
print(dumps(loads(readable), indent=2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment