1
0
Fork 0
mirror of https://git.sr.ht/~cadence/NewLeaf synced 2026-03-07 13:01:37 +00:00

#29 Extract named channels using dynamic endpoint with second__path param instead of /user/

This commit is contained in:
Lomanic 2021-11-13 20:15:16 +01:00 committed by Cadence Ember
parent 29a3894337
commit ac1aa07108
2 changed files with 12 additions and 6 deletions

View file

@ -12,12 +12,12 @@ channel_cache_lock = Lock()
channel_latest_cache = TTLCache(maxsize=500, ttl=300)
channel_latest_cache_lock = Lock()
def extract_channel(ucid):
def extract_channel(ucid, second__path="user"):
with channel_cache_lock:
if ucid in channel_cache:
return channel_cache[ucid]
channel_type = "channel" if len(ucid) == 24 and ucid[:2] == "UC" else "user"
channel_type = "channel" if len(ucid) == 24 and ucid[:2] == "UC" else second__path
r = requests.get("https://www.youtube.com/{}/{}/videos?hl=en".format(channel_type, ucid), cookies=eu_consent_cookie())
r.raise_for_status()
yt_initial_data = extract_yt_initial_data(r.content.decode("utf8"))