Skip to content

Commit

Permalink
Merge pull request #90 from Felk/twitch_string_ids
Browse files Browse the repository at this point in the history
Parse twitch ids as strings instead of integers
  • Loading branch information
xenova committed Jul 1, 2021
2 parents 1ff4117 + 4f3e652 commit a854e80
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
19 changes: 10 additions & 9 deletions chat_downloader/sites/twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
timestamp_to_microseconds,
seconds_to_time,
int_or_none,
str_or_none,
replace_with_underscores,
multi_get,
remove_prefixes,
Expand Down Expand Up @@ -343,7 +344,7 @@ def _parse_emotes(text):
return emotes

_AUTHOR_REMAPPING = {
'_id': r('id', int_or_none),
'_id': r('id', str_or_none),
'name': 'name',
'display_name': 'display_name',
'logo': r('images', _parse_author_images),
Expand Down Expand Up @@ -487,7 +488,7 @@ def _parse_emotes(text):
# can be empty (which means it depends on dark/light theme)
'color': 'colour',
'display-name': 'author_display_name',
'user-id': r('author_id', int_or_none),
'user-id': r('author_id', str_or_none),



Expand All @@ -502,8 +503,7 @@ def _parse_emotes(text):

'id': 'message_id',
'mod': r('author_is_moderator', _parse_bool),
'room-id': r('channel_id', int_or_none),

'room-id': r('channel_id', str_or_none),
'tmi-sent-ts': r('timestamp', lambda x: int_or_none(x, 0) * 1000),

'subscriber': r('author_is_subscriber', _parse_bool),
Expand All @@ -516,7 +516,8 @@ def _parse_emotes(text):


'reply-parent-msg-body': r('in_reply_to_message', _decode_pseudo_BNF),
'reply-parent-user-id': r('in_reply_to_author_id', int_or_none),
'reply-parent-user-id': r('in_reply_to_author_id', str_or_none),

'reply-parent-msg-id': 'in_reply_to_message_id',
'reply-parent-display-name': 'in_reply_to_author_display_name',
'reply-parent-user-login': 'in_reply_to_author_name',
Expand Down Expand Up @@ -547,7 +548,7 @@ def _parse_emotes(text):
'number-of-viewers': 'number_of_viewers',

# ban user
'target-user-id': r('target_author_id', int_or_none),
'target-user-id': r('target_author_id', str_or_none),

# USERNOTICE - other
**_MESSAGE_PARAM_REMAPPING
Expand Down Expand Up @@ -910,7 +911,7 @@ def _parse_game(item):
return None

_CLIP_REMAPPING = {
'id': r('id', int_or_none),
'id': r('id', str_or_none),
'slug': 'slug',
'url': 'url',
'embedURL': 'embed_url',
Expand Down Expand Up @@ -973,7 +974,7 @@ def get_user_clips(self, username, limit=100, filter_by='LAST_WEEK'):
break

_VIDEO_REMAPPING = {
'id': r('id', int_or_none),
'id': r('id', str_or_none),
'animatedPreviewURL': 'animated_preview_url',
'game': r('game', _parse_game),

Expand Down Expand Up @@ -1056,7 +1057,7 @@ def get_featured_videos(self, username):

_LIVESTREAM_REMAPPING = {

'id': r('id', int_or_none),
'id': r('id', str_or_none),
'title': 'title',
'viewersCount': 'viewers',

Expand Down
7 changes: 7 additions & 0 deletions chat_downloader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ def float_or_none(v, default=None):
except (ValueError, TypeError):
return default

def str_or_none(v, default=None):
try:
return str(v)
except (ValueError, TypeError):
return default


def try_get_first_key(dictionary, default=None):
try:
return next(iter(dictionary))
Expand Down

0 comments on commit a854e80

Please sign in to comment.