mirror of
https://git.sr.ht/~cadence/NewLeaf
synced 2024-12-21 12:46:58 +00:00
Channel path fixes I'm pretty sure I already did?
- use "channels" as default path, not "user" - cache based on the combination of the path and the id - fix channel latest
This commit is contained in:
parent
ac1aa07108
commit
714f1030fb
@ -13,9 +13,11 @@ channel_latest_cache = TTLCache(maxsize=500, ttl=300)
|
||||
channel_latest_cache_lock = Lock()
|
||||
|
||||
def extract_channel(ucid, second__path="user"):
|
||||
cache_key = (ucid, second__path)
|
||||
|
||||
with channel_cache_lock:
|
||||
if ucid in channel_cache:
|
||||
return channel_cache[ucid]
|
||||
if cache_key in channel_cache:
|
||||
return channel_cache[cache_key]
|
||||
|
||||
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())
|
||||
@ -154,12 +156,12 @@ def extract_channel(ucid, second__path="user"):
|
||||
}
|
||||
|
||||
with channel_cache_lock:
|
||||
channel_cache[ucid] = channel
|
||||
channel_cache[cache_key] = channel
|
||||
|
||||
return channel
|
||||
|
||||
def extract_channel_videos(ucid):
|
||||
channel = extract_channel(ucid)
|
||||
def extract_channel_videos(ucid, second__path="channel"):
|
||||
channel = extract_channel(ucid, second__path)
|
||||
if "error" in channel:
|
||||
return channel
|
||||
else:
|
||||
|
6
index.py
6
index.py
@ -58,7 +58,7 @@ class NewLeaf(object):
|
||||
|
||||
@cherrypy.expose
|
||||
@cherrypy.tools.json_out()
|
||||
def channels(self, *suffix, second__path="user", **kwargs):
|
||||
def channels(self, *suffix, second__path="channel", **kwargs):
|
||||
ucid = ""
|
||||
part = ""
|
||||
possible_parts = ("videos", "latest", "playlists")
|
||||
@ -74,7 +74,7 @@ class NewLeaf(object):
|
||||
"error": "Two components specified in URL, but neither component was recognised as a part keyword.",
|
||||
"identifier": "PART_KEYWORD_NOT_RECOGNISED"
|
||||
}
|
||||
possible_paths = ("channel", "c", "user")
|
||||
possible_paths = ("channel",) if part == "latest" else ("channel", "c", "user")
|
||||
if second__path not in possible_paths:
|
||||
return {
|
||||
"error": "second__path parameter must be one of: " + str(possible_paths),
|
||||
@ -84,7 +84,7 @@ class NewLeaf(object):
|
||||
if part == "playlists":
|
||||
return []
|
||||
elif part == "latest":
|
||||
return extract_channel_latest(ucid, second__path)
|
||||
return extract_channel_latest(ucid)
|
||||
elif part == "videos":
|
||||
return extract_channel_videos(ucid, second__path)
|
||||
else: # part == "", so extract whole channel
|
||||
|
Loading…
Reference in New Issue
Block a user