def credentials_from_config_file():
    client_id = None
    oauth_token = None

    config = _get_config()
    if "Credentials" in config.sections():
        client_id = config["Credentials"].get("client_id")
        oauth_token = config["Credentials"].get("oauth_token")

    return client_id, oauth_token BASE_OAUTH_URL = "https://id.twitch.tv/oauth2/" PERIOD_ALL = "all" PERIODS = [PERIOD_DAY, PERIOD_WEEK, PERIOD_MONTH, PERIOD_ALL] VIDEO_SORT_TIME = "time" VIDEO_SORTS = [VIDEO_SORT_TIME, VIDEO_SORT_TRENDING, VIDEO_SORT_VIEWS] VIDEO_TYPE_ALL = "all" VIDEO_TYPES = [
    VIDEO_TYPE_ALL,
    VIDEO_TYPE_UPLAOD,
    VIDEO_TYPE_ARCHIVE,
    VIDEO_TYPE_HIGHLIGHT,
] class TwitchAttributeException(TwitchException):
    pass class TwitchOAuthException(TwitchException):
    pass class APICursor(TwitchAPIMixin):
    def __init__(
        self, client_id, path, resource, oauth_token=None, cursor=None, params=None
    ):
        super(APICursor, self).__init__()
        self._path = path
        self._queue = []
        self._cursor = cursor
        self._resource = resource
        self._client_id = client_id
        self._oauth_token = oauth_token
        self._params = params
        self._total = None
        self._requests_count = 0

        # Pre-fetch the first page as soon as cursor is instantiated
        self.next_page()

    def __repr__(self):
        return str(self._queue)

    def __len__(self):
        return len(self._queue)

    def __iter__(self):
        return self

    def __next__(self):
        if not self._queue and not self.next_page():
            raise StopIteration()

        return self._queue.pop(0)

    # Python 2 compatibility.
    next = __next__

    def __getitem__(self, index):
        return self._queue[index]

    def next_page(self):
        # Twitch stops returning a cursor when you're on the last page. So if we've made
        # more than 1 request to their API and we don't get a cursor back, it means
        # we're on the last page, so return whatever's left in the queue.
        if self._requests_count > 0 and not self._cursor:
            return self._queue

        if self._cursor:
            self._params["after"] = self._cursor

        response = self._request_get(self._path, params=self._params)
        self._requests_count += 1
        self._queue = [self._resource.construct_from(data) for data in response["data"]]
        self._cursor = response["pagination"].get("cursor")
        self._total = response.get("total")
        return self._queue

    @property
    def cursor(self):
        return self._cursor

    @property
    def total(self):
        if not self._total:
            raise TwitchNotProvidedException()
        return self._total class APIGet(TwitchAPIMixin):
    def __init__(self, client_id, path, resource, oauth_token=None, params=None):
        super(APIGet, self).__init__()
        self._path = path
        self._resource = resource
        self._client_id = client_id
        self._oauth_token = oauth_token
        self._params = params

    def fetch(self):
        response = self._request_get(self._path, params=self._params)
        return [self._resource.construct_from(data) for data in response["data"]] class Clip(TwitchObject):
    pass class Follow(TwitchObject):
    pass class Game(TwitchObject):
    pass class Stream(TwitchObject):
    pass class StreamMetadata(TwitchObject):
    pass class Tag(TwitchObject):
    pass class User(TwitchObject):
    pass class Video(TwitchObject):
    pass
from requests import post
from twitch.conf import credentials_from_config_file
from twitch.constants import (
    BASE_OAUTH_URL,
    PERIOD_ALL,
    PERIODS,
    VIDEO_SORT_TIME,
    VIDEO_SORTS,
    VIDEO_TYPE_ALL,
    VIDEO_TYPES,
)
from twitch.exceptions import TwitchAttributeException, TwitchOAuthException
from twitch.helix.base import APICursor, APIGet
from twitch.resources import (
    Clip,
    Follow,
    Game,
    Stream,
    StreamMetadata,
    Tag,
    User,
    Video,
)
        if "access_token" in response:
            self._oauth_token = response["access_token"]
        elif "message" in response:
            raise TwitchOAuthException(response["message"])
        else:
            raise TwitchOAuthException()

    def get_streams(
        self,
        after=None,
        before=None,
        community_ids=None,
        page_size=20,
        game_ids=None,
        languages=None,
        user_ids=None,
        user_logins=None,
    ):

        if community_ids and len(community_ids) > 100:
            raise TwitchAttributeException(
                "Maximum of 100 Community IDs can be supplied"
            )
        if game_ids and len(game_ids) > 100:
            raise TwitchAttributeException("Maximum of 100 Game IDs can be supplied")
        if languages and len(languages) > 100:
            raise TwitchAttributeException("Maximum of 100 languages can be supplied")
        if user_ids and len(user_ids) > 100:
            raise TwitchAttributeException("Maximum of 100 User IDs can be supplied")
        if user_logins and len(user_logins) > 100:
            raise TwitchAttributeException(
                "Maximum of 100 User login names can be supplied"
            )
        if page_size > 100:
            raise TwitchAttributeException("Maximum number of objects to return is 100")

        params = {
            "after": after,
            "before": before,
            "community_id": community_ids,
            "first": page_size,
            "game_id": game_ids,
            "language": languages,
            "user_id": user_ids,
            "user_login": user_logins,
        }

        return APICursor(
            client_id=self._client_id,
            oauth_token=self._oauth_token,
            path="streams",
            resource=Stream,
            params=params,
        )

    def get_games(self, game_ids=None, names=None):
        if game_ids and len(game_ids) > 100:
            raise TwitchAttributeException("Maximum of 100 Game IDs can be supplied")
        if names and len(names) > 100:
            raise TwitchAttributeException("Maximum of 100 Game names can be supplied")

        params = {
            "id": game_ids,
            "name": names,
        }
        return APIGet(
            client_id=self._client_id,
            oauth_token=self._oauth_token,
            path="games",
            resource=Game,
            params=params,
        ).fetch()

    def get_clips(
        self,
        broadcaster_id=None,
        game_id=None,
        clip_ids=None,
        after=None,
        before=None,
        started_at=None,
        ended_at=None,
        page_size=20,
    ):
        if not broadcaster_id and not clip_ids and not game_id:
            raise TwitchAttributeException(
                "At least one of the following parameters must be provided "
                "[broadcaster_id, clip_ids, game_id]"
            )
        if clip_ids and len(clip_ids) > 100:
            raise TwitchAttributeException("Maximum of 100 Clip IDs can be supplied")
        if page_size > 100:
            raise TwitchAttributeException("Maximum number of objects to return is 100")

        params = {
            "broadcaster_id": broadcaster_id,
            "game_id": game_id,
            "id": clip_ids,
            "after": after,
            "before": before,
            "started_at": started_at,
            "ended_at": ended_at,
        }

        if broadcaster_id or game_id:
            params["first"] = page_size

            return APICursor(
                client_id=self._client_id,
                oauth_token=self._oauth_token,
                path="clips",
                resource=Clip,
                params=params,
            )

        else:
            return APIGet(
                client_id=self._client_id,
                oauth_token=self._oauth_token,
                path="clips",

                resource=Clip,