Experimental python script for downloading a stream (which has ended) from ustream.tv
The goal is to automate the process to get the video file for the whole stream in FLV format
This stream is protected by a dumb authentication (enter your name, role, email, phone num)
pip3 install -r requirements.txt
python3 ustream.py
-
get channel id from the page : https://www.ustream.tv/channel/curJSsZFUUu
-
authenticate with dummy input (name, role, email, phone numb.) to get the
hash
field via the url :https://www.ustream.tv/ajax/viewer-registration/save/{channel_id}/channel/{channel_id}.json
-
call the get channel content API (with the auth
hash
) to get the list of video :https://www.ustream.tv/ajax/viewing-experience/channel/{channel_id}/content.json
-
open websocket connection to :
wss://r{8_digit_random}-1-{video_id}-recorded-wss-live.ums.ustream.tv/1/ustream
and send a connect
action with the following parameter :
{
"cmd":"connect",
"args":[
{
"type":"viewer",
"appId":3,
"appVersion":2,
"isOffairRecorded":True,
"referrer": url,
"media": video_id,
"application":"recorded",
"hash":json.dumps(auth["hash"])
}
]
}
Then 3 responses frames are received including one with stream
information which gives chunk url format and list of hashes to download. This includes mp4/segmented
& flv/segmented
. Here we download only flv/segmented
- download all chunk (for this video it's 14XX .flv file of 6 sec.)
- remove FLV headers of all chunk > 0 (eg chunk1 to chunkn excluding the first chunk)
- concatenate all those chunk to the first chunk : 0.flv
- copy the flv file to the specified location
Note that this is for personal use or education purpose only. For other usage, use the official API
Use ffmpeg :
ffmpeg -i stream.flv -codec copy stream.mp4
The MIT License (MIT) Copyright (c) 2017 Bertrand Martel