1
0
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:
mpeter50 2023-07-14 13:38:50 +02:00
parent 206ca4092b
commit 0aa41b8e84

View File

@ -21,7 +21,6 @@
parse_iso8601,
parse_qs,
qualities,
RetryManager,
str_or_none,
try_get,
unified_timestamp,
@ -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,8 +595,8 @@ def _get_subtitles(self, vod_id):
if not chat_history:
return
self.to_screen('Extracted %d chat messages' % len(chat_history))
else:
self.write_debug(f'Extracted {len(chat_history)} chat messages')
return {'rechat': [{
'data': json.dumps(chat_history),
@ -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