Downloading past twitch broadcasts in python

6k Views Asked by At

I have been trying to download past broadcasts for a streamer on twitch using python. I found this python code online:

https://gist.github.com/baderj/8340312

However, when I try to call the functions I am getting errors giving me a status 400 message. Unsure if this is the code I want to download the video (as an mp4) or how to use it properly.

And by video I mean something like this as an example: www(dot)twitch.tv/imaqtpie/v/108909385 //note cant put more than 3 links since I don't have 10 reputation

Any tips on how i should go about doing this?

Here's an example of running it in cmd:

python twitch_past_broadcast_downloader.py 108909385

After running it, it gave me this:

Exception API returned 400

This is where i got the information on running it: https://www.johannesbader.ch/2014/01/find-video-url-of-twitch-tv-live-streams-or-past-broadcasts/

2

There are 2 best solutions below

3
On BEST ANSWER

Huh it's not as easy at it seems ... The code you found on this gist is quite old and Twitch has completely changed its API. Now you will need a Client ID to download videos, in order to limit the amount of video you're downloading.

If you want to correct this gist, here are simple steps you can do :

  1. Register an application : Everything is explained here ! Register you app and keep closely your client id.
  2. Change API route : It is no longer '{base}/api/videos/a{id_}' but {base}/kraken/videos/{id_} (not sure about the last one). You will need to change it inside the python code. The doc is here.
  3. Add the client id to the url : As said in the doc, you need to give a header to the request you make, so add a Client-ID: <client_id> header in the request.

And now I think you will need to start debugging a bit, because it is old code :/

I will try myself to do it and I will edit this answer when I'm finished, but try yourself :)

See ya !

EDIT : Mhhh ... It doesn't seem to be possible anyway to download a video with the API :/ I was thinking only links to API changed, but the chunks section of the response from the video url disappeared and Twitch is no longer giving access to raw videos :/

Really sorry I told you to do that, even with the API I think is no longer possible :/

0
On

You can download past broadcasts of Twitch videos with Python library streamlink. You will need OAuth token which you can generate with the command

streamlink --twitch-oauth-authenticate

Download VODs with:

streamlink --twitch-oauth-token <your-oauth-token> https://www.twitch.tv/videos/<VideoID> best -o <your-output-folder>