Example #1
0
File: models.py Project: bibby/itch
    def _replay_chat(self, start, end):
        caches = [set(), set()]
        cache_index = 0
        while start <= end:
            prev_cache = caches[cache_index]
            cache_index = (cache_index + 1) % 2
            cache = caches[cache_index] = set()

            payload = {
                "video_id": self.id,
                "start": start,
            }

            res = API.get(RECHAT, payload)
            if "errors" in res:
                return

            for message in res.get("data"):
                mid = message.get("id")
                if mid in prev_cache:
                    continue

                cache.add(mid)
                yield message

            start += 30
Example #2
0
File: models.py Project: bibby/itch
    def past_streams(self, cap=None):
        url = "{}/channels/{}/videos"
        url = url.format(KRAKEN, self.name)
        params = {
            "broadcasts": "true",
        }

        read_count = 1
        vods_read = 0
        while read_count:
            if not url:
                return

            res = API.get(url, params)
            videos = res.get("videos", [])
            read_count = len(videos)
            for video in videos:
                yield Video(
                    total=res.get("_total"),
                    **video
                )

                vods_read += 1
                if cap and vods_read >= cap:
                    return
            url = res.get("_links").get("next", None)
Example #3
0
    def _replay_chat(self, start, end):
        caches = [set(), set()]
        cache_index = 0
        while start <= end:
            prev_cache = caches[cache_index]
            cache_index = (cache_index + 1) % 2
            cache = caches[cache_index] = set()

            payload = {
                "video_id": self.id,
                "start": start,
            }

            res = API.get(RECHAT, payload)
            if "errors" in res:
                return

            for message in res.get("data"):
                mid = message.get("id")
                if mid in prev_cache:
                    continue

                cache.add(mid)
                yield message

            start += 30
Example #4
0
 def live_stream(self):
     url = "{}/streams/{}"
     url = url.format(KRAKEN, self.name)
     res = API.get(url)
     stream = res.get("stream", None)
     if stream:
         return Stream(links=res.get("_links"), **stream)
Example #5
0
File: models.py Project: bibby/itch
 def get_chatters(self):
     url = "{}/group/user/{}/chatters"
     url = url.format(TMI, self.name)
     res = API.get(url)
     return Chatters(
         count=res.get("chatter_count"),
         **res.get("chatters")
     )
Example #6
0
File: models.py Project: bibby/itch
 def live_stream(self):
     url = "{}/streams/{}"
     url = url.format(KRAKEN, self.name)
     res = API.get(url)
     stream = res.get("stream", None)
     if stream:
         return Stream(
             links=res.get("_links"),
             **stream
         )
Example #7
0
File: models.py Project: bibby/itch
    def _replay_boundaries(self):
        payload = {
            "video_id": self.id,
            "start": 0,
        }

        res = API.get(RECHAT, payload)
        if "errors" not in res:
            raise Exception("Expected chat replay boundary error message.")

        msg = res.get("errors")[0].get("detail")
        try:
            mat = re.match('-?\d+ is not between (\d+) and (\d+)', msg)
            return tuple(map(int, [mat.group(1), mat.group(2)]))
        except Exception as e:
            logger.warning(msg)
            logger.exception(e)
            raise
Example #8
0
    def _replay_boundaries(self):
        payload = {
            "video_id": self.id,
            "start": 0,
        }

        res = API.get(RECHAT, payload)
        if "errors" not in res:
            raise Exception("Expected chat replay boundary error message.")

        msg = res.get("errors")[0].get("detail")
        try:
            mat = re.match('-?\d+ is not between (\d+) and (\d+)', msg)
            return tuple(map(int, [mat.group(1), mat.group(2)]))
        except Exception as e:
            logger.warning(msg)
            logger.exception(e)
            raise
Example #9
0
    def get_follows(url, cursor=None):
        payload = {}
        read_count = 1
        while read_count:
            if cursor:
                payload["cursor"] = cursor

            res = API.get(url, payload)
            if res:
                follows = res.get("follows", [])
                read_count = len(follows)
                for follow in follows:
                    follow['total'] = res.get('_total')
                    yield follow

                if read_count:
                    cursor = res.get("_cursor")
                    if not cursor:
                        url = res.get("_links").get("next")
