From 158dcc3b7fb8d029e291d3a8f973db28b071606f Mon Sep 17 00:00:00 2001 From: sherl Date: Sun, 19 Oct 2025 23:32:12 +0200 Subject: [PATCH] fix: comment reply count extraction suspected a/b test, sorting comments with "top" option returns a new ctoken which will return "Replies" text for comments without replies. to get rid of this behavior it'd be best to create known good ctokens for every request. --- ythdd_extractor.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ythdd_extractor.py b/ythdd_extractor.py index 49abeb8..67fd4fc 100644 --- a/ythdd_extractor.py +++ b/ythdd_extractor.py @@ -518,6 +518,13 @@ def WEBgetVideoComments(ctoken: str) -> tuple: reply_ctoken = safeTraverse(reply_renderer, ["commentThreadRenderer", "replies", "commentRepliesRenderer", "contents", 0, "continuationItemRenderer", "continuationEndpoint", "continuationCommand", "token"], default="") reply_count = safeTraverse(reply_renderer, ["commentThreadRenderer", "replies", "commentRepliesRenderer", "viewReplies", "buttonRenderer", "text", "runs", 0, "text"], default="0 replies").split(" ")[0] + # suspected a/b test. can be worked arount with on-demand ctoken creation. + # workaround for yt not showing replies when sorting for "top" comments + try: + int(reply_count) # can be just "Replies" + except: + reply_count = "0" + for comment in actual_comments: found_key = safeTraverse(comment, ["entityKey"], default="unknown-key") # try to link a relevant ctoken if a comment has response