Skip to content

Commit 8cf9040

Browse files
authored
Merge pull request #3 from anxdpanic/pr-1
1.0.0~alpha1
2 parents a735df5 + a6ee4ad commit 8cf9040

10 files changed

Lines changed: 65 additions & 22 deletions

File tree

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
# python-twitch for Kodi (script.module.python.twitch)
1+
# python-twitch for Kodi
2+
###### script.module.python.twitch
23

3-
# Currently Staging * Untested/Not working
4+
python-twitch for Kodi is module for interaction with the Twitch.tv API
45

5-
This Kodi module is a based on python-twitch https://github.com/ingwinlu/python-twitch. Thanks to ingwinlu for his continued work on the project.
6+
#### Usage:
7+
Example can be found <link to Twitch on Kodi (v2) api module>
8+
9+
#### API Documentation:
10+
https://dev.twitch.tv/docs
11+
12+
---
13+
This Kodi module is a based on python-twitch https://github.com/ingwinlu/python-twitch
14+
Thanks to ingwinlu for his continued work on the project.

addon.xml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="script.module.python-twitch" name="python-twitch for Kodi" version="1.0.0~alpha1" provider-name="A Talented Community">
2+
<addon id="script.module.python.twitch" name="python-twitch for Kodi" version="1.0.0~alpha1" provider-name="A Talented Community">
33
<requires>
44
<import addon="xbmc.python" version="2.1.0"/>
55
<import addon="script.module.six" version="1.9.0"/>
6+
<import addon="script.module.requests" version="2.9.1"/>
67
</requires>
78
<extension point="xbmc.python.module" library="resources/lib"/>
89
<extension point="xbmc.addon.metadata">
910
<platform>all</platform>
10-
<summary lang="en">A fork of python-twitch, for Kodi</summary>
11+
<news>
12+
- initial release
13+
- use script.module.requests
14+
- remove default client_id
15+
- add oauth token support
16+
- add authorization, client id headers to all api calls
17+
- update api.twitch to use https
18+
- update usher to allow_source
19+
- videos.by_channel from broadcasts bool to broadcast_type: 'archive', 'highlight', 'upload'
20+
- update m3u_pattern
21+
</news>
22+
<assets>
23+
<icon>icon.png</icon>
24+
<fanart>fanart.jpg</fanart>
25+
</assets>
26+
<platform>all</platform>
27+
<summary lang="en">Module for interaction with the Twitch.tv API</summary>
1128
<description lang="en">python-twitch for Kodi is module for interaction with the Twitch.tv API based on python-twitch by ingwinlu.</description>
1229
<license>GNU GENERAL PUBLIC LICENSE. Version 3, 29 June 2007</license>
1330
<forum> </forum>

changelog.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
1.0.0
2+
- initial release
3+
- use script.module.requests
4+
- remove default client_id
5+
- add oauth token support
6+
- add authorization, client id headers to all api calls
7+
- update api.twitch to use https
8+
- update usher to allow_source
9+
- videos.by_channel from broadcasts bool to broadcast_type: 'archive', 'highlight', 'upload'
10+
- update m3u_pattern

resources/lib/twitch/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- encoding: utf-8 -*-
22

33
VERSION = '1.3.0'
4-
CLIENT_ID = 'conc17x2vpauvp2youhs3legi90c6jx'
4+
CLIENT_ID = ''
5+
OAUTH_TOKEN = ''

resources/lib/twitch/api/usher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def live(channel):
4040
q.add_urlkw(keys.CHANNEL, channel)
4141
q.add_param(keys.SIG, token[keys.SIG])
4242
q.add_param(keys.TOKEN, token[keys.TOKEN])
43-
q.add_param(keys.ALLOW_SOURCE, Boolean.FALSE)
43+
q.add_param(keys.ALLOW_SOURCE, Boolean.TRUE)
4444
return q
4545

4646

@@ -55,6 +55,7 @@ def _vod(id):
5555
q.add_urlkw(keys.ID, id)
5656
q.add_param(keys.NAUTHSIG, token[keys.SIG])
5757
q.add_param(keys.NAUTH, token[keys.TOKEN])
58+
q.add_param(keys.ALLOW_SOURCE, Boolean.TRUE)
5859
return q
5960

6061

resources/lib/twitch/api/v3/videos.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ def top(limit=10, offset=0, game=None, period=Period.WEEK):
2828

