Downloading a Livestream Streaming Video

Livestream is designed to stream videos, but specifically disallows the saving of live streams. Fortunately, if the data is allowed to reach your computer, be it by stream or otherwise, you can find a way to save it. This is how you can save Livestream stream data. The following may need a certain amount of technical knowledge to execute.

1) Find your stream

For this example I’ll use today’s stream of Manhattan Neighborhood Network’s public access television broadcast. The url for this particular stream looks like this: http://livestream.com/mnn5/events/4846282

Load this website in your favorite browser.

2) Find the playlist url

Open the developer console in your browser and type window.config.event.stream_info.m3u8_url. The console will print out the url of the M3U playlist that describes the stream data location.

MNN Livestream

In my case this url looks like this:

http://api.new.livestream.com/accounts/17251372/events/4846282/broadcasts/118258527.m3u8?dw=100&hdnea=st=1459832413~exp=1459834213~acl=/i/17251372_4846282_59828693_1@366744/*~hmac=d0d1040ff694dc7e9583f15bf13bb4e430bb5bae79a2119d7294b84e1ba8688a

Copy the url into your browser. Your browser will start to download a file called master.m3u

3) Find the other playlist urls

Open the file you just downloaded, master.m3u in your favorite text editor. You should see text like this:

#EXTM3U  
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=6096000,RESOLUTION=1920x1080,CODECS="avc1.77.30, mp4a.40.2"
http://livestream-f.akamaihd.net/i/17251372_4846282_59828693_1@366744/index_3096_av-p.m3u8?sd=10&dw=100&rebase=on

Each line that doesn’t start with a # is the url of another M3U playlist that will finally contain your video data.

Copy the above url into your browser and another file named index_3096_av-p.m3u will download.

4) Find the MPEG data urls

Again, open the downloaded file in your favorite text editor, and it should look like this:

#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-ALLOW-CACHE:YES
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:145983339
#EXTINF:10.000,
http://livestream-f.akamaihd.net/i/17251372_4846282_59828693_1@366744/segment145983339_3096_av-p.ts?sd=10&dw=100&rebase=on
#EXTINF:10.000,
http://livestream-f.akamaihd.net/i/17251372_4846282_59828693_1@366744/segment145983340_3096_av-p.ts?sd=10&dw=100&rebase=on

Again, each line that doesn’t start with a # is a url, except this time they each point to 10-second long MPEG-2 Transport Stream video files.

If you copy-paste each of these links into your browser you’ll download your video 10 seconds at a time.

5) Download the MPEG data

If there are too many video urls to download by hand you can use the following bash script to download the entire sequence of video:

for i in `seq 145983339 145983340`; do
  wget --load-cookies cookies.txt "http://livestream-f.akamaihd.net/i/17251372_4846282_59643958_1@366744/segment${i}_3096_av-p.ts?sd=10";
done

Be sure to replace the numbers in your seq call and the url in wget to match the values from the M3U

6) Merge the data

After all the small video files are saved on your filesystem all you need to do is join them into a single video file. Simply cating the files together works just fine:

cat *.ts* > full_video.ts

7) Play the video

At this point, the generated file full_video.ts can be opened with any good video player like VLC

8) Optional: Compress the video

If the file you’ve downloaded is larger than you’d like, you can re-encode the video with better compression using, for example, Handbrake