Update: I’ve made some helper scripts, including a script to download subtitles. See http://users.linpro.no/ingvar/nrk/.
NRK (Norwegian Broadcasting Corporation) recently deployed their new net TV broadcasting solution, tv.nrk.no, with, among other nice features, HD content. For Linux users, regretfully, the player is implemented in Flash.
Generally, Linux users would like more control. Here’s how to download video content from tv.nrk.no (and probably other sites using the same technology), and play it offline on Linux.
The flash player uses AdobeHDS for streaming fragments via Akamai’s CDN. The magic consists of three steps: Getting the manifest describing the fragments. Downloading the fragments. Merging the fragments into a playable file.
First for downloading and merging. This is all done by one single magic script, AdobeHDS.php, that can be downloaded from https://github.com/K-S-V/Scripts. All praise to KSV who made the script. By some strange reason, the script is written in PHP, so you need to have that installed as well.
Put the script somewhere where it’s easy to find it, like in ~/bin, and you’re good to go. Now you just need to get the manifest url.
To get the manifest, use a recent version of Mozilla Firefox. Surf to http://tv.nrk.no/, and hit Ctrl+Shift+K to enable Firefox’ built-in website debugger. In the filter box, enter manifest and press enter. Find your video in the web browser panel, and start it. Let it play for a second or five, and the URL to the manifest should appear in the debugger window. Click on the match and copy the url.
Now just call the merge script with the manifest url. Add the delete option to get rid of the fragments after merging. Use quotes to avoid problems with special characters like ‘?’ and ‘&’.
php ~/bin/AdobeHDS.php --quality high --delete --manifest 'http://someserver.akamaihd.net/path/to/something.mp4.csmil/manifest.f4m?hdcore=someversion&g=somesessionkey' KSV Adobe HDS Downloader Downloading fragment 1116/1116 Found 1116 fragments Joined 1116 fragments in 205.07 seconds Finished
The result will be a video file that you can play with any recent media player, like totem or mplayer (given you have the right codecs installed, of course). NRK seems to favour h264 video with aac audio in the flv (“flash video”) container.
Now for subtitles. I made a small perl script that builds .srt files from NRK’s html subtitle format. Download the script and place it somewhere handy, like in ~/bin, and run chmod +x on it to make it executable. You will need the following cpan modules: DateTime::Precise, Text::Iconv, and HTML::TokeParser::Simple.
Go back to your tv.nrk.no browser window, and in the debug filter, search for “subtitles” (without quotes). Reload the page if necessary. Click on the match, and copy the url. Then run the script with the subtitles url in the same directory as where you downloaded the film. The result should work for example with mplayer or totem. Example:
perl ~/bin/nrk-subtitles http://tv.nrk.no/programsubtitles/koif53005208 > subtitles.srt mplayer -sub subtitles.srt film.flv