From a5417b44d4a6da2342abed235ea714387baf8d02 Mon Sep 17 00:00:00 2001 From: anxdpanic Date: Sat, 12 Feb 2022 13:22:43 -0500 Subject: [PATCH] add helix search endpoints --- resources/lib/twitch/api/helix/search.py | 39 ++++++++++++++++++++++++ resources/lib/twitch/keys.py | 1 + 2 files changed, 40 insertions(+) create mode 100644 resources/lib/twitch/api/helix/search.py diff --git a/resources/lib/twitch/api/helix/search.py b/resources/lib/twitch/api/helix/search.py new file mode 100644 index 0000000..5b4dcb5 --- /dev/null +++ b/resources/lib/twitch/api/helix/search.py @@ -0,0 +1,39 @@ +# -*- encoding: utf-8 -*- +""" + Reference: https://dev.twitch.tv/docs/api/reference + + Copyright (C) 2022- 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 ... import keys +from ...api.parameters import Boolean, Cursor, IntRange +from ...queries import HelixQuery as Qry +from ...queries import query + + +# required scope: none +@query +def get_categories(search_query, after='MA==', first=20, use_app_token=False): + q = Qry('search/categories', use_app_token=use_app_token) + q.add_param(keys.QUERY, search_query) + 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 +@query +def get_channels(search_query, after='MA==', first=20, live_only=True, use_app_token=False): + q = Qry('search/channels', use_app_token=use_app_token) + q.add_param(keys.QUERY, search_query) + q.add_param(keys.AFTER, Cursor.validate(after), 'MA==') + q.add_param(keys.FIRST, IntRange(1, 100).validate(first), 20) + q.add_param(keys.LIVE_ONLY, Boolean.validate(live_only), True) + + return q diff --git a/resources/lib/twitch/keys.py b/resources/lib/twitch/keys.py index ea65173..c33d0e3 100644 --- a/resources/lib/twitch/keys.py +++ b/resources/lib/twitch/keys.py @@ -70,6 +70,7 @@ LANGUAGE = 'language' LIMIT = 'limit' LIVE = 'live' +LIVE_ONLY = 'live_only' LOGIN = 'login' MANIFEST_ID = 'manifest_id' MEDIAPLAYER = 'mediaplayer'