mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-06-28 09:28:33 +00:00
twitch chat: review changes part 2
This commit is contained in:
parent
206ca4092b
commit
0aa41b8e84
@ -21,7 +21,6 @@
|
||||
parse_iso8601,
|
||||
parse_qs,
|
||||
qualities,
|
||||
RetryManager,
|
||||
str_or_none,
|
||||
try_get,
|
||||
unified_timestamp,
|
||||
@ -552,7 +551,7 @@ def _get_subtitles(self, vod_id):
|
||||
pagenum = 1
|
||||
gql_ops = [{
|
||||
'operationName': 'VideoCommentsByOffsetOrCursor',
|
||||
'variables': { 'videoID': vod_id }
|
||||
'variables': {'videoID': vod_id}
|
||||
# 'variables.cursor': <filled in in subsequent requests>
|
||||
}]
|
||||
|
||||
@ -561,8 +560,6 @@ def _get_subtitles(self, vod_id):
|
||||
|
||||
for retry in self.RetryManager():
|
||||
response = self._download_gql(vod_id, gql_ops, 'Downloading chat fragment page %d' % pagenum, fatal=False)
|
||||
# response = False
|
||||
# TODO: delete the direct False, uncomment _download_gql
|
||||
|
||||
if response is False:
|
||||
retry.error = ExtractorError("f'Unable to fetch next chat history fragment.'", video_id=vod_id, ie=self)
|
||||
@ -570,8 +567,6 @@ def _get_subtitles(self, vod_id):
|
||||
# TODO: when this happens, should I forget a partial chat history, or is it better to keep it?
|
||||
# I think if I keep it, it might be better to persist a warning that it is incomplete
|
||||
|
||||
# time.sleep(5)
|
||||
|
||||
response_errors = traverse_obj(response, (..., 'errors'))
|
||||
if response_errors:
|
||||
self.report_warning(f"Error response recevied for fetching next chat history fragment: {response_errors}")
|
||||
@ -600,10 +595,10 @@ def _get_subtitles(self, vod_id):
|
||||
|
||||
if not chat_history:
|
||||
return
|
||||
else:
|
||||
self.write_debug(f'Extracted {len(chat_history)} chat messages')
|
||||
|
||||
self.to_screen('Extracted %d chat messages' % len(chat_history))
|
||||
|
||||
return { 'rechat': [{
|
||||
return {'rechat': [{
|
||||
'data': json.dumps(chat_history),
|
||||
'ext': 'twitch-gql-20221228.json'
|
||||
}]}
|
||||
@ -628,7 +623,12 @@ def _real_extract(self, url):
|
||||
info['start_time'] = parse_duration(query['t'][0])
|
||||
|
||||
if info.get('timestamp'):
|
||||
info['subtitles'] = self.extract_subtitles(vod_id)
|
||||
info['subtitles'] = {'rechat': [{
|
||||
'url': update_url_query(f'https://api.twitch.tv/v5/videos/{vod_id}/comments',
|
||||
{'client_id': self._CLIENT_ID}),
|
||||
'ext': 'json',
|
||||
}]},
|
||||
info['__post_extractor'] = lambda: {'subtitles': self.extract_subtitles(vod_id)}
|
||||
|
||||
return info
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user