Skip to content

Commit f40e148

Browse files
authored
Merge pull request #124 from anxdpanic/pr_isengard
2.0.21~alpha2
2 parents 2329c7c + 32e2db3 commit f40e148

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

Diff for: addon.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="script.module.python.twitch" name="python-twitch for Kodi" version="2.0.21~alpha1" provider-name="anxdpanic, A Talented Community">
2+
<addon id="script.module.python.twitch" name="python-twitch for Kodi" version="2.0.21~alpha2" provider-name="anxdpanic, A Talented Community">
33
<requires>
44
<import addon="xbmc.python" version="2.20.0"/>
55
<import addon="script.module.six" version="1.11.0"/>

Diff for: resources/lib/twitch/api/usher.py

+23-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929
}
3030

3131

32+
def get_access_token(token):
33+
stream_access_token = None
34+
video_access_token = None
35+
if isinstance(token, list):
36+
if token:
37+
data = token[0].get(keys.DATA, {})
38+
stream_access_token = data.get(keys.STREAM_PLAYBACK_ACCESS_TOKEN)
39+
video_access_token = data.get(keys.VIDEO_PLAYBACK_ACCESS_TOKEN)
40+
return stream_access_token or video_access_token or token
41+
42+
3243
def valid_video_id(video_id):
3344
if video_id.startswith('videos'):
3445
video_id = 'v' + video_id[6:]
@@ -80,10 +91,12 @@ def _legacy_video(video_id):
8091

8192
def live_request(channel, platform=keys.WEB, headers={}):
8293
token = channel_token(channel, platform=platform, headers=headers)
83-
token = token[0][keys.DATA][keys.STREAM_PLAYBACK_ACCESS_TOKEN]
94+
token = get_access_token(token)
8495

8596
if not token:
8697
return ACCESS_TOKEN_EXCEPTION
98+
elif isinstance(token, dict) and 'error' in token:
99+
return token
87100
else:
88101
signature = token[keys.SIGNATURE]
89102
access_token = token[keys.VALUE]
@@ -133,9 +146,11 @@ def _live(channel, token, headers={}):
133146
@m3u8
134147
def live(channel, platform=keys.WEB, headers={}):
135148
token = channel_token(channel, platform=platform, headers=headers)
136-
token = token[0][keys.DATA][keys.STREAM_PLAYBACK_ACCESS_TOKEN]
149+
token = get_access_token(token)
137150
if not token:
138151
return ACCESS_TOKEN_EXCEPTION
152+
elif isinstance(token, dict) and 'error' in token:
153+
return token
139154
else:
140155
return _live(channel, token, headers=headers)
141156

@@ -144,10 +159,12 @@ def video_request(video_id, platform=keys.WEB, headers={}):
144159
video_id = valid_video_id(video_id)
145160
if video_id:
146161
token = vod_token(video_id, platform=platform, headers=headers)
147-
token = token[0][keys.DATA][keys.VIDEO_PLAYBACK_ACCESS_TOKEN]
162+
token = get_access_token(token)
148163

149164
if not token:
150165
return ACCESS_TOKEN_EXCEPTION
166+
elif isinstance(token, dict) and 'error' in token:
167+
return token
151168
else:
152169
signature = token[keys.SIGNATURE]
153170
access_token = token[keys.VALUE]
@@ -203,10 +220,12 @@ def video(video_id, platform=keys.WEB, headers={}):
203220
video_id = valid_video_id(video_id)
204221
if video_id:
205222
token = vod_token(video_id, platform=platform, headers=headers)
206-
token = token[0][keys.DATA][keys.VIDEO_PLAYBACK_ACCESS_TOKEN]
223+
token = get_access_token(token)
207224

208225
if not token:
209226
return ACCESS_TOKEN_EXCEPTION
227+
elif isinstance(token, dict) and 'error' in token:
228+
return token
210229
else:
211230
return _vod(video_id, token, headers=headers)
212231
else:

0 commit comments

Comments
 (0)