Is There Any Way To Check if a Twitch Stream Is Live Using Python?

后端 未结 7 486
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 18:44

I\'m just wondering if there is any way to write a python script to check to see if a twitch.tv stream is live?

I\'m not sure why my app engine tag was removed, but this

7条回答
  •  温柔的废话
    2021-02-04 19:26

    Use the twitch api with your client_id as a parameter, then parse the json:

    https://api.twitch.tv/kraken/streams/massansc?client_id=XXXXXXX
    

    Twitch Client Id is explained here: https://dev.twitch.tv/docs#client-id, you need to register a developer application: https://www.twitch.tv/kraken/oauth2/clients/new

    Example:

    import requests
    import json
    
    def is_live_stream(streamer_name, client_id):
    
        twitch_api_stream_url = "https://api.twitch.tv/kraken/streams/" \
                        + streamer_name + "?client_id=" + client_id
    
        streamer_html = requests.get(twitch_api_stream_url)
        streamer = json.loads(streamer_html.content)
    
        return streamer["stream"] is not None
    

提交回复
热议问题