2929
@query
3030
def by_channel(name, limit=10, offset=0,
31-
broadcasts=Boolean.FALSE, hls=Boolean.FALSE):
31+
broadcast_type=keys.ARCHIVE, hls=Boolean.FALSE):
3232
q = Qry('channels/{channel}/videos')
3333
q.add_urlkw(keys.CHANNEL, name)
3434
q.add_param(keys.LIMIT, limit, 10)
3535
q.add_param(keys.OFFSET, offset, 0)
36-
q.add_param(keys.BROADCASTS, Boolean.validate(broadcasts), Boolean.FALSE)
36+
q.add_param(keys.BROADCAST_TYPE, broadcast_type, keys.ARCHIVE)
3737
q.add_param(keys.HLS, Boolean.validate(hls), Boolean.FALSE)
3838
return q
3939

resources/lib/twitch/keys.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@
3535
USER_AGENT_STRING = ('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) '
3636
'Gecko/20100101 Firefox/6.0')
3737
VOD = 'vod'
38+
BROADCAST_TYPE = 'broadcast_type'
39+
ARCHIVE = 'archive'
40+
UPLOAD = 'upload'
41+
HIGHLIGHT = 'highlight'

resources/lib/twitch/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from twitch.logging import log
55

66
_m3u_pattern = re.compile(
7-
r'#EXT-X-MEDIA:.*'
7+
r'#EXT-X-MEDIA:TYPE=VIDEO.*'
88
r'GROUP-ID="(?P<group_id>.\w*)",'
99
r'NAME="(?P<group_name>\w*)"[,=\w]*\n'
1010
r'#EXT-X-STREAM-INF:.*\n('

resources/lib/twitch/queries.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
from six.moves.urllib.parse import urljoin
44

5-
from twitch import CLIENT_ID
5+
from twitch import CLIENT_ID, OAUTH_TOKEN
66
from twitch.exceptions import ResourceUnavailableException
77
from twitch.logging import log
88
from twitch.scraper import download, get_json
99

1010
_kraken_baseurl = 'https://api.twitch.tv/kraken/'
11-
_hidden_baseurl = 'http://api.twitch.tv/api/'
11+
_hidden_baseurl = 'https://api.twitch.tv/api/'
1212
_usher_baseurl = 'http://usher.twitch.tv/'
1313

1414
_v2_headers = {'ACCEPT': 'application/vnd.twitchtv.v2+json'}
@@ -81,18 +81,23 @@ def execute(self):
8181
class ApiQuery(JsonQuery):
8282
def __init__(self, path, headers={}):
8383
headers.setdefault('Client-Id', CLIENT_ID)
84+
headers.setdefault('Authorization', 'OAuth {access_token}'.format(access_token=OAUTH_TOKEN))
8485
super(ApiQuery, self).__init__(_kraken_baseurl, headers)
8586
self.add_path(path)
8687

8788

8889
class HiddenApiQuery(JsonQuery):
8990
def __init__(self, path, headers={}):
91+
headers.setdefault('Client-Id', CLIENT_ID)
92+
headers.setdefault('Authorization', 'OAuth {access_token}'.format(access_token=OAUTH_TOKEN))
9093
super(HiddenApiQuery, self).__init__(_hidden_baseurl, headers)
9194
self.add_path(path)
9295

9396

9497
class UsherQuery(DownloadQuery):
9598
def __init__(self, path, headers={}):
99+
headers.setdefault('Client-Id', CLIENT_ID)
100+
headers.setdefault('Authorization', 'OAuth {access_token}'.format(access_token=OAUTH_TOKEN))
96101
super(UsherQuery, self).__init__(_usher_baseurl, headers)
97102
self.add_path(path)
98103

resources/lib/twitch/scraper.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# -*- encoding: utf-8 -*-
2-
import six
2+
import requests
3+
# import six
34
from six.moves.urllib.error import URLError
45
from six.moves.urllib.parse import quote_plus # NOQA
56
from six.moves.urllib.parse import urlencode
6-
from six.moves.urllib.request import Request, urlopen
7+
# from six.moves.urllib.request import Request, urlopen
78

89
from twitch.keys import USER_AGENT, USER_AGENT_STRING
910
from twitch.logging import log
@@ -41,14 +42,9 @@ def download(baseurl, parameters={}, headers={}):
4142
data = ""
4243
for _ in range(MAX_RETRIES):
4344
try:
44-
req = Request(url, headers=headers)
45-
req.add_header(USER_AGENT, USER_AGENT_STRING)
46-
response = urlopen(req)
47-
if six.PY2:
48-
data = response.read()
49-
else:
50-
data = response.read().decode('utf-8')
51-
response.close()
45+
headers.update({USER_AGENT: USER_AGENT_STRING})
46+
response = requests.get(url, headers=headers)
47+
data = response.content
5248
break
5349
except Exception as err:
5450
if not isinstance(err, URLError):

0 commit comments

Comments
 (0)