From f6ced2959676703344154065e64c4857582cd35f Mon Sep 17 00:00:00 2001 From: jakeogh Date: Tue, 14 May 2024 18:55:02 -0700 Subject: [PATCH] use get_first() and remove .get() --- yt_dlp/extractor/youtube.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py index 7f89c1c34..73f7dcaf1 100644 --- a/yt_dlp/extractor/youtube.py +++ b/yt_dlp/extractor/youtube.py @@ -3308,9 +3308,11 @@ def _extract_heatmap(self, data): })) or None def _extract_comment(self, view_model, entities, parent=None): - comment_entity_payload = traverse_obj(entities, (..., 'payload', 'commentEntityPayload', {dict}), get_all=False) - toolbar_entity_payload = traverse_obj(entities, (..., 'payload', 'engagementToolbarStateEntityPayload', {dict}), get_all=False) - comment_id = comment_entity_payload.get('properties').get('commentId') + comment_entity_payload = get_first(entities, ('payload', 'commentEntityPayload', {dict})) + toolbar_entity_payload = get_first(entities, ('payload', 'engagementToolbarStateEntityPayload', {dict})) or {} + comment_id = traverse_obj(comment_entity_payload, ('properties', 'commentId', {str})) + if not comment_id: + return info = { 'id': comment_id,