Skip to content

Commit 4eb3a24

Browse files
authored
Merge pull request #70 from anxdpanic/dev
fix clip usher
2 parents 8c59f62 + 914fc19 commit 4eb3a24

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

addon.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<extension point="xbmc.addon.metadata">
1010
<platform>all</platform>
1111
<news>
12-
[fix] Python 3 - don't decode string when processing clips
12+
[fix] clip usher
1313
</news>
1414
<assets>
1515
<icon>icon.png</icon>

changelog.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2.0.12
2+
[fix] clip usher
3+
14
2.0.11
25
[fix] Python 3 - don't decode string when processing clips
36

resources/lib/twitch/api/usher.py

+30-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
See LICENSES/GPL-3.0-only for more information.
1212
"""
1313

14+
import json
15+
1416
from .. import keys
1517
from ..api.parameters import Boolean
1618
from ..parser import m3u8, clip_embed
@@ -170,7 +172,32 @@ def video(video_id, platform=keys.WEB, headers={}):
170172

171173
@clip_embed
172174
@query
173-
def clip(slug):
174-
q = ClipsQuery('api/v2/clips/{clip}/status')
175-
q.add_urlkw(keys.CLIP, slug)
175+
def clip(slug, headers={}):
176+
data = json.dumps({
177+
'query': '''{
178+
clip(slug: "%s") {
179+
broadcaster {
180+
displayName
181+
}
182+
createdAt
183+
curator {
184+
displayName
185+
id
186+
}
187+
durationSeconds
188+
id
189+
tiny: thumbnailURL(width: 86, height: 45)
190+
small: thumbnailURL(width: 260, height: 147)
191+
medium: thumbnailURL(width: 480, height: 272)
192+
title
193+
videoQualities {
194+
frameRate
195+
quality
196+
sourceURL
197+
}
198+
viewCount
199+
}
200+
}''' % slug,
201+
})
202+
q = ClipsQuery(headers=headers, data=data)
176203
return q

resources/lib/twitch/parser.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"""
1212

1313
import re
14-
from ast import literal_eval
15-
from six import PY2
14+
1615
from . import keys
1716
from .log import log
1817

@@ -133,20 +132,18 @@ def m3u8_to_list(string):
133132

134133
def clip_embed_to_list(response):
135134
log.debug('clip_embed_to_list called for:\n{0}'.format(response))
136-
if PY2 or isinstance(response, bytes):
137-
response = response.decode('utf-8')
138-
response = literal_eval(response)
139135
qualities = list()
140136
l = list()
141137

142138
if isinstance(response, dict):
143-
qualities = response.get('quality_options', list())
139+
clip = response.get('data', {}).get('clip', {})
140+
qualities = clip.get('videoQualities', list())
144141

145142
if qualities:
146143
l = [{
147144
'id': item['quality'],
148145
'name': item['quality'],
149-
'url': item['source'],
146+
'url': item['sourceURL'],
150147
'bandwidth': -1
151148
} for item in qualities]
152149
if l:

resources/lib/twitch/queries.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
_helix_baseurl = 'https://api.twitch.tv/helix/'
2525
_hidden_baseurl = 'https://api.twitch.tv/api/'
2626
_usher_baseurl = 'https://usher.ttvnw.net/'
27-
_clips_baseurl = 'https://clips.twitch.tv/'
27+
_clips_baseurl = 'https://gql.twitch.tv/gql'
2828
_uploads_baseurl = 'https://uploads.twitch.tv/'
2929
_oauth_baseurl = 'https://api.twitch.tv/kraken/oauth2/'
3030

@@ -195,11 +195,12 @@ def __init__(self, path, headers={}, data={}, method=methods.GET):
195195
self.add_path(path)
196196

197197

198-
class ClipsQuery(DownloadQuery):
199-
def __init__(self, path, headers={}, data={}, method=methods.GET):
198+
class ClipsQuery(JsonQuery):
199+
def __init__(self, path='', headers={}, data={}, method=methods.POST):
200200
_headers = deepcopy(headers)
201201
super(ClipsQuery, self).__init__(_clips_baseurl, _headers, data, method)
202-
self.add_path(path)
202+
if path:
203+
self.add_path(path)
203204

204205

205206
class UploadsQuery(DownloadQuery):

0 commit comments

Comments
 (0)