How to detect start/stop of a broadcast?


Currently one feature of a chat bot I programmed is that it records chat lines to a database. I’d like to introduce a little bit more organization to this database by splitting up chat into “broadcasts”. My goal is, when a broadcast ‘starts’, to create a new entry in "broadcast’ database and start adding any messages from the twitch chat to this entry “broadcast#45”. When a broadcast ends, create a new entry in “broadcast” database “offline#45” where all chat messages after a broadcast are appended to. and repeat. To do this, I need some sort of marker for when a broadcast starts/ends.

The poor man’s solution I’m currently using is broadcast start = if the chat line contains the string “x viewers have resubscribed while you were away” and broadcast end = hosting someone else. This isn’t always reliable though, considering there may be a day where no resubscriptions happen between broadcasting sessions, or the streamer doesn’t host after a broadcast.

I also know that I can use this to determine what a broadcast status, which includes the broadcast start time. I imagine I could check this every minute or so.

So to the expert developers on here: how would you recommend solving this problem?

1 Like

By polling

Thats the only official way to do it right now.

1 Like

Also keep in mind that depending how frequently you poll the endpoint Barry suggested you could end up getting one response saying a stream is online, then the next time get an offline response because you just happened to hit a slightly older cache.

So you might want to make sure you don’t poll too frequently, or set up a counter so that once a stream is live it only gets set as offline if you receive x consecutive offline responses from the API (a counter like this can also help if a stream is having connection issues and is going and down a lot, as an app can still count it as a single broadcast unless it’s down for an extended period of time).

1 Like

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