Skip to content

Commit

Permalink
[sites:youtube] Fix issue with Top/Live chat continuations in differe…
Browse files Browse the repository at this point in the history
…nt languages (#75)
  • Loading branch information
xenova committed Feb 20, 2021
1 parent 8c81a86 commit 421781c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions chat_downloader/sites/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ def _get_initial_video_info(self, video_id):

def _get_chat_messages(self, initial_info, params):

initial_continuation_info = initial_info.get('continuation_info')
initial_continuation_info = initial_info.get('continuation_info') or {}

# stream_start_time = initial_info.get('start_time')
is_live = initial_info.get('is_live')
Expand All @@ -1013,18 +1013,22 @@ def _get_chat_messages(self, initial_info, params):
# Top chat replay - Some messages, such as potential spam, may not be visible
# Live chat replay - All messages are visible
chat_type = params.get('chat_type').title() # Live or Top
continuation_title = '{} chat'.format(chat_type)

continuation_values = list(initial_continuation_info.values())
continuation_keys = list(initial_continuation_info.keys())
if len(continuation_values) < 2:
raise NoContinuation(
'Initial continuation information could not be found.'.format(initial_continuation_info))

continuation_index = 0 if chat_type == 'Top' else 1
continuation = continuation_values[continuation_index]
log('debug', 'Getting {} chat ({}).'.format(
chat_type, continuation_keys[continuation_index]))

api_type = 'live_chat'
if not is_live:
continuation_title += ' replay'
api_type += '_replay'

continuation = initial_continuation_info.get(continuation_title)
if not continuation:
raise NoContinuation(
'Initial continuation information could not be found for {}.'.format(continuation_title))

init_page = self._YOUTUBE_INIT_API_TEMPLATE.format(
api_type, continuation)
# must run to get first few messages, otherwise might miss some
Expand Down

0 comments on commit 421781c

Please sign in to comment.