示例#1
0
    def get_videos(self,
                   channel_id,
                   limit=10,
                   offset=0,
                   broadcast_type=BROADCAST_TYPE_HIGHLIGHT,
                   language=None,
                   sort=VIDEO_SORT_TIME):
        if limit > 100:
            raise TwitchAttributeException(
                'Maximum number of objects returned in one request is 100')

        if broadcast_type not in BROADCAST_TYPES:
            raise TwitchAttributeException(
                'Broadcast type is not valid. Valid values are {}'.format(
                    BROADCAST_TYPES))

        if sort not in VIDEO_SORTS:
            raise TwitchAttributeException(
                'Sort is not valid. Valid values are {}'.format(VIDEO_SORTS))

        params = {
            'limit': limit,
            'offset': offset,
            'broadcast_type': broadcast_type,
            'sort': sort
        }
        if language is not None:
            params['language'] = language
        response = self._request_get('channels/{}/videos'.format(channel_id),
                                     params=params)
        return [Video.construct_from(x) for x in response['videos']]
示例#2
0
    def get_top(self,
                limit=10,
                offset=0,
                game=None,
                period=PERIOD_WEEK,
                broadcast_type=BROADCAST_TYPE_HIGHLIGHT):
        if limit > 100:
            raise TwitchAttributeException(
                'Maximum number of objects returned in one request is 100')
        if period not in PERIODS:
            raise TwitchAttributeException(
                'Period is not valid. Valid values are {}'.format(PERIODS))

        if broadcast_type not in BROADCAST_TYPES:
            raise TwitchAttributeException(
                'Broadcast type is not valid. Valid values are {}'.format(
                    BROADCAST_TYPES))

        params = {
            'limit': limit,
            'offset': offset,
            'game': game,
            'period': period,
            'broadcast_type': ','.join(broadcast_type)
        }

        response = self._request_get('videos/top', params=params)
        return [Video.construct_from(x) for x in response['vods']]
示例#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 {}'.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']]
    def get_posts(self, channel_id, limit=10, cursor=None, comments=5):
        if limit > 100:
            raise TwitchAttributeException(
                'Maximum number of objects returned in one request is 100')
        if comments > 5:
            raise TwitchAttributeException(
                'Maximum number of comments returned in one request is 5')

        params = {'limit': limit, 'cursor': cursor, 'comments': comments}
        response = self._request_get('feed/{}/posts'.format(channel_id),
                                     params=params)
        return [Post.construct_from(x) for x in response['posts']]
示例#5
0
    def get_videos(self, video_ids=None, user_id=None, game_id=None, after=None, before=None,
                   page_size=20, language=None, period=PERIOD_ALL, sort=VIDEO_SORT_TIME,
                   video_type=VIDEO_TYPE_ALL):
        if video_ids and len(video_ids) > 100:
            raise TwitchAttributeException('Maximum of 100 Video IDs can be supplied')

        params = {
            'id': video_ids,
            'user_id': user_id,
            'game_id': game_id,
        }

        if user_id or game_id:
            if page_size > 100:
                raise TwitchAttributeException('Maximum number of objects to return is 100')
            if period not in PERIODS:
                raise TwitchAttributeException(
                    'Invalid value for period. Valid values are {}'.format(PERIODS)
                )
            if sort not in VIDEO_SORTS:
                raise TwitchAttributeException(
                    'Invalid value for sort. Valid values are {}'.format(VIDEO_SORTS)
                )
            if video_type not in VIDEO_TYPES:
                raise TwitchAttributeException(
                    'Invalid value for video_type. Valid values are {}'.format(VIDEO_TYPES)
                )

            params['after'] = after
            params['before'] = before
            params['first'] = page_size
            params['language'] = language
            params['period'] = period
            params['sort'] = sort
            params['type'] = video_type

            return APICursor(
                client_id=self._client_id,
                oauth_token=self._oauth_token,
                path='videos',
                resource=Video,
                params=params
            )
        else:
            return APIGet(
                client_id=self._client_id,
                oauth_token=self._oauth_token,
                path='videos',
                resource=Video,
                params=params
            ).fetch()
