mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-09-28 13:47:53 +00:00
twitch chat: review changes part 2
This commit is contained in:
parent
9d94a95e0e
commit
548c359b08
|
@ -24,7 +24,6 @@
|
|||
parse_iso8601,
|
||||
parse_qs,
|
||||
qualities,
|
||||
RetryManager,
|
||||
str_or_none,
|
||||
traverse_obj,
|
||||
try_get,
|
||||
|
@ -534,7 +533,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>
|
||||
}]
|
||||
|
||||
|
@ -543,8 +542,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)
|
||||
|
@ -552,8 +549,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}")
|
||||
|
@ -582,10 +577,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'
|
||||
}]}
|
||||
|
@ -622,7 +617,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 a new issue