Example #10
0
File: models.py Project: bibby/itch
    def get_follows(url, cursor=None):
        payload = {}
        read_count = 1
        while read_count:
            if cursor:
                payload["cursor"] = cursor

            res = API.get(url, payload)
            if res:
                follows = res.get("follows", [])
                read_count = len(follows)
                for follow in follows:
                    follow['total'] = res.get('_total')
                    yield follow

                if read_count:
                    cursor = res.get("_cursor")
                    if not cursor:
                        url = res.get("_links").get("next")
Example #11
0
File: models.py Project: bibby/itch
    def loots_streams(self, limit=None, direction=None):
        url = "{}/search/channels/{}/streams"
        max_streams = LOOTS_MAX_GET
        direction = direction or 'desc'
        if limit:
            max_streams = min(limit, LOOTS_MAX_GET)

        params = {
            "json": json.dumps({
                "offset": 0,
                "limit": max_streams,
                "sort_key": "_t",
                "sort_order": direction.lower()
            })
        }

        url = url.format(LOOTS, self.id)
        res = API.get(url, params)
        for stream in res.get("data", []):
            yield LootsStream(**stream)
Example #12
0
    def loots_streams(self, limit=None, direction=None):
        url = "{}/search/channels/{}/streams"
        max_streams = LOOTS_MAX_GET
        direction = direction or 'desc'
        if limit:
            max_streams = min(limit, LOOTS_MAX_GET)

        params = {
            "json":
            json.dumps({
                "offset": 0,
                "limit": max_streams,
                "sort_key": "_t",
                "sort_order": direction.lower()
            })
        }

        url = url.format(LOOTS, self.id)
        res = API.get(url, params)
        for stream in res.get("data", []):
            yield LootsStream(**stream)
Example #13
0
    def past_streams(self, cap=None):
        url = "{}/channels/{}/videos"
        url = url.format(KRAKEN, self.name)
        params = {
            "broadcasts": "true",
        }

        read_count = 1
        vods_read = 0
        while read_count:
            if not url:
                return

            res = API.get(url, params)
            videos = res.get("videos", [])
            read_count = len(videos)
            for video in videos:
                yield Video(total=res.get("_total"), **video)

                vods_read += 1
                if cap and vods_read >= cap:
                    return
            url = res.get("_links").get("next", None)
Example #14
0
def __set_caching(**kwargs):
    caching = __get_cache(kwargs.get('caching'))
    if caching:
        TwitchAPI.set_caching(caching)
Example #15
0
 def get(id):
     url = '{}/rechat-message/{}'
     url = url.format(RECHAT, id)
     return ChatMessage(**API.get(url))
Example #16
0
File: models.py Project: bibby/itch
 def get(name):
     url = '{}/channels/{}'
     url = url.format(KRAKEN, name.lower().strip())
     return Channel(**API.get(url))
Example #17
0
File: models.py Project: bibby/itch
 def get(vid_id):
     url = '{}/videos/{}'
     url = url.format(KRAKEN, vid_id)
     return Video(**API.get(url))
Example #18
0
File: models.py Project: bibby/itch
 def get(name):
     url = '{}/users/{}'
     url = url.format(KRAKEN, name.lower().strip())
     return User(**API.get(url))
Example #19
0
 def get(vid_id):
     url = '{}/videos/{}'
     url = url.format(KRAKEN, vid_id)
     return Video(**API.get(url))
Example #20
0
 def get(name):
     url = '{}/users/{}'
     url = url.format(KRAKEN, name.lower().strip())
     return User(**API.get(url))
Example #21
0
 def get(name):
     url = '{}/channels/{}'
     url = url.format(KRAKEN, name.lower().strip())
     return Channel(**API.get(url))
Example #22
0
 def get_chatters(self):
     url = "{}/group/user/{}/chatters"
     url = url.format(TMI, self.name)
     res = API.get(url)
     return Chatters(count=res.get("chatter_count"), **res.get("chatters"))
Example #23
0
File: models.py Project: bibby/itch
 def get(id):
     url = '{}/rechat-message/{}'
     url = url.format(RECHAT, id)
     return ChatMessage(**API.get(url))