Downloading HD content from tv.nrk.no

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

Enjoy!

Tags: ,

113 Responses to “Downloading HD content from tv.nrk.no”

  1. Chris says:

    Great work godztian!

    I really appreciate the work you have put into this. I hope you will publish the script so that others can make use of your work an expertise.

    Thank you, thank you!

  2. Benjamin Smith says:

    Don’t know why PHP gets no respect as a CLI script language on par with python or perl.

  3. Mads says:

    You should make a version for this with libquvi: http://quvi.sourceforge.net/

    By doing this, we could play NRK files directly from mpv/mplayer by URL only. Would be awesome!

  4. cirrus says:

    Why not just write a plugin for livestreamer to stream content from that site ? still great work, thanks brethren https://github.com/chrippa/livestreamer

  5. ingvar says:

    Cirrus,

    Seems like a livstreamer plugin for tv.nrk.no already exists. Enjoy! :-)

    http://livestreamer.tanuki.se/en/latest/plugin_matrix.html#plugin-matrix

    Ingvar

  6. ingvar says:

    Mads, if all you want is streaming, try livestreamer. It does exactly this, and has a plugin for tv.nrk.no.

  7. ingvar says:

    Sorry, mocking PHP is just unavoidable.

  8. Hi everyone, i have developed a little GUI in java (run on all OS) for AdobeHDS.php

    http://grabanymedia.altervista.org/adobehds-php-helper/

    If you want other options please comment on main download page ;)

  9. Peter says:

    Hi
    Method still working? Because I cant find any manifest in debuger :/
    To download the file i must have norwegian ip?

    Thx for answer :)

  10. ingvar says:

    Hi, Peter. This method does still work, as do the scripts linked to in the post. But you need a Norwegian IP, yes.

  11. Peter says:

    Ok thx for answer :) but how i get this link from debuger exatly?

  12. ingvar says:

    Peter, in Firefox, press Ctrl+Shift+K, select “Console” and “Net”. In the search box, enter “manifest”. Reload the page and start the in-browser player. If you don’t get any result, your browser probably selects a non-flash player. Try with curl instead: In a terminal shell, enter something like this: curl http://tv.nrk.no/url/to/the/show/you/want/here | grep manifest

    Ingvar

  13. Ola says:

    Hi there

    AM trying to use this on a Win7 32bit, but cant seem to get it to work. For example where can I get a working PHP for Win7, and how do I set this up? Have tried the GUI and it opens but doesnt download. Am trying to dl the new season of Lilyhammer :)

    Any help would be appreciated

Leave a Reply