From c09a8de05dbbf2ad87c28d130086deb259ab6986 Mon Sep 17 00:00:00 2001 From: anxdpanic Date: Fri, 1 Mar 2019 10:01:06 -0500 Subject: [PATCH 1/3] change xrange to range --- resources/lib/twitch/api/parameters.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/lib/twitch/api/parameters.py b/resources/lib/twitch/api/parameters.py index c8ac4f9..b58d52e 100644 --- a/resources/lib/twitch/api/parameters.py +++ b/resources/lib/twitch/api/parameters.py @@ -10,7 +10,7 @@ See LICENSES/GPL-3.0-only for more information. """ -from six.moves import xrange +from six.moves import range from base64 import b64decode @@ -223,7 +223,7 @@ class IntRange(_Parameter): @classmethod def __init__(cls, first, last): - cls._valid = [i for i in xrange(first, last + 1)] + cls._valid = [i for i in range(first, last + 1)] class ItemCount(object): From 957a96625dde338114a76350195fb5ce4eb73e74 Mon Sep 17 00:00:00 2001 From: anxdpanic Date: Fri, 1 Mar 2019 10:38:03 -0500 Subject: [PATCH 2/3] add missing helix api endpoints --- addon.xml | 4 +- changelog.txt | 3 ++ resources/lib/twitch/api/helix/__init__.py | 7 ++- .../lib/twitch/api/helix/entitlements.py | 27 ++++++++++- resources/lib/twitch/api/helix/streams.py | 26 +++++++++- .../lib/twitch/api/helix/subscriptions.py | 35 ++++++++++++++ resources/lib/twitch/api/helix/tags.py | 48 +++++++++++++++++++ resources/lib/twitch/keys.py | 5 +- 8 files changed, 146 insertions(+), 9 deletions(-) create mode 100644 resources/lib/twitch/api/helix/subscriptions.py create mode 100644 resources/lib/twitch/api/helix/tags.py diff --git a/addon.xml b/addon.xml index 1ae1527..ec195cc 100644 --- a/addon.xml +++ b/addon.xml @@ -9,9 +9,7 @@ all -[add] add frame rate and resolution to returned stream information -[upd] update usher parameters -[upd] use SPDX license identifiers +[add] add missing helix api endpoints icon.png diff --git a/changelog.txt b/changelog.txt index 814a99e..4df219c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +2.0.6 +[add] add missing helix api endpoints + 2.0.5 [add] add frame rate and resolution to returned stream information [upd] update usher parameters diff --git a/resources/lib/twitch/api/helix/__init__.py b/resources/lib/twitch/api/helix/__init__.py index e463188..9593dbd 100644 --- a/resources/lib/twitch/api/helix/__init__.py +++ b/resources/lib/twitch/api/helix/__init__.py @@ -2,7 +2,7 @@ """ Reference: https://dev.twitch.tv/docs/ - Copyright (C) 2016-2018 script.module.python.twitch + Copyright (C) 2016-2019 script.module.python.twitch This file is part of script.module.python.twitch @@ -10,7 +10,8 @@ See LICENSES/GPL-3.0-only for more information. """ -__all__ = ['analytics', 'bits', 'clips', 'entitlements', 'games', 'streams', 'users', 'videos', 'webhooks'] +__all__ = ['analytics', 'bits', 'clips', 'entitlements', 'games', 'streams', + 'subscriptions', 'tags', 'users', 'videos', 'webhooks'] from . import analytics # NOQA from . import bits # NOQA @@ -18,6 +19,8 @@ from . import entitlements # NOQA from . import games # NOQA from . import streams # NOQA +from . import subscriptions # NOQA +from . import tags # NOQA from . import users # NOQA from . import videos # NOQA from . import webhooks # NOQA diff --git a/resources/lib/twitch/api/helix/entitlements.py b/resources/lib/twitch/api/helix/entitlements.py index 5ba5295..e146ad4 100644 --- a/resources/lib/twitch/api/helix/entitlements.py +++ b/resources/lib/twitch/api/helix/entitlements.py @@ -2,7 +2,7 @@ """ Reference: https://dev.twitch.tv/docs/api/reference - Copyright (C) 2016-2018 script.module.python.twitch + Copyright (C) 2016-2019 script.module.python.twitch This file is part of script.module.python.twitch @@ -10,8 +10,9 @@ See LICENSES/GPL-3.0-only for more information. """ -from ..parameters import EntitlementType +from ..parameters import EntitlementType, ItemCount from ... import keys +from ... import methods from ...queries import HelixQuery as Qry from ...queries import query @@ -25,3 +26,25 @@ def upload(manifest_id, entitlement_type=EntitlementType.BULK_DROPS_GRANT): q.add_param(keys.TYPE, EntitlementType.validate(entitlement_type)) return q + + +# required scope: none +# requires app access token +@query +def get_code_status(code, user_id): + q = Qry('entitlements/codes', use_app_token=True, method=methods.GET) + q.add_param(keys.CODE, ItemCount(max_items=20).validate(code), list()) + q.add_param(keys.USER_ID, user_id) + + return q + + +# required scope: none +# requires app access token +@query +def redeem_code(code, user_id): + q = Qry('entitlements/codes', use_app_token=True, method=methods.POST) + q.add_param(keys.CODE, ItemCount(max_items=20).validate(code), list()) + q.add_param(keys.USER_ID, user_id) + + return q diff --git a/resources/lib/twitch/api/helix/streams.py b/resources/lib/twitch/api/helix/streams.py index 7e7505b..1716d6a 100644 --- a/resources/lib/twitch/api/helix/streams.py +++ b/resources/lib/twitch/api/helix/streams.py @@ -2,7 +2,7 @@ """ Reference: https://dev.twitch.tv/docs/api/reference - Copyright (C) 2016-2018 script.module.python.twitch + Copyright (C) 2016-2019 script.module.python.twitch This file is part of script.module.python.twitch @@ -12,6 +12,7 @@ from ... import keys from ...api.parameters import Cursor, Language, IntRange, ItemCount +from ... import methods from ...queries import HelixQuery as Qry from ...queries import query @@ -58,3 +59,26 @@ def get_metadata(community_id=list(), game_id=list(), user_id=list(), q.add_param(keys.LANGUAGE, Language.validate(language), '') return q + + +# required scope: user:edit:broadcast +@query +def create_stream_marker(user_id, description=''): + q = Qry('streams/markers', use_app_token=False, method=methods.POST) + q.add_param(keys.USER_ID, user_id) + q.add_param(keys.DESCRIPTION, description, '') + + return q + + +# required scope: user:read:broadcast +@query +def get_stream_markers(user_id, video_id, after='MA==', before='MA==', first=20): + q = Qry('streams/markers', use_app_token=False, method=methods.GET) + q.add_param(keys.USER_ID, user_id) + q.add_param(keys.VIDEO_ID, video_id) + q.add_param(keys.AFTER, Cursor.validate(after), 'MA==') + q.add_param(keys.BEFORE, Cursor.validate(before), 'MA==') + q.add_param(keys.FIRST, IntRange(1, 100).validate(first), 20) + + return q diff --git a/resources/lib/twitch/api/helix/subscriptions.py b/resources/lib/twitch/api/helix/subscriptions.py new file mode 100644 index 0000000..238308d --- /dev/null +++ b/resources/lib/twitch/api/helix/subscriptions.py @@ -0,0 +1,35 @@ +# -*- encoding: utf-8 -*- +""" + Reference: https://dev.twitch.tv/docs/api/reference + + Copyright (C) 2016-2019 script.module.python.twitch + + This file is part of script.module.python.twitch + + SPDX-License-Identifier: GPL-3.0-only + See LICENSES/GPL-3.0-only for more information. +""" + +from ..parameters import ItemCount +from ... import keys, methods +from ...queries import HelixQuery as Qry +from ...queries import query + + +# required scope: channel:read:subscriptions +@query +def get_broadcaster_subscriptions(broadcaster_id): + q = Qry('subscriptions', use_app_token=False, method=methods.GET) + q.add_param(keys.BROADCASTER_ID, broadcaster_id) + + return q + + +# required scope: channel:read:subscriptions +@query +def get_user_subscriptions(broadcaster_id, user_id): + q = Qry('subscriptions', use_app_token=False, method=methods.GET) + q.add_param(keys.BROADCASTER_ID, broadcaster_id) + q.add_param(keys.USER_ID, ItemCount().validate(user_id), list()) + + return q diff --git a/resources/lib/twitch/api/helix/tags.py b/resources/lib/twitch/api/helix/tags.py new file mode 100644 index 0000000..aa9d022 --- /dev/null +++ b/resources/lib/twitch/api/helix/tags.py @@ -0,0 +1,48 @@ +# -*- encoding: utf-8 -*- +""" + Reference: https://dev.twitch.tv/docs/api/reference + + Copyright (C) 2016-2019 script.module.python.twitch + + This file is part of script.module.python.twitch + + SPDX-License-Identifier: GPL-3.0-only + See LICENSES/GPL-3.0-only for more information. +""" + +from ..parameters import Cursor, IntRange, ItemCount +from ... import keys, methods +from ...queries import HelixQuery as Qry +from ...queries import query + + +# required scope: none +# requires app access token +@query +def get_all_stream_tags(tag_id, after='MA==', first=20): + q = Qry('tags/streams', use_app_token=True, method=methods.GET) + q.add_param(keys.TAG_ID, ItemCount().validate(tag_id), list()) + q.add_param(keys.AFTER, Cursor.validate(after), 'MA==') + q.add_param(keys.FIRST, IntRange(1, 100).validate(first), 20) + + return q + + +# required scope: none +# requires app access token +@query +def get_stream_tags(broadcaster_id): + q = Qry('streams/tags', use_app_token=True, method=methods.GET) + q.add_param(keys.BROADCASTER_ID, broadcaster_id) + + return q + + +# required scope: user:edit:broadcast +@query +def replace_stream_tags(broadcaster_id, tag_ids=list()): + q = Qry('tags/streams', use_app_token=False, method=methods.PUT) + q.add_param(keys.BROADCASTER_ID, broadcaster_id) + q.add_param(keys.TAG_IDS, ItemCount().validate(tag_ids), list()) + + return q diff --git a/resources/lib/twitch/keys.py b/resources/lib/twitch/keys.py index e30b354..f96e446 100644 --- a/resources/lib/twitch/keys.py +++ b/resources/lib/twitch/keys.py @@ -3,7 +3,7 @@ string constants Copyright (C) 2012-2016 python-twitch (https://github.com/ingwinlu/python-twitch) - Copyright (C) 2016-2018 script.module.python.twitch + Copyright (C) 2016-2019 script.module.python.twitch This file is part of script.module.python.twitch @@ -29,6 +29,7 @@ CHANNEL_FEED_ENABLED = 'channel_feed_enabled' CHANNEL_ID = 'channel_id' CLIP = 'clip' +CODE = 'code' COLLECTION_ID = 'collection_id' COMMENT_ID = 'comment_id' COMMENTS = 'comments' @@ -100,6 +101,8 @@ STATUS = 'status' STREAM_TYPE = 'stream_type' SUMMARY = 'summary' +TAG_ID = 'tag_id' +TAG_IDS = 'tag_ids' TAG_LIST = 'tag_list' TARGET_ID = 'target_id' TEAM = 'team' From b3b5b876502ad656c977c22791a2d5d624179550 Mon Sep 17 00:00:00 2001 From: anxdpanic Date: Fri, 1 Mar 2019 10:38:13 -0500 Subject: [PATCH 3/3] 2.0.6 --- addon.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon.xml b/addon.xml index ec195cc..52144c4 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@ - +