Query category change in "real time"

Hi everyone,

I’m currently recording her streams for a streamer. To do this, I ask every 15 seconds whether the stream is online. Now, as soon as the streamer changes the category from Just Chatting to a game, for example, I would like to automatically set a marker with the game as a description. Now it should be possible to write a message in the chat with my Python script and this set the marker. However, I have to ask which category is set or whether it has been changed. I would like to do this in “real time”, however, since the marker is otherwise offset by up to 15 seconds, as with my other script. I use these 15 seconds because I don’t want to exceed the request limit on Twitch. Is there perhaps a better way to record the set category or changes to the category?

I am currently working purely with Python and would prefer this language. But if it is only possible with someone else, it would be good if you can help me directly with snippets.

Thanks in advance.

The API uses caching, so polling faster than once a minute may not only be wasteful, but polling too fast can actually result in errors where one request may hit a new cache server, then a subsequent request hit a stale cache that still has old data.

The most responsive method to get changes is by using EventSub, as this allows you to subscribe to channel.update type for that channel and receive notifications whenever the channel changes category or title. While there still may be some very minor delay due to caching and processing this is as close as you can get to real-time.

To use EventSub with the webhook transport method you would need to use a library that runs a webserver so you can listen for the incoming notifications on Twitch, and it must be over SSL, so you can either run that server yourself in your app and get a domain/cert for HTTPS, or there are many services out there than can handle the domain and cert stuff for you and forward messages to your app.

1 Like

Thank you for this information. This is something completely new for me and if I understand it correctly, is it not only feasible with Python, but does Javascript need it right? That would be a new language that I would have to learn.

Any language that can listen for incoming HTTPS requests can use EventSub.

This means that Python can do it (although I’m not experienced with that language so unsure what the best HTTPS server lib woudl be). Javascript can do it, a popular NodeJS module for handling the whole webserver side of things being Express which is in many tutorials and guides.

Another option is to use cloud services such as AWS API Gateway and AWS Lambda, so that takes care of the whole web server side of things for you, and you can write the logic inside Lambda functions in a huge range of languages that could then make the stream markers you need to make.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.