From 3ef651718e3050252b5f9eb9f46906ef01b8e924 Mon Sep 17 00:00:00 2001 From: jakeogh Date: Wed, 24 Apr 2024 11:10:13 -0700 Subject: [PATCH] replace dict access with traverse_obj() and use likeCountA11y --- yt_dlp/extractor/youtube.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py index 1c12c2320..b4f33e7f7 100644 --- a/yt_dlp/extractor/youtube.py +++ b/yt_dlp/extractor/youtube.py @@ -3307,13 +3307,13 @@ def _extract_heatmap(self, data): })) or 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') info = { 'id': comment_id, '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': try_get(entity_payload, lambda x: x['author']['displayName'], str), 'author_thumbnail': traverse_obj(entity_payload, ('author', 'avatarThumbnailUrl', {url_or_none})),