示例#6
0
 def get_top(self, limit=10, cursor=None):
     if limit > 100:
         raise TwitchAttributeException(
             'Maximum number of objects returned in one request is 100')
     params = {'limit': limit, 'cursor': cursor}
     response = self._request_get('communities/top', params=params)
     return [Community.construct_from(x) for x in response['communities']]
示例#7
0
    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()
示例#8
0
    def get_featured(self, limit=25, offset=0):
        if limit > 100:
            raise TwitchAttributeException(
                'Maximum number of objects returned in one request is 100')

        params = {'limit': limit, 'offset': offset}
        response = self._request_get('streams/featured', params=params)
        return [Featured.construct_from(x) for x in response['featured']]
示例#9
0
    def get_all(self, limit=10, offset=0):
        if limit > 100:
            raise TwitchAttributeException(
                'Maximum number of objects returned in one request is 100')

        params = {'limit': limit, 'offset': offset}
        response = self._request_get('teams', params=params)
        return [Team.construct_from(x) for x in response['teams']]
示例#10
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 []]
示例#11
0
    def channels(self, query, limit=25, offset=0):
        if limit > 100:
            raise TwitchAttributeException(
                'Maximum number of objects returned in one request is 100')

        params = {'query': query, 'limit': limit, 'offset': offset}
        response = self._request_get('search/channels', params=params)
        return [Channel.construct_from(x) for x in response['channels'] or []]
示例#12
0
 def get_timed_out_users(self, community_id, limit=10, cursor=None):
     if limit > 100:
         raise TwitchAttributeException(
             'Maximum number of objects returned in one request is 100')
     params = {'limit': limit, 'cursor': cursor}
     response = self._request_get(
         'communities/{}/timeouts'.format(community_id), params=params)
     return [User.construct_from(x) for x in response['timed_out_users']]
示例#13
0
    def get_user_block_list(self, user_id, limit=25, offset=0):
        if limit > 100:
            raise TwitchAttributeException(
                'Maximum number of objects returned in one request is 100')

        params = {'limit': limit, 'offset': offset}
        response = self._request_get('users/{}/blocks'.format(user_id),
                                     params=params)
        return [UserBlock.construct_from(x) for x in response['blocks']]
    def get_post(self, channel_id, post_id, comments=5):
        if comments > 5:
            raise TwitchAttributeException(
                'Maximum number of comments returned in one request is 5')

        params = {'comments': comments}
        response = self._request_get('feed/{}/posts/{}'.format(
            channel_id, post_id),
                                     params=params)
        return Post.construct_from(response)
示例#15
0
    def get_followers(self,
                      channel_id,
                      limit=25,
                      offset=0,
                      cursor=None,
                      direction=DIRECTION_DESC):
        if limit > 100:
            raise TwitchAttributeException(
                'Maximum number of objects returned in one request is 100')
        if direction not in DIRECTIONS:
            raise TwitchAttributeException(
                'Direction is not valid. Valid values are {}'.format(
                    DIRECTIONS))

        params = {'limit': limit, 'offset': offset, 'direction': direction}
        if cursor is not None:
            params['cursor'] = cursor
        response = self._request_get('channels/{}/follows'.format(channel_id),
                                     params=params)
        return [Follow.construct_from(x) for x in response['follows']]
示例#16
0
    def get_user_follows(self, after=None, page_size=20, from_id=None, to_id=None):
        if not from_id and not to_id:
            raise TwitchAttributeException('from_id or to_id must be provided.')
        if page_size > 100:
            raise TwitchAttributeException('Maximum number of objects to return is 100')

        params = {
            'after': after,
            'first': page_size,
            'from_id': from_id,
            'to_id': to_id,
        }

        return APICursor(
            client_id=self._client_id,
            oauth_token=self._oauth_token,
            path='users/follows',
            resource=Follow,
            params=params
        )
