Skip to content

bertrandmartel/ustream-dl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Download stream from ustream.tv

CircleCI License

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)

Usage

pip3 install -r requirements.txt
python3 ustream.py

Call Flow

processing

link to this diagram

Process

  • 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

Convert the flv output to mp4

Use ffmpeg :

ffmpeg -i stream.flv -codec copy stream.mp4

References

License

The MIT License (MIT) Copyright (c) 2017 Bertrand Martel

About

Experimental python script for downloading a stream (which has ended) from ustream.tv

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages