[PATCH NewLeaf 1/1] #29 Extract named channels using dynamic endpoint with second__path param instead of /user/
Export this patch
From: Lomanic <lomanic@hotmail.fr>
---
extractors/channel.py | 4 ++--
index.py | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/extractors/channel.py b/extractors/channel.py
index 454a4e5..30e2b7b 100644
--- a/extractors/channel.py
@@ -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
with requests.get("https://www.youtube.com/{}/{}/videos?hl=en".format(channel_type, ucid), cookies=eu_consent_cookie()) as r:
r.raise_for_status()
yt_initial_data = extract_yt_initial_data(r.content.decode("utf8"))
diff --git a/index.py b/index.py
index ffc35c7..875b89a 100644
--- a/index.py
+++ b/index.py
@@ -58,7 +58,7 @@ class NewLeaf(object):
@cherrypy.expose
@cherrypy.tools.json_out()
- def channels(self, *suffix, **kwargs):
+ def channels(self, *suffix, second__path="user", **kwargs):
ucid = ""
part = ""
possible_parts = ("videos", "latest", "playlists")
@@ -78,11 +78,11 @@ class NewLeaf(object):
if part == "playlists":
return []
elif part == "latest":
- return extract_channel_latest(ucid)
+ return extract_channel_latest(ucid, second__path)
elif part == "videos":
- return extract_channel_videos(ucid)
+ return extract_channel_videos(ucid, second__path)
else: # part == "", so extract whole channel
- return extract_channel(ucid)
+ return extract_channel(ucid, second__path)
@cherrypy.expose
@cherrypy.tools.json_out()
--
2.32.0