mirror of https://git.sr.ht/~cadence/NewLeaf
Compare commits
2 Commits
c9b16d3efd
...
ac1aa07108
Author | SHA1 | Date |
---|---|---|
Lomanic | ac1aa07108 | |
Lomanic | 29a3894337 |
|
@ -12,12 +12,12 @@ channel_cache_lock = Lock()
|
||||||
channel_latest_cache = TTLCache(maxsize=500, ttl=300)
|
channel_latest_cache = TTLCache(maxsize=500, ttl=300)
|
||||||
channel_latest_cache_lock = Lock()
|
channel_latest_cache_lock = Lock()
|
||||||
|
|
||||||
def extract_channel(ucid):
|
def extract_channel(ucid, second__path="user"):
|
||||||
with channel_cache_lock:
|
with channel_cache_lock:
|
||||||
if ucid in channel_cache:
|
if ucid in channel_cache:
|
||||||
return channel_cache[ucid]
|
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 = requests.get("https://www.youtube.com/{}/{}/videos?hl=en".format(channel_type, ucid), cookies=eu_consent_cookie())
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
yt_initial_data = extract_yt_initial_data(r.content.decode("utf8"))
|
yt_initial_data = extract_yt_initial_data(r.content.decode("utf8"))
|
||||||
|
@ -35,7 +35,10 @@ def extract_channel(ucid):
|
||||||
"identifier": "ACCOUNT_TERMINATED"
|
"identifier": "ACCOUNT_TERMINATED"
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
print("Seen alert text '{}'".format(alert_text))
|
return {
|
||||||
|
"error": alert_text,
|
||||||
|
"identifier": "UNKNOWN"
|
||||||
|
}
|
||||||
|
|
||||||
header = yt_initial_data["header"]["c4TabbedHeaderRenderer"] if "c4TabbedHeaderRenderer" in yt_initial_data["header"] else {}
|
header = yt_initial_data["header"]["c4TabbedHeaderRenderer"] if "c4TabbedHeaderRenderer" in yt_initial_data["header"] else {}
|
||||||
channel_metadata = yt_initial_data["metadata"]["channelMetadataRenderer"]
|
channel_metadata = yt_initial_data["metadata"]["channelMetadataRenderer"]
|
||||||
|
|
14
index.py
14
index.py
|
@ -58,7 +58,7 @@ class NewLeaf(object):
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@cherrypy.tools.json_out()
|
@cherrypy.tools.json_out()
|
||||||
def channels(self, *suffix, **kwargs):
|
def channels(self, *suffix, second__path="user", **kwargs):
|
||||||
ucid = ""
|
ucid = ""
|
||||||
part = ""
|
part = ""
|
||||||
possible_parts = ("videos", "latest", "playlists")
|
possible_parts = ("videos", "latest", "playlists")
|
||||||
|
@ -74,15 +74,21 @@ class NewLeaf(object):
|
||||||
"error": "Two components specified in URL, but neither component was recognised as a part keyword.",
|
"error": "Two components specified in URL, but neither component was recognised as a part keyword.",
|
||||||
"identifier": "PART_KEYWORD_NOT_RECOGNISED"
|
"identifier": "PART_KEYWORD_NOT_RECOGNISED"
|
||||||
}
|
}
|
||||||
|
possible_paths = ("channel", "c", "user")
|
||||||
|
if second__path not in possible_paths:
|
||||||
|
return {
|
||||||
|
"error": "second__path parameter must be one of: " + str(possible_paths),
|
||||||
|
"identifier": "PATH_PARAMETER_NOT_RECOGNISED"
|
||||||
|
}
|
||||||
|
|
||||||
if part == "playlists":
|
if part == "playlists":
|
||||||
return []
|
return []
|
||||||
elif part == "latest":
|
elif part == "latest":
|
||||||
return extract_channel_latest(ucid)
|
return extract_channel_latest(ucid, second__path)
|
||||||
elif part == "videos":
|
elif part == "videos":
|
||||||
return extract_channel_videos(ucid)
|
return extract_channel_videos(ucid, second__path)
|
||||||
else: # part == "", so extract whole channel
|
else: # part == "", so extract whole channel
|
||||||
return extract_channel(ucid)
|
return extract_channel(ucid, second__path)
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@cherrypy.tools.json_out()
|
@cherrypy.tools.json_out()
|
||||||
|
|
Loading…
Reference in New Issue