Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.settings
/.project
/.pydevproject
*.pyc
*.pyo
/.idea
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# script.module.python.twitch
# python-twitch for Kodi (script.module.python.twitch)

# Currently Staging * Untested/Not working

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.
16 changes: 16 additions & 0 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.python-twitch" name="python-twitch for Kodi" version="1.0.0~alpha1" provider-name="">
<requires>
<import addon="xbmc.python" version="2.1.0"/>
<import addon="script.module.six" version="1.9.0"/>
</requires>
<extension point="xbmc.python.module" library="resources/lib"/>
<extension point="xbmc.addon.metadata">
<platform>all</platform>
<summary lang="en">A fork of python-twitch, for Kodi</summary>
<description lang="en">python-twitch for Kodi is module for interaction with the Twitch.tv API based on python-twitch by ingwinlu.</description>
<license>GNU GENERAL PUBLIC LICENSE. Version 3, 29 June 2007</license>
<forum> </forum>
<source>https://github.com/MrSprigster/script.module.python.twitch</source>
</extension>
</addon>
4 changes: 4 additions & 0 deletions resources/lib/twitch/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- encoding: utf-8 -*-

VERSION = '1.3.0'
CLIENT_ID = 'conc17x2vpauvp2youhs3legi90c6jx'
6 changes: 6 additions & 0 deletions resources/lib/twitch/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- encoding: utf-8 -*-

from twitch.api import v3
from twitch.api import v3 as default

__all__ = ['v3', 'default']
40 changes: 40 additions & 0 deletions resources/lib/twitch/api/parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- encoding: utf-8 -*-


class _Parameter(object):
_valid = []

@classmethod
def validate(cls, value):
if value in cls._valid:
return value
raise ValueError(value)


class Period(_Parameter):
WEEK = 'week'
MONTH = 'month'
ALL = 'all'
_valid = [WEEK, MONTH, ALL]


class Boolean(_Parameter):
TRUE = 'true'
FALSE = 'false'

_valid = [TRUE, FALSE]


class Direction(_Parameter):
DESC = 'desc'
ASC = 'asc'

_valid = [DESC, ASC]


class SortBy(_Parameter):
CREATED_AT = 'created_at'
LAST_BROADCAST = 'last_broadcast'
LOGIN = 'login'

_valid = [CREATED_AT, LAST_BROADCAST, LOGIN]
67 changes: 67 additions & 0 deletions resources/lib/twitch/api/usher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- encoding: utf-8 -*-

from twitch.logging import log # NOQA
log.warning('By using this module you are violating the Twitch TOS') # NOQA

from twitch import keys
from twitch.api.parameters import Boolean
from twitch.parser import m3u8
from twitch.queries import HiddenApiQuery, UsherQuery
from twitch.queries import query


@query
def channel_token(channel):
q = HiddenApiQuery('channels/{channel}/access_token')
q.add_urlkw(keys.CHANNEL, channel)
return q


@query
def vod_token(id):
q = HiddenApiQuery('vods/{vod}/access_token')
q.add_urlkw(keys.VOD, id)
return q


@query
def _legacy_video(id):
q = HiddenApiQuery('videos/{id}')
q.add_urlkw(keys.ID, id)
return q


@m3u8
@query
def live(channel):
token = channel_token(channel)

q = UsherQuery('api/channel/hls/{channel}.m3u8')
q.add_urlkw(keys.CHANNEL, channel)
q.add_param(keys.SIG, token[keys.SIG])
q.add_param(keys.TOKEN, token[keys.TOKEN])
q.add_param(keys.ALLOW_SOURCE, Boolean.FALSE)
return q


@m3u8
@query
def _vod(id):
id = id[1:]

token = vod_token(id)

q = UsherQuery('vod/{id}')
q.add_urlkw(keys.ID, id)
q.add_param(keys.NAUTHSIG, token[keys.SIG])
q.add_param(keys.NAUTH, token[keys.TOKEN])
return q


def video(id):
if id.startswith('v'):
return _vod(id)
elif id.startswith(('a', 'c')):
return _legacy_video(id)
else:
raise NotImplementedError('Unknown Video Type')
2 changes: 2 additions & 0 deletions resources/lib/twitch/api/v2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- encoding: utf-8 -*-
# https://github.com/justintv/Twitch-API/blob/master/v2_resources/
16 changes: 16 additions & 0 deletions resources/lib/twitch/api/v3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- encoding: utf-8 -*-
# https://github.com/justintv/Twitch-API/blob/master/v3_resources/

from twitch.api.v3 import blocks # NOQA
from twitch.api.v3 import channels # NOQA
from twitch.api.v3 import chat # NOQA
from twitch.api.v3 import follows # NOQA
from twitch.api.v3 import games # NOQA
from twitch.api.v3 import ingests # NOQA
from twitch.api.v3 import search # NOQA
from twitch.api.v3 import streams # NOQA
from twitch.api.v3 import subscriptions # NOQA
from twitch.api.v3 import teams # NOQA
from twitch.api.v3 import users # NOQA
from twitch.api.v3 import videos # NOQA
from twitch.api.v3.root import root # NOQA
22 changes: 22 additions & 0 deletions resources/lib/twitch/api/v3/blocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-
# https://github.com/justintv/Twitch-API/blob/master/v3_resources/blocks.md