示例#17
0
 def get_follows(self,
                 user_id,
                 limit=25,
                 offset=0,
                 direction=DIRECTION_DESC,
                 sort_by=USERS_SORT_BY_CREATED_AT):
     if limit > MAX_FOLLOWS_LIMIT:
         raise TwitchAttributeException(
             'Maximum number of objects returned in one request is 100')
     if direction not in DIRECTIONS:
         raise TwitchAttributeException(
             'Direction is not valid. Valid values are {}'.format(
                 DIRECTIONS))
     if sort_by not in USERS_SORT_BY:
         raise TwitchAttributeException(
             'Sort by is not valud. Valid values are {}'.format(
                 USERS_SORT_BY))
     params = {'limit': limit, 'offset': offset, 'direction': direction}
     response = self._request_get(
         'users/{}/follows/channels'.format(user_id), params=params)
     return [Follow.construct_from(x) for x in response['follows']]
    def get_post_comments(self, channel_id, post_id, limit=10, cursor=None):
        if limit > 100:
            raise TwitchAttributeException(
                'Maximum number of objects returned in one request is 100')

        params = {
            'limit': limit,
            'cursor': cursor,
        }
        url = 'feed/{}/posts/{}/comments'.format(channel_id, post_id)
        response = self._request_get(url, params=params)
        return [Comment.construct_from(x) for x in response['comments']]
示例#19
0
    def get_followed_videos(self,
                            limit=10,
                            offset=0,
                            broadcast_type=BROADCAST_TYPE_HIGHLIGHT):
        if limit > 100:
            raise TwitchAttributeException(
                'Maximum number of objects returned in one request is 100')

        if broadcast_type not in BROADCAST_TYPES:
            raise TwitchAttributeException(
                'Broadcast type is not valid. Valid values are {}'.format(
                    BROADCAST_TYPES))

        params = {
            'limit': limit,
            'offset': offset,
            'broadcast_type': broadcast_type
        }

        response = self._request_get('videos/followed', params=params)
        return [Video.construct_from(x) for x in response['videos']]
示例#20
0
    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 Community 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
        )
示例#21
0
    def get_clips(self, broadcaster_id=None, game_id=None, clip_ids=None, after=None, before=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,
        }

        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,
                params=params
            ).fetch()
示例#22
0
 def get_all_follows(self,
                     user_id,
                     direction=DIRECTION_DESC,
                     sort_by=USERS_SORT_BY_CREATED_AT):
     if direction not in DIRECTIONS:
         raise TwitchAttributeException(
             'Direction is not valid. Valid values are {}'.format(
                 DIRECTIONS))
     if sort_by not in USERS_SORT_BY:
         raise TwitchAttributeException(
             'Sort by is not valud. Valid values are {}'.format(
                 USERS_SORT_BY))
     offset = 0
     params = {'limit': MAX_FOLLOWS_LIMIT, 'direction': direction}
     follows = []
     while offset is not None:
         params.update({'offset': offset})
         response = self._request_get(
             'users/{}/follows/channels'.format(user_id), params=params)
         offset = response.get('_offset')
         follows.extend(response['follows'])
     return [Follow.construct_from(x) for x in follows]
示例#23
0
    def get_subscribers(self,
                        channel_id,
                        limit=25,
                        offset=0,
                        direction=DIRECTION_ASC):
        if limit > 100:
            raise TwitchAttributeException(
                'Maximum number of objects returned in one request is 100')
        if direction not in DIRECTIONS:
            raise TwitchAttributeException(
                'Direction is not valid. Valid values are {}'.format(
                    DIRECTIONS))

        params = {
            # 'limit': limit,
            # 'offset': offset,
            # 'direction': direction
        }
        response = self._request_get(
            'channels/{}/subscriptions'.format(channel_id), params=params)
        return [
            Subscription.construct_from(x) for x in response['subscriptions']
        ]
示例#24
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'])
 def get_by_channel(self,
                    channel_id,
                    limit=10,
                    cursor=None,
                    containing_item=None):
     if limit > 100:
         raise TwitchAttributeException(
             'Maximum number of objects returned in one request is 100')
     params = {
         'limit': limit,
         'cursor': cursor,
     }
     if containing_item:
         params['containing_item'] = containing_item
     response = self._request_get(
         'channels/{}/collections'.format(channel_id))
     return [Collection.construct_from(x) for x in response['collections']]
示例#26
0
    def get_top_games(self, after=None, before=None, page_size=20):
        if page_size > 100:
            raise TwitchAttributeException('Maximum number of objects to return is 100')

        params = {
            'after': after,
            'before': before,
            'first': page_size,
        }

        return APICursor(
            client_id=self._client_id,
            oauth_token=self._oauth_token,
            path='games/top',
            resource=Game,
            params=params
        )
示例#27
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']]