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.
This commit is contained in:
@@ -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_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]
|
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:
|
for comment in actual_comments:
|
||||||
found_key = safeTraverse(comment, ["entityKey"], default="unknown-key")
|
found_key = safeTraverse(comment, ["entityKey"], default="unknown-key")
|
||||||
# try to link a relevant ctoken if a comment has response
|
# try to link a relevant ctoken if a comment has response
|
||||||
|
|||||||
Reference in New Issue
Block a user