Skip to content

Commit 006a627

Browse files
authored
Merge pull request #1 from anxdpanic/PR-Stage
Initial staging
2 parents e0af0a0 + 505fa9c commit 006a627

28 files changed

Lines changed: 823 additions & 1 deletion

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.settings
2+
/.project
3+
/.pydevproject
4+
*.pyc
5+
*.pyo
6+
/.idea

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
# script.module.python.twitch
1+
# python-twitch for Kodi (script.module.python.twitch)
2+
3+
# Currently Staging * Untested/Not working
4+
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.

addon.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?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="">
3+
<requires>
4+
<import addon="xbmc.python" version="2.1.0"/>
5+
<import addon="script.module.six" version="1.9.0"/>
6+
</requires>
7+
<extension point="xbmc.python.module" library="resources/lib"/>
8+
<extension point="xbmc.addon.metadata">
9+
<platform>all</platform>
10+
<summary lang="en">A fork of python-twitch, for Kodi</summary>
11+
<description lang="en">python-twitch for Kodi is module for interaction with the Twitch.tv API based on python-twitch by ingwinlu.</description>
12+
<license>GNU GENERAL PUBLIC LICENSE. Version 3, 29 June 2007</license>
13+
<forum> </forum>
14+
<source>https://github.com/MrSprigster/script.module.python.twitch</source>
15+
</extension>
16+
</addon>

resources/lib/twitch/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# -*- encoding: utf-8 -*-
2+
3+
VERSION = '1.3.0'
4+
CLIENT_ID = 'conc17x2vpauvp2youhs3legi90c6jx'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- encoding: utf-8 -*-
2+
3+
from twitch.api import v3
4+
from twitch.api import v3 as default
5+
6+
__all__ = ['v3', 'default']
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- encoding: utf-8 -*-
2+
3+
4+
class _Parameter(object):
5+
_valid = []
6+
7+
@classmethod
8+
def validate(cls, value):
9+
if value in cls._valid:
10+
return value
11+
raise ValueError(value)
12+
13+
14+
class Period(_Parameter):
15+
WEEK = 'week'
16+
MONTH = 'month'
17+
ALL = 'all'
18+
_valid = [WEEK, MONTH, ALL]
19+
20+
21+
class Boolean(_Parameter):
22+
TRUE = 'true'
23+
FALSE = 'false'
24+
25+
_valid = [TRUE, FALSE]
26+
27+
28+
class Direction(_Parameter):
29+
DESC = 'desc'
30+
ASC = 'asc'
31+
32+
_valid = [DESC, ASC]
33+
34+
35+
class SortBy(_Parameter):
36+
CREATED_AT = 'created_at'
37+
LAST_BROADCAST = 'last_broadcast'
38+
LOGIN = 'login'
39+
40+
_valid = [CREATED_AT, LAST_BROADCAST, LOGIN]

resources/lib/twitch/api/usher.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# -*- encoding: utf-8 -*-
2+
3+
from twitch.logging import log # NOQA
4+
log.warning('By using this module you are violating the Twitch TOS') # NOQA
5+
6+
from twitch import keys
7+
from twitch.api.parameters import Boolean
8+
from twitch.parser import m3u8
9+
from twitch.queries import HiddenApiQuery, UsherQuery
10+
from twitch.queries import query
11+
12+
13+
@query
14+
def channel_token(channel):
15+
q = HiddenApiQuery('channels/{channel}/access_token')
16+
q.add_urlkw(keys.CHANNEL, channel)
17+
return q
18+
19+
20+
@query
21+
def vod_token(id):
22+
q = HiddenApiQuery('vods/{vod}/access_token')
23+
q.add_urlkw(keys.VOD, id)
24+
return q
25+
26+
27+
@query
28+
def _legacy_video(id):
29+
q = HiddenApiQuery('videos/{id}')
30+
q.add_urlkw(keys.ID, id)
31+
return q
32+
33+
34+
@m3u8
35+
@query
36+
def live(channel):
37+
token = channel_token(channel)
38+
39+
q = UsherQuery('api/channel/hls/{channel}.m3u8')
40+
q.add_urlkw(keys.CHANNEL, channel)
41+
q.add_param(keys.SIG, token[keys.SIG])
42+
q.add_param(keys.TOKEN, token[keys.TOKEN])
43+
q.add_param(keys.ALLOW_SOURCE, Boolean.FALSE)
44+
return q
45+
46+
47+
@m3u8
48+
@query
49+
def _vod(id):
50+
id = id[1:]
51+
52+
token = vod_token(id)
53+
54+
q = UsherQuery('vod/{id}')
55+
q.add_urlkw(keys.ID, id)
56+
q.add_param(keys.NAUTHSIG, token[keys.SIG])
57+
q.add_param(keys.NAUTH, token[keys.TOKEN])
58+
return q
59+
60+
61+
def video(id):
62+
if id.startswith('v'):
63+
return _vod(id)
64+
elif id.startswith(('a', 'c')):
65+
return _legacy_video(id)
66+
else:
67+
raise NotImplementedError('Unknown Video Type')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# -*- encoding: utf-8 -*-
2+
# https://github.com/justintv/Twitch-API/blob/master/v2_resources/
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- encoding: utf-8 -*-
2+
# https://github.com/justintv/Twitch-API/blob/master/v3_resources/
3+
4+
from twitch.api.v3 import blocks # NOQA
5+
from twitch.api.v3 import channels # NOQA
6+
from twitch.api.v3 import chat # NOQA
7+
from twitch.api.v3 import follows # NOQA
8+
from twitch.api.v3 import games # NOQA
9+
from twitch.api.v3 import ingests # NOQA
10+
from twitch.api.v3 import search # NOQA
11+
from twitch.api.v3 import streams # NOQA
12+
from twitch.api.v3 import subscriptions # NOQA
13+
from twitch.api.v3 import teams # NOQA
14+
from twitch.api.v3 import users # NOQA
15+
from twitch.api.v3 import videos # NOQA
16+
from twitch.api.v3.root import root # NOQA
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- encoding: utf-8 -*-
2+
# https://github.com/justintv/Twitch-API/blob/master/v3_resources/blocks.md
3+
4+
from twitch.queries import query
5+
6+
7+
# Needs Authentification
8+
@query
9+
def by_name(user):
10+
raise NotImplementedError
11+
12+
13+
# Needs Authentification, needs PUT
14+
@query
15+
def add_block(user, target):
16+
raise NotImplementedError
17+
18+
19+
# Needs Authentification, needs DELETE
20+
@query
21+
def del_block(user, target):
22+
raise NotImplementedError

0 commit comments

Comments
 (0)