From 367a4667e3fd40219f9fb2f3ece06433505558e8 Mon Sep 17 00:00:00 2001 From: Jackson Humphrey Date: Wed, 13 Nov 2024 11:58:08 -0600 Subject: [PATCH] Moved comment.get into a try_call and moved the check for an invalid comment ID to the beginning so that we bail out immediately if the thing we're parsing isn't actually a comment. --- yt_dlp/extractor/patreon.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yt_dlp/extractor/patreon.py b/yt_dlp/extractor/patreon.py index 4d668cd37d..10d7f76c23 100644 --- a/yt_dlp/extractor/patreon.py +++ b/yt_dlp/extractor/patreon.py @@ -17,6 +17,7 @@ from ..utils import ( smuggle_url, str_or_none, traverse_obj, + try_call, url_or_none, urljoin, ) @@ -406,10 +407,9 @@ class PatreonIE(PatreonBaseIE): cursor = None for comment in traverse_obj(response, (('data', ('included', lambda _, v: v['type'] == 'comment')), ...)): count += 1 - comment_id = comment.get('id') - attributes = comment.get('attributes') or {} - if comment_id is None: + if (comment_id := try_call(lambda: comment.get('id'))) is None: continue + attributes = comment.get('attributes') or {} author_id = traverse_obj(comment, ('relationships', 'commenter', 'data', 'id')) author_info = traverse_obj( response, ('included', lambda _, v: v['id'] == author_id and v['type'] == 'user', 'attributes'),