-
-
Save tech234a/7ec4c215291a4625c3bb83b75f9eeca8 to your computer and use it in GitHub Desktop.
YouTube URL to UCID Resolver
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
from requests import session | |
from sys import argv | |
mys = session() | |
def resolve_url(url: str, iter=False): | |
result = mys.post("https://www.youtube.com/youtubei/v1/navigation/resolve_url?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8", json={"context": {"client": {"clientName": "WEB", "clientVersion": "2.20211012.01.00"}}, "url": url}).json() | |
if "endpoint" in result.keys(): | |
rend = result["endpoint"] | |
rkey = rend.keys() | |
if "browseEndpoint" in rkey: | |
ri = rend["browseEndpoint"]["browseId"] | |
if len(ri) == 24 and ri.startswith("UC"): | |
return ri | |
elif "urlEndpoint" in rkey and not iter: | |
return resolve_url(rend["urlEndpoint"]["url"], True) | |
return None | |
if len(argv) == 2: | |
print(resolve_url(argv[1])) | |
else: | |
print("""YouTube URL to UCID Resolver by tech234a | |
USAGE: python3 resolve.py [Channel URL] | |
Or use as a Python module by importing this file | |
and using the resolve_url function. | |
REQUIREMENTS: requests (pip install requests) | |
NOTES: Only provide 1 channel URL at a time.""") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment