From a2e2fedc90414fc14ffccabac39aece3c9cebe6d Mon Sep 17 00:00:00 2001 From: sherl Date: Sun, 28 Sep 2025 10:12:23 +0200 Subject: [PATCH] fix: handle empty channel tabs gracefully prevents 500s when a channel tab is empty --- ythdd_inv_tl.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ythdd_inv_tl.py b/ythdd_inv_tl.py index 481b6ba..f6dccbb 100644 --- a/ythdd_inv_tl.py +++ b/ythdd_inv_tl.py @@ -665,9 +665,9 @@ def get_channel_tab(requested_tab, ucid, req, only_json: bool = False): # only the renderers differ - but they are taken care of in ythdd_struct_parser.parseRenderers() if ctoken is None: - inner_contents = safeTraverse(result, ["richGridRenderer", "contents"], default=[[]]) + inner_contents = safeTraverse(result, ["richGridRenderer", "contents"], default=[]) else: - inner_contents = safeTraverse(wdata, ["onResponseReceivedActions", 0, "appendContinuationItemsAction", "continuationItems"], default=[[]]) + inner_contents = safeTraverse(wdata, ["onResponseReceivedActions", 0, "appendContinuationItemsAction", "continuationItems"], default=[]) for entry in inner_contents: # videos from videos tab have no owner info (?) or it's in another place. if it is somewhere, this expression can be made simpler by traversing something else in struct parser. @@ -675,7 +675,7 @@ def get_channel_tab(requested_tab, ucid, req, only_json: bool = False): if item is not None: items.append(ythdd_struct_parser.parseRenderers(item, {"author_name": name, "author_ucid": ucid, "avatar": avatar})) - new_continuation = safeTraverse(inner_contents[-1], ["continuationItemRenderer", "continuationEndpoint", "continuationCommand", "token"], default="") + new_continuation = safeTraverse(inner_contents, [-1, "continuationItemRenderer", "continuationEndpoint", "continuationCommand", "token"], default="") response = { "videos": items @@ -694,16 +694,17 @@ def get_channel_tab(requested_tab, ucid, req, only_json: bool = False): case "playlists": + # todo: replace this with an on-demand generated ctoken? if ctoken is None: - inner_contents = safeTraverse(result, ["sectionListRenderer", "contents", 0, "itemSectionRenderer", "contents", 0, "gridRenderer", "items"], default=[[]]) + inner_contents = safeTraverse(result, ["sectionListRenderer", "contents", 0, "itemSectionRenderer", "contents", 0, "gridRenderer", "items"], default=[]) else: - inner_contents = safeTraverse(wdata, ["onResponseReceivedActions", 0, "appendContinuationItemsAction", "continuationItems"], default=[[]]) + inner_contents = safeTraverse(wdata, ["onResponseReceivedActions", 0, "appendContinuationItemsAction", "continuationItems"], default=[]) for entry in inner_contents: item = ythdd_struct_parser.parseRenderers(entry, {"author_name": name, "author_ucid": ucid, "avatar": avatar}) items.append(item) - new_continuation = safeTraverse(inner_contents[-1], ["continuationItemRenderer", "continuationEndpoint", "continuationCommand", "token"], default="") + new_continuation = safeTraverse(inner_contents, [-1, "continuationItemRenderer", "continuationEndpoint", "continuationCommand", "token"], default="") response = { "playlists": items