Skip to content

Commit 4f19784

Browse files
authored
Merge pull request #77 from anxdpanic/pr_isengard
change followed, following, and unfollowing games to use gql endpoints
2 parents 8ace366 + da65b11 commit 4f19784

File tree

6 files changed

+88
-16
lines changed

6 files changed

+88
-16
lines changed

addon.xml

Lines changed: 2 additions & 2 deletions
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.15" provider-name="anxdpanic, A Talented Community">
2+
<addon id="script.module.python.twitch" name="python-twitch for Kodi" version="2.0.16~beta1" 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"/>
@@ -9,7 +9,7 @@
99
<extension point="xbmc.addon.metadata">
1010
<platform>all</platform>
1111
<news>
12-
[upd] Update material to reflect repository changes
12+
[chg] change followed, following, and unfollowing games to use gql endpoints
1313
</news>
1414
<assets>
1515
<icon>icon.png</icon>

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2.0.16
2+
[chg] change followed, following, and unfollowing games to use gql endpoints
3+
14
2.0.15
25
[upd] Update material to reflect repository changes
36

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
msgid ""
2+
msgstr ""
3+
"Project-Id-Version: \n"
4+
"Report-Msgid-Bugs-To: \n"
5+
"POT-Creation-Date: 2016-09-18 00:54+0000\n"
6+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
7+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
8+
"Language-Team: LANGUAGE\n"
9+
"Language: en_GB\n"
10+
"MIME-Version: 1.0\n"
11+
"Content-Type: text/plain; charset=UTF-8\n"
12+
"Content-Transfer-Encoding: 8bit\n"
13+
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
14+
15+
# msgctxt "#30000"
16+
# msgid ""
17+
# msgstr ""

resources/lib/twitch/api/v5/games.py

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from ... import keys, methods
1414
from ...queries import V5Query as Qry
1515
from ...queries import HiddenApiQuery as HQry
16+
from ...queries import GQLQuery as GQLQry
1617
from ...queries import query
1718

1819

@@ -38,29 +39,63 @@ def _check_follows(username, name, headers={}):
3839
# required scope: none
3940
# undocumented / unsupported
4041
@query
41-
def _get_followed(username, limit=25, offset=0, headers={}):
42-
q = HQry('users/{username}/follows/games', headers=headers, use_token=False)
43-
q.add_urlkw(keys.USERNAME, username)
44-
q.add_param(keys.LIMIT, limit, 25)
45-
q.add_param(keys.OFFSET, offset, 0)
42+
def _get_followed(limit=100, headers={}):
43+
data = [{
44+
"operationName": "FollowingGames_CurrentUser",
45+
"variables": {
46+
"limit": limit,
47+
"type": "LIVE"
48+
},
49+
"extensions": {
50+
"persistedQuery": {
51+
"version": 1,
52+
"sha256Hash": "8446d4d234005813dc1f024f487ce95434c3e4202f451dd42777935b5ed035ce"
53+
}
54+
}
55+
}]
56+
q = GQLQry('', headers=headers, data=data, use_token=False)
4657
return q
4758

4859

4960
# required scope: user_follows_edit
5061
# undocumented / unsupported
5162
@query
52-
def _follow(username, name, headers={}):
53-
q = HQry('users/{username}/follows/games/follow', headers=headers, method=methods.PUT)
54-
q.add_urlkw(keys.USERNAME, username)
55-
q.add_data(keys.NAME, name)
63+
def _follow(game_id, headers={}):
64+
data = [{
65+
"operationName": "FollowGameButton_FollowGame",
66+
"variables": {
67+
"input": {
68+
"gameID": str(game_id)
69+
}
70+
},
71+
"extensions": {
72+
"persistedQuery": {
73+
"version": 1,
74+
"sha256Hash": "b846b65ba4bc9a3561dbe2d069d95deed9b9e031bcfda2482d1bedd84a1c2eb3"
75+
}
76+
}
77+
}]
78+
q = GQLQry('', headers=headers, data=data, use_token=False)
5679
return q
5780

5881

5982
# required scope: user_follows_edit
6083
# undocumented / unsupported
6184
@query
62-
def _unfollow(username, name, headers={}):
63-
q = HQry('users/{username}/follows/games/unfollow', headers=headers, method=methods.DELETE)
64-
q.add_urlkw(keys.USERNAME, username)
65-
q.add_data(keys.NAME, name)
85+
def _unfollow(game_id, headers={}):
86+
data = [{
87+
"operationName": "FollowGameButton_UnfollowGame",
88+
"variables": {
89+
"input": {
90+
"gameID": str(game_id)
91+
}
92+
},
93+
"extensions": {
94+
"persistedQuery": {
95+
"version": 1,
96+
"sha256Hash": "811e02e396ebba0664f21ff002f2eff3c6f57e8af9aedb4f4dfa77cefd0db43d"
97+
}
98+
}
99+
}]
100+
q = GQLQry('', headers=headers, data=data, use_token=False)
66101
return q

resources/lib/twitch/queries.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
_usher_baseurl = 'https://usher.ttvnw.net/'
2727
_clips_baseurl = 'https://gql.twitch.tv/gql'
2828
_uploads_baseurl = 'https://uploads.twitch.tv/'
29+
_gql_baseurl = 'https://gql.twitch.tv/gql'
2930
_oauth_baseurl = 'https://api.twitch.tv/kraken/oauth2/'
3031

3132

@@ -221,6 +222,16 @@ def __init__(self, path, use_app_token=False, method=methods.GET):
221222
super(HelixQuery, self).__init__(path, use_app_token=use_app_token, method=method)
222223

223224

225+
class GQLQuery(JsonQuery):
226+
def __init__(self, path, headers={}, data={}, use_token=True, method=methods.POST):
227+
_headers = deepcopy(headers)
228+
_headers.setdefault('Client-ID', CLIENT_ID)
229+
if use_token and OAUTH_TOKEN:
230+
_headers.setdefault('Authorization', 'OAuth {access_token}'.format(access_token=OAUTH_TOKEN))
231+
super(GQLQuery, self).__init__(_gql_baseurl, _headers, data, method)
232+
self.add_path(path)
233+
234+
224235
def assert_new(d, k):
225236
if k in d:
226237
v = d.get(k)

resources/lib/twitch/scraper.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ def download(baseurl, parameters={}, headers={}, data={}, method=methods.GET, re
9595
for _ in range(MAX_RETRIES):
9696
try:
9797
headers.update({USER_AGENT: USER_AGENT_STRING})
98-
response = requests.request(method=method, url=url, headers=headers, data=data, verify=SSL_VERIFICATION)
98+
if isinstance(data, list):
99+
json_body = data
100+
data = None
101+
else:
102+
json_body = None
103+
response = requests.request(method=method, url=url, headers=headers,
104+
json=json_body, data=data, verify=SSL_VERIFICATION)
99105
content = response.content
100106
if not content:
101107
content = '{{"status": {0}}}'.format(response.status_code)

0 commit comments

Comments
 (0)