From 8d428b42c054a1418c9753148d609be7d4dab43e Mon Sep 17 00:00:00 2001 From: jakeogh Date: Tue, 14 May 2024 19:01:41 -0700 Subject: [PATCH] use single traversal --- yt_dlp/extractor/youtube.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py index 73f7dcaf1..e92907f42 100644 --- a/yt_dlp/extractor/youtube.py +++ b/yt_dlp/extractor/youtube.py @@ -3316,12 +3316,14 @@ def _extract_comment(self, view_model, entities, parent=None): info = { 'id': comment_id, - 'text': try_get(comment_entity_payload, lambda x: x['properties']['content']['content'], str), - 'like_count': parse_count(try_get(comment_entity_payload, lambda x: x['toolbar']['likeCountA11y'], str)) or 0, - 'author_id': traverse_obj(comment_entity_payload, ('author', 'channelId', {self.ucid_or_none})), - 'author': try_get(comment_entity_payload, lambda x: x['author']['displayName'], str), - 'author_thumbnail': traverse_obj(comment_entity_payload, ('author', 'avatarThumbnailUrl', {url_or_none})), 'parent': parent or 'root', + **traverse_obj(comment_entity_payload, { + 'text': ('properties', 'content', 'content', {str}), + 'like_count': ('toolbar', 'likeCountA11y', {parse_count}), + 'author_id': ('author', 'channelId', {self.ucid_or_none}), + 'author': ('author', 'displayName', {str}), + 'author_thumbnail': ('author', 'avatarThumbnailUrl', {url_or_none}), + }), } # Timestamp is an estimate calculated from the current time and time_text