[ie/pialive] fix comment extraction

Authored by: bashonly
This commit is contained in:
bashonly 2024-11-17 11:00:01 -06:00
parent 67a7194547
commit d308f6c36e
No known key found for this signature in database
GPG Key ID: 783F096F253D15B0

View File

@ -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}),
}))