From d308f6c36ea0140c35a05250595ba8cde2032ee3 Mon Sep 17 00:00:00 2001 From: bashonly Date: Sun, 17 Nov 2024 11:00:01 -0600 Subject: [PATCH] [ie/pialive] fix comment extraction Authored by: bashonly --- yt_dlp/extractor/pialive.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/yt_dlp/extractor/pialive.py b/yt_dlp/extractor/pialive.py index 7323de43f1..9b6b223ad4 100644 --- a/yt_dlp/extractor/pialive.py +++ b/yt_dlp/extractor/pialive.py @@ -6,6 +6,7 @@ from ..utils import ( get_element_by_class, get_element_html_by_class, multipart_encode, + str_or_none, unified_timestamp, url_or_none, ) @@ -112,15 +113,17 @@ class PiaLiveIE(InfoExtractor): def _get_comments(self, video_id, chat_room_url): if not chat_room_url: return - if comment_page := self._download_webpage( - chat_room_url, video_id, headers={'Referer': self._PLAYER_ROOT_URL}, - note='Fetching comment page', errnote='Unable to fetch comment page', fatal=False): - yield from traverse_obj(self._search_json( - r'var\s+_history\s*=', comment_page, 'comment list', - video_id, contains_pattern=r'\[(?s:.+)\]', fatal=False), (..., { - 'timestamp': 0, - 'author_is_uploader': (1, {lambda x: x == 2}), - 'author': 2, - 'text': 3, - 'id': 4, - })) + comment_page = self._download_webpage( + chat_room_url, video_id, headers={'Referer': self._PLAYER_ROOT_URL}, + note='Fetching comment page', errnote='Unable to fetch comment page', fatal=False) + if not comment_page: + return + yield from traverse_obj(self._search_json( + r'var\s+_history\s*=', comment_page, 'comment list', + video_id, contains_pattern=r'\[(?s:.+)\]', fatal=False), (..., { + 'timestamp': (0, {int}), + 'author_is_uploader': (1, {lambda x: x == 2}), + 'author': (2, {str}), + 'text': (3, {str}), + 'id': (4, {str_or_none}), + }))