Twitch VOD Chat Downloader
Yet another Twitch Chat downloader...
There are dozens of applications out there that allow for the download of Twitch Chat, but actually finding a good one would've taken longer then building my own! As my only desire was the actually download of the chat messages, I quickly threw this together with Python. Starting off with actually traversing the newly discovered internal Twitch comments API:
- https://api.twitch.tv/v5/videos/VOD_ID/comments?content_offset_seconds=0
- https://api.twitch.tv/v5/videos/VOD_ID/comments?cursor=CURSOR
If you're familiar you can probably guess how these are used: the first request is made with content_offset_seconds=0
, which returns a lovely JSON object with all the chat messages in the comments
key, and the next cursor returned under the _next
key - until you reach the end, at which point there is no _next
key.
Traverse this linked-list of cursors is exactly what the script does!
Is it working...?
This was a difficult question to tell as the script did take some time, not just because of the volume of requests, but also thanks to a delay I added to avoid getting rate limited or such.
So I threw in a message that would print out how far into the video the script had gotten so far. I would've liked to make this into a percentage, or invert it into telling how much time was remaining, but both of those would require getting the VOD duration, and that would be more work, so I didn't!
Only for VODs
Unfortunately when it's downloading the chat of a live stream there's no difference between being up to date and being at the end of a vod.
Now you may think this is an easy fix, simply keep polling for new messages until it eventually stops returning messages, and you would be right, this is an easy fix. One I had no interesting in implementing as I had no desire to download chat live, so was perfectly satisfied having to wait until the stream had finished to start up the script.
Make it Useful
Now my purpose for this was to save the data for usage in my #100Devs Asset Manager, but I'd feel bad if I didn't make this project somewhat useful on it's own, so I replicated my querying logic from said asset manager into here under it's own search
script.
I've already written about my improvements to these very terminal queries if you'd like to read more.