0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-10-31 23:02:40 +00:00

replace dict access with traverse_obj() and use likeCountA11y

This commit is contained in:
jakeogh 2024-04-24 11:10:13 -07:00
parent 17bb4434c2
commit 3ef651718e

View file

@ -3307,13 +3307,13 @@ def _extract_heatmap(self, data):
})) or None })) or None
def _extract_comment(self, view_model, entity, parent=None): def _extract_comment(self, view_model, entity, parent=None):
entity_payload = entity['payload']['commentEntityPayload'] entity_payload = traverse_obj(entity, ('payload', 'commentEntityPayload', {dict}))
comment_id = entity_payload.get('properties').get('commentId') comment_id = entity_payload.get('properties').get('commentId')
info = { info = {
'id': comment_id, 'id': comment_id,
'text': try_get(entity_payload, lambda x: x['properties']['content']['content'], str), 'text': try_get(entity_payload, lambda x: x['properties']['content']['content'], str),
'like_count': str_to_int(try_get(entity_payload, lambda x: x['toolbar']['likeCountNotliked'], str)) or 0, 'like_count': self._search_regex(r'^([\d]+)', try_get(entity_payload, lambda x: x['toolbar']['likeCountA11y'], str), 'like_count', fatal=False) or 0,
'author_id': traverse_obj(entity_payload, ('author', 'channelId', {self.ucid_or_none})), 'author_id': traverse_obj(entity_payload, ('author', 'channelId', {self.ucid_or_none})),
'author': try_get(entity_payload, lambda x: x['author']['displayName'], str), 'author': try_get(entity_payload, lambda x: x['author']['displayName'], str),
'author_thumbnail': traverse_obj(entity_payload, ('author', 'avatarThumbnailUrl', {url_or_none})), 'author_thumbnail': traverse_obj(entity_payload, ('author', 'avatarThumbnailUrl', {url_or_none})),