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? Any and all thoughts are appreciated!
EDIT: I'm not sure why my app engine tag was removed, but this would be using app engine.
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? Any and all thoughts are appreciated!
EDIT: I'm not sure why my app engine tag was removed, but this would be using app engine.
It looks like Twitch provides an API (documentation here) that provides a way to get that info. A very simple example of getting the feed would be:
This will dump all of the info, which you can then parse with a JSON library (XML looks to be available too). Looks like the value returns empty if the stream isn't live (haven't tested this much at all, nor have I read anything :) ). Hope this helps!
Since all answers are actually outdated as of 2020-05-02, i'll give it a shot. You now are required to register a developer application (I believe), and now you must use an endpoint that requires a user-id instead of a username (as they can change).
See https://dev.twitch.tv/docs/v5/reference/users
and https://dev.twitch.tv/docs/v5/reference/streams
First you'll need to Register an application
From that you'll need to get your
Client-ID
.The one in this example is not a real
RocketDonkey's fine answer seems to be outdated by now, so I'm posting an updated answer for people like me who stumble across this SO-question with google. You can check the status of the user EXAMPLEUSER by parsing
The entry "stream":null will tell you that the user if offline, if that user exists. Here is a small Python script which you can use on the commandline that will print 0 for user online, 1 for user offline and 2 for user not found.
Use the twitch api with your client_id as a parameter, then parse the json:
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:
Yes. You can use Twitch API call
https://api.twitch.tv/kraken/streams/YOUR_CHANNEL_NAME
and parse result to check if it's live.The below function returns a streamID if the channel is live, else returns -1.