twitch.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:Bonfire 作者: Phxntxm 项目源码 文件源码
def channel_online(self, twitch_url: str):
        # Check a specific channel's data, and get the response in text format
        channel = re.search("(?<=twitch.tv/)(.*)", twitch_url).group(1)
        url = "https://api.twitch.tv/kraken/streams/{}".format(channel)

        response = await utils.request(url, payload=self.params)

        # For some reason Twitch's API call is not reliable, sometimes it returns stream as None
        # That is what we're checking specifically, sometimes it doesn't exist in the returned JSON at all
        # Sometimes it returns something that cannot be decoded with JSON (which means we'll get None back)
        # In either error case, just assume they're offline, the next check will most likely work
        try:
            return response['stream'] is not None
        except (KeyError, TypeError):
            return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号