from twitch.queries import query


# Needs Authentification
@query
def by_name(user):
raise NotImplementedError


# Needs Authentification, needs PUT
@query
def add_block(user, target):
raise NotImplementedError


# Needs Authentification, needs DELETE
@query
def del_block(user, target):
raise NotImplementedError
54 changes: 54 additions & 0 deletions resources/lib/twitch/api/v3/channels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- encoding: utf-8 -*-
# https://github.com/justintv/Twitch-API/blob/master/v3_resources/channels.md

from twitch import keys
from twitch.queries import V3Query as Qry
from twitch.queries import query

from .videos import by_channel


@query
def by_name(name):
q = Qry('channels/{channel}')
q.add_urlkw(keys.CHANNEL, name)
return q


@query
def channel():
raise NotImplementedError


def get_videos(name, **kwargs):
return by_channel(name, **kwargs)


@query
def editors(name):
raise NotImplementedError


# TODO needs authentification and put requests
@query
def update(name, status=None, game=None, delay=0):
raise NotImplementedError


# TODO needs auth
@query
def delete(name):
raise NotImplementedError


# TODO needs auth, needs POST request
@query
def commercial(name, length=30):
raise NotImplementedError


@query
def teams(name):
q = Qry('channels/{channel}/teams')
q.add_urlkw('channel', name)
return q
26 changes: 26 additions & 0 deletions resources/lib/twitch/api/v3/chat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- encoding: utf-8 -*-
# https://github.com/justintv/Twitch-API/blob/master/v3_resources/chat.md

from twitch import keys
from twitch.queries import V3Query as Qry
from twitch.queries import query


@query
def by_channel(name):
q = Qry('chat/{channel}')
q.add_urlkw(keys.CHANNEL, name)
return q


@query
def badges(name):
q = Qry('chat/{channel}/badges')
q.add_urlkw(keys.CHANNEL, name)
return q


@query
def emoticons():
q = Qry('chat/emoticons')
return q
55 changes: 55 additions & 0 deletions resources/lib/twitch/api/v3/follows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# -*- encoding: utf-8 -*-
# https://github.com/justintv/Twitch-API/blob/master/v3_resources/follows.md

from twitch import keys
from twitch.api.parameters import Direction, SortBy
from twitch.queries import V3Query as Qry
from twitch.queries import query


@query
def by_channel(name, limit=25, offset=0, direction=Direction.DESC):
q = Qry('channels/{channel}/follows')
q.add_urlkw(keys.CHANNEL, name)
q.add_param(keys.LIMIT, limit, 25)
q.add_param(keys.OFFSET, offset, 0)
q.add_param(keys.DIRECTION, direction, Direction.DESC)
return q


@query
def by_user(name, limit=25, offset=0, direction=Direction.DESC,
sort_by=SortBy.CREATED_AT):
q = Qry('users/{user}/follows/channels')
q.add_urlkw(keys.USER, name)
q.add_param(keys.LIMIT, limit, 25)
q.add_param(keys.OFFSET, offset, 0)
q.add_param(keys.DIRECTION, direction, Direction.DESC)
q.add_param(keys.SORT_BY, sort_by, SortBy.CREATED_AT)
return q


@query
def status(user, target):
q = Qry('users/{user}/follows/channels/{target}')
q.add_urlkw(keys.USER, user)
q.add_urlkw(keys.TARGET, target)
return q


# Needs Auth, needs PUT
@query
def follow(user, target):
raise NotImplementedError


# Needs Auth, needs DELETE
@query
def unfollow(user, target):
raise NotImplementedError


# Needs Auth
@query
def streams():
raise NotImplementedError
14 changes: 14 additions & 0 deletions resources/lib/twitch/api/v3/games.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- encoding: utf-8 -*-
# https://github.com/justintv/Twitch-API/blob/master/v3_resources/games.md

from twitch import keys
from twitch.queries import V3Query as Qry
from twitch.queries import query


@query
def top(limit=10, offset=0):
q = Qry('games/top')
q.add_param(keys.LIMIT, limit, 10)
q.add_param(keys.OFFSET, offset, 0)
return q
11 changes: 11 additions & 0 deletions resources/lib/twitch/api/v3/ingests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- encoding: utf-8 -*-
# https://github.com/justintv/Twitch-API/blob/master/v3_resources/ingests.md

from twitch.queries import V3Query as Qry
from twitch.queries import query


@query
def get():
q = Qry('ingests')
return q
11 changes: 11 additions & 0 deletions resources/lib/twitch/api/v3/root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- encoding: utf-8 -*-
# https://github.com/justintv/Twitch-API/blob/master/v3_resources/root.md

from twitch.queries import V3Query as Qry
from twitch.queries import query


# TODO token as parameter
@query
def root():
return Qry('')
Loading