Skip to content

Commit d410b99

Browse files
authored
Merge pull request #633 from anxdpanic/pr_isengard
fixup rerun playback
2 parents 70b09c4 + 9622d69 commit d410b99

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

resources/lib/twitch_addon/addon/api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ def get_username(self):
120120
@cache.cache_method(cache_limit=cache.limit)
121121
def get_user_ids(self, logins):
122122
results = self.api.users.get_users(user_login=logins)
123-
return self.error_check(results)
123+
results = self.error_check(results)
124+
ids = []
125+
for user in results.get(Keys.DATA, [{}]):
126+
if user.get(Keys.ID):
127+
ids.append(user.get(Keys.ID))
128+
return ids
124129

125130
@api_error_handler
126131
@cache.cache_method(cache_limit=cache.limit)

resources/lib/twitch_addon/addon/converter.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,15 @@ def video_to_playitem(self, video):
281281
'content_type': 'video',
282282
'is_playable': True}
283283

284-
def stream_to_playitem(self, stream):
284+
def stream_to_playitem(self, stream, id_only=False):
285285
# path is returned '' and must be set after
286286
image = self.get_thumbnail(stream.get(Keys.THUMBNAIL_URL), Images.VIDEOTHUMB)
287-
title = self.get_title_for_stream(stream)
288-
info = self.get_plot_for_stream(stream, include_title=False)
287+
if not id_only:
288+
title = self.get_title_for_stream(stream)
289+
info = self.get_plot_for_stream(stream, include_title=False)
290+
else:
291+
title = stream.get(Keys.USER_NAME, stream.get(Keys.USER_LOGIN))
292+
info = {}
289293
info.update({'mediatype': 'video'})
290294
return {'label': title,
291295
'path': '',

resources/lib/twitch_addon/routes/play.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,34 @@ def _set_seek_time(value):
104104
elif channel_id or channel_name:
105105
if channel_name and not channel_id:
106106
result = api.get_user_ids(channel_name)
107-
result = result.get(Keys.DATA, [{}])[0]
108-
channel_id = result.get(Keys.ID)
107+
if result:
108+
channel_id = result[0]
109109
if channel_id:
110110
if not quality:
111111
quality = utils.get_default_quality('stream', channel_id)
112112
if quality:
113113
quality = quality[str(channel_id)]['quality']
114+
id_only = False
114115
result = api.get_channel_stream(channel_id)[Keys.DATA]
115116
if result:
116117
result = result[0]
117118
channel_name = result[Keys.USER_NAME] \
118119
if result[Keys.USER_NAME] else result[Keys.USER_LOGIN]
119120
name = result[Keys.USER_LOGIN]
121+
else: # rerun
122+
user = api.get_users(user_ids=channel_id)
123+
if user.get(Keys.DATA, [{}]):
124+
user = user[Keys.DATA][0]
125+
id_only = True
126+
name = user.get(Keys.LOGIN)
127+
result = {
128+
Keys.USER_NAME: user.get(Keys.DISPLAY_NAME, Keys.LOGIN),
129+
Keys.USER_LOGIN: user.get(Keys.LOGIN),
130+
Keys.USER_ID: user.get(Keys.ID),
131+
} # make a dummy result to continue with playback
132+
if name:
120133
videos = api.get_live(name)
121-
item_dict = converter.stream_to_playitem(result)
134+
item_dict = converter.stream_to_playitem(result, id_only=id_only)
122135
is_live = True
123136
elif slug:
124137
result = api.get_clip_by_slug(slug)

0 commit comments

Comments
 (0)