feat: video comments endpoint
This commit is contained in:
@@ -304,6 +304,46 @@ def parseRenderers(entry: dict, context: dict = {}) -> dict:
|
||||
# breakpoint()
|
||||
return
|
||||
|
||||
def customCommentRendererParser(comment: dict, context: dict = {}) -> dict:
|
||||
|
||||
cep = safeTraverse(comment, ["payload", "commentEntityPayload"], default={})
|
||||
content = safeTraverse(cep, ["properties", "content", "content"], default="")
|
||||
content_html = escape(content).replace("\r\n", "<br>").replace("\n", "<br>")
|
||||
author = safeTraverse(cep, ["author"], default={})
|
||||
verified = safeTraverse(author, ["isVerified"], default=False) or safeTraverse(author, ["isArtist"], default=False)
|
||||
ucid = safeTraverse(author, ["channelId"], default="UNKNOWNCHANNELID")
|
||||
published_date = safeTraverse(cep, ["properties", "publishedTime"], default="now")
|
||||
edited = False
|
||||
|
||||
if published_date.endswith(" (edited)"):
|
||||
edited = True
|
||||
published_date_unix = int(dateparser.parse(published_date.removesuffix(" (edited)")).timestamp())
|
||||
else:
|
||||
published_date_unix = int(dateparser.parse(published_date).timestamp())
|
||||
|
||||
inv_comment = {
|
||||
"authorId": ucid,
|
||||
"authorUrl": "/channel/" + ucid,
|
||||
"author": safeTraverse(author, ["displayName"], default="@ythdd-unknown-user"),
|
||||
"verified": verified,
|
||||
"authorThumbnails": ythdd_extractor.generateChannelAvatarsFromUrl(safeTraverse(author, ["avatarThumbnailUrl"], default=DEFAULT_AVATAR)), # proxy them!
|
||||
"authorIsChannelOwner": safeTraverse(author, ["isCreator"], default=False), # ???
|
||||
"isSponsor": False, # not sure how to retrieve this
|
||||
"likeCount": parseViewsFromViewText("0" + safeTraverse(cep, ["toolbar", "likeCountNotliked"], default="0") + " likes"),
|
||||
"isPinned": False,
|
||||
"commentId": safeTraverse(cep, ["properties", "commentId"], default="UNKNOWNCOMMENTID"),
|
||||
"content": content,
|
||||
"contentHtml": content_html,
|
||||
"isEdited": edited,
|
||||
"published": published_date_unix,
|
||||
"publishedText": published_date if published_date != "now" else "unknown amount of time ago"
|
||||
}
|
||||
|
||||
if "replies" in comment:
|
||||
inv_comment["replies"] = comment["replies"]
|
||||
|
||||
return inv_comment
|
||||
|
||||
def parseDescriptionSnippet(snippet: list):
|
||||
|
||||
text = ""
|
||||
|
||||
Reference in New Issue
Block a user