Skip to content

Commit

Permalink
[sites:youtube] Make emotes optional (Fixes #97)
Browse files Browse the repository at this point in the history
  • Loading branch information
xenova committed Jul 1, 2021
1 parent 015fded commit 2212eb7
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions chat_downloader/sites/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,25 +423,27 @@ def _parse_runs(run_info, parse_links=True):

else: # is a normal message
message_info['message'] += run['text']

elif 'emoji' in run:
emoji = run['emoji']
emoji_id = emoji['emojiId']
emoji_id = emoji.get('emojiId')

name = emoji['shortcuts'][0]
name = multi_get(emoji, 'shortcuts', 0)

if emoji_id and emoji_id not in message_emotes:
if name:
if emoji_id and emoji_id not in message_emotes:

# TODO change to remapping?
message_emotes[emoji_id] = {
'id': emoji_id,
'name': name,
'shortcuts': emoji.get('shortcuts'),
'search_terms': emoji.get('searchTerms'),
'images': YouTubeChatDownloader._parse_thumbnails(emoji.get('image', {})),
'is_custom_emoji': emoji.get('isCustomEmoji', False)
}
# TODO change to remapping?
message_emotes[emoji_id] = {
'id': emoji_id,
'name': name,
'shortcuts': emoji.get('shortcuts'),
'search_terms': emoji.get('searchTerms'),
'images': YouTubeChatDownloader._parse_thumbnails(emoji.get('image', {})),
'is_custom_emoji': emoji.get('isCustomEmoji', False)
}

message_info['message'] += name
message_info['message'] += name

else:
# unknown run
Expand Down Expand Up @@ -1128,8 +1130,10 @@ def _get_initial_video_info(self, video_id):
else:
# Video exists, but you cannot view chat for some reason

error_runs = multi_get(conversation_bar, 'conversationBarRenderer', 'availabilityMessage', 'messageRenderer', 'text')
error_message = self._parse_runs(error_runs, False)['message'] if error_runs else 'Video does not have a chat replay.'
error_runs = multi_get(conversation_bar, 'conversationBarRenderer',
'availabilityMessage', 'messageRenderer', 'text')
error_message = self._parse_runs(error_runs, False)[
'message'] if error_runs else 'Video does not have a chat replay.'

raise NoChatReplay(error_message)

Expand Down

0 comments on commit 2212eb7

Please sign in to comment.