diff --git a/extractors/channel.py b/extractors/channel.py index fad39b3..8c610d8 100644 --- a/extractors/channel.py +++ b/extractors/channel.py @@ -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: diff --git a/index.py b/index.py index 482c6d5..e88e343 100644 --- a/index.py +++ b/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