Пример #1
0
    def streams(self, query, limit=25, offset=0, hls=None):
        if limit > 100:
            raise TwitchAttributeException(
                "Maximum number of objects returned in one request is 100")

        params = {"query": query, "limit": limit, "offset": offset, "hls": hls}
        response = self._request_get("search/streams", params=params)
        return [Stream.construct_from(x) for x in response["streams"] or []]
Пример #2
0
    def streams(self, query, limit=25, offset=0, hls=None):
        if limit > 100:
            raise TwitchAttributeException(
                'Maximum number of objects returned in one request is 100')

        params = {'query': query, 'limit': limit, 'offset': offset, 'hls': hls}
        response = self._request_get('search/streams', params=params)
        return [Stream.construct_from(x) for x in response['streams'] or []]
Пример #3
0
    def get_followed(self, stream_type=STREAM_TYPE_LIVE, limit=25, offset=0):
        if stream_type not in STREAM_TYPES:
            raise TwitchAttributeException(
                'Stream type is not valid. Valid values are %s' % STREAM_TYPES)
        if limit > 100:
            raise TwitchAttributeException(
                'Maximum number of objects returned in one request is 100')

        params = {'stream_type': stream_type, 'limit': limit, 'offset': offset}
        response = self._request_get('streams/followed', params=params)
        return [Stream.construct_from(x) for x in response['streams']]
Пример #4
0
    def get_followed(self, stream_type=STREAM_TYPE_LIVE, limit=25, offset=0):
        if stream_type not in STREAM_TYPES:
            raise TwitchAttributeException(
                "Stream type is not valid. Valid values are {}".format(
                    STREAM_TYPES))
        if limit > 100:
            raise TwitchAttributeException(
                "Maximum number of objects returned in one request is 100")

        params = {"stream_type": stream_type, "limit": limit, "offset": offset}
        response = self._request_get("streams/followed", params=params)
        return [Stream.construct_from(x) for x in response["streams"]]
Пример #5
0
    def get_stream_by_user(self, channel_id, stream_type=STREAM_TYPE_LIVE):
        if stream_type not in STREAM_TYPES:
            raise TwitchAttributeException(
                'Stream type is not valid. Valid values are %s' % STREAM_TYPES)

        params = {
            'stream_type': stream_type,
        }
        response = self._request_get('streams/%s' % channel_id, params=params)

        if not response['stream']:
            return None
        return Stream.construct_from(response['stream'])
Пример #6
0
    def get_stream_by_user(self, channel_id, stream_type=STREAM_TYPE_LIVE):
        if stream_type not in STREAM_TYPES:
            raise TwitchAttributeException(
                "Stream type is not valid. Valid values are {}".format(STREAM_TYPES)
            )

        params = {
            "stream_type": stream_type,
        }
        response = self._request_get("streams/{}".format(channel_id), params=params)

        if not response["stream"]:
            return None
        return Stream.construct_from(response["stream"])
Пример #7
0
    def get_live_streams(self,
                         channel=None,
                         game=None,
                         language=None,
                         stream_type=STREAM_TYPE_LIVE,
                         limit=25,
                         offset=0):
        if limit > 100:
            raise TwitchAttributeException(
                'Maximum number of objects returned in one request is 100')

        params = {'stream_type': stream_type, 'limit': limit, 'offset': offset}
        if channel is not None:
            params['channel'] = channel
        if game is not None:
            params['game'] = game
        if language is not None:
            params['language'] = language
        response = self._request_get('streams', params=params)
        return [Stream.construct_from(x) for x in response['streams']]
Пример #8
0
    def get_live_streams(
        self,
        channel=None,
        game=None,
        language=None,
        stream_type=STREAM_TYPE_LIVE,
        limit=25,
        offset=0,
    ):
        if limit > 100:
            raise TwitchAttributeException(
                "Maximum number of objects returned in one request is 100")

        params = {"stream_type": stream_type, "limit": limit, "offset": offset}
        if channel is not None:
            params["channel"] = channel
        if game is not None:
            params["game"] = game
        if language is not None:
            params["language"] = language
        response = self._request_get("streams", params=params)
        return [Stream.construct_from(x) for x in response["streams"]]
Пример #9
0
        "channels": ["channel123"],
    }
}
CONFIG_WITH_OAUTH = {
    sensor.DOMAIN: {
        "platform": "twitch",
        CONF_CLIENT_ID: "1234",
        "channels": ["channel123"],
        "token": "9876",
    }
}

USER_ID = User({"id": 123, "display_name": "channel123", "logo": "logo.png"})
STREAM_OBJECT_ONLINE = Stream(
    {
        "channel": {"game": "Good Game", "status": "Title"},
        "preview": {"medium": "stream-medium.png"},
    }
)
CHANNEL_OBJECT = Channel({"followers": 42, "views": 24})
OAUTH_USER_ID = User({"id": 987})
SUB_ACTIVE = Subscription({"created_at": "2020-01-20T21:22:42", "is_gift": False})
FOLLOW_ACTIVE = Follow({"created_at": "2020-01-20T21:22:42"})


async def test_init(hass):
    """Test initial config."""

    channels = MagicMock()
    channels.get_by_id.return_value = CHANNEL_OBJECT
    streams = MagicMock()
    streams.get_stream_by_user.return_value = None
Пример #10
0
    def get_streams_in_community(self, community_id):
        response = self._request_get(
            'streams?community_id={}'.format(community_id))

        return [Stream.construct_from(x) for x in response['streams']]