tirsdag den 2. oktober 2012

downloading video's from dr.dk

Intro

Some time ago I was contacted by my sister, who lives in Canada, with a request.
She would like to show her kids some danish cartoons.
Quite a lot of these can actually be streamed for free in Denmark  because they are made by Danmarks Radio (DR), and are paid for by TV-tax/media-license in Denmark that nearly everyone has to pay.

It's not really the topic of the entry to explain it, but it shot it goes a little like this:
  • Do you own a tv (does not matter if it's connected)? if yes: PAY
  • Do you own a cellphone with WAP (or a smartphone)? if yes: PAY
  • Do you have access to the internet? if yes: PAY
  • Do you live in a cave, with no friends, no real life? if so: You don't have to pay
    • Exception(s):
      • Do you own a radio? if yes: PAY
Ok, I'm being mean here, and I am actually gladly paying 2200 dkr. pr year (thats 380$ or 295€), because they make some good commercial free TV and radio programs.

You talked about downloading tv-shows, and now you're talking about fee's and taxes?
Yes, sorry.

The thing is that DR is forced, like many others, to only display their content to citizens in Denmark.
Since I live in Denmark I thought I'd just download those shows, and share them with her. Problem solved.

And here is (finally) how I did it.

How DR streams it's media

First up, the link to DR's TV-library is here: http://dr.dk/tv

If you are outside of DK, you might not see all the content.
They too, are using Geo IP'ing - if you want to overcome this, use VPN, or get the direct link to the media-content (or do both for best performance - at least I sometimes have problems streaming netflix movies from the US over VPN (Overplay)).
On a side-note: Yeah. netflix is FINALLY coming to Denmark in October, THANK YOU (and only days after that HBO said they would offer something for the european nordic market as well). Suddenly thay all seem to want to catch up. I just hope it's not overpriced, and a subset of the US version (which I sadly kinda know it will be already).

DR finally uses a flash player (before they used a crappy Windows mediaplayer plugin), so now everyone (windows, mac and linux) can join in and see what they paid for. Sadly this also makes it a little more troublesome to get the direct link.

I've found a show that needs downloding (another request):
and clicking on the show, brings up the player:
and it is indeed flash.


Getting the media link(s)

I've tried several of the downloadhelpers / youtube downloaders but none of them seem to be able to find the links for the media.
Luckily there are other ways.

Using info the the player

The player has a built-in console, you can start by pressing ctrl-k.
It should look something like this:

You need to be very fast on the keys, because it only prints the information in the beginning, and the flash element needs to have focus first (if one could introduce a delay between the page loading and the media starting it would be very helpful).
On the above screenshot, I only got the last lines, but it's enough.

Strike that. Each time it buffers, it prints the info again (see the timestamp):

You'll need the info, so keep it open.

Using the source-code

If you can't get to the console, you can read the info from the site source code + javescript codes sent back and fourth.

You need yourself a proper browser (firefox with firebug, or chrome). Because we need to see what the javascripts are sending back and forth.
Turn on firebug in firefox, or developer tools in chrome to start.
Now open/reload the media link.

In the source code, look for a "rtmp://" link: rtmp://vod-prio2.gss.dr.dk:

In the botton pane, go to Network.
I found the request in there somewhere; can't remember how exactly anymore (and maybe they changed it :-/)

Update: Just search for it

A commenter just noted that you can just search for it, from dr.dk's serach box.
Just include "rtmp" as a search keyword.

This finds a ressourceId page in the search results, with all the relevant information.
Here an example (http://www.dr.dk/handlers/GetResource.ashx?id=1320340):
{"resourceId":1320340,"name":"Forbrydelsen III (9:10) Synstolkning","mediaType":"Video","restrictedToDenmark":false,"downloadable":false,"geofilterId":0,"publish":null,"expire":null,"links":[{"qualityId":3416809,"uri":"rtmp:\/\/vod.dr.dk\/cms\/mp4:CMS\/Resources\/dr.dk\/NETTV\/DR1\/2012\/11\/12642391-87bf-4dee-b35d-5fec187a3cdd\/Forbrydelsen-III--9-10--Synsto_5c68a152fa1b441eb23c932307e9f943.mp4?ID=1320340","linkType":"Streaming","fileType":"mp4","bitrateKbps":1127,"width":854,"height":480},{"qualityId":3416810,"uri":"rtmp:\/\/vod.dr.dk\/cms\/mp4:CMS\/Resources\/dr.dk\/NETTV\/DR1\/2012\/11\/12642391-87bf-4dee-b35d-5fec187a3cdd\/Forbrydelsen-III--9-10--Synsto_5c68a152fa1b441eb23c932307e9f943_1.mp4?ID=1320340","linkType":"Streaming","fileType":"mp4","bitrateKbps":562,"width":640,"height":360},{"qualityId":3416811,"uri":"rtmp:\/\/vod.dr.dk\/cms\/mp4:CMS\/Resources\/dr.dk\/NETTV\/DR1\/2012\/11\/12642391-87bf-4dee-b35d-5fec187a3cdd\/Forbrydelsen-III--9-10--Synsto_5c68a152fa1b441eb23c932307e9f943_2.mp4?ID=1320340","linkType":"Streaming","fileType":"mp4","bitrateKbps":248,"width":416,"height":234},{"qualityId":3416812,"uri":"rtmp:\/\/vod.dr.dk\/cms\/mp4:CMS\/Resources\/dr.dk\/NETTV\/DR1\/2012\/11\/12642391-87bf-4dee-b35d-5fec187a3cdd\/Forbrydelsen-III--9-10--Synsto_5c68a152fa1b441eb23c932307e9f943_3.mp4?ID=1320340","linkType":"Streaming","fileType":"mp4","bitrateKbps":122,"width":416,"height":234}],"chapters":[],"productionNumber":null,"postingGuid":"{b4fa025e-b022-44f2-8df7-03624df6f889}","images":[],"durationInMilliseconds":3525000,"site":null,"broadcastType":"Program","runningOrder":null,"postingTitle":null,"postingTeaser":null}
This shows all the needed info.
Thanks for the update. It is much easier then the ways I found.
Hopefully. they'll keep indexing these GetResource pages :-)

Downloading the video


Using linux/rtmpdump


Next we need a linux machine, or at least rtmpdump:


I've already installed rtmpdump, so in the above, I just run it.
The parameters are:
  • -r  rtmp://vod-prio2.gss.dr.dk/cms
    • This is the server address or url
  • -y mp4:CMS/Resources/dr.dk/NETTV/DR2/2012/09/44dbf1d8-4af3-42f4-8b08-92932922e4c7/aa7a95ca4dc641dcae6be4cd63817ed2_564.mp4?ID=1237625
    • this is the actual stream
  • -o test.mp4
    • This is the desired output filename, in this case test.mp4. Select wantever you want.
  • -V
    • this is optional, and gives you debugging output. Very useful, if it dosen't work.
In the console output above, the -r and -y options are mashed together, but from my example you should be able to see where to spilt it.


It's then start downloading the media...
Once done, it will return you to the prompt again, saying "download complete".

Using windows/vlc

Sorry. I can't find a way to set the playpath in vlc.

What the hell happend to blogspot?

Hmm... long time no see, and I see that blogspot has gotten a new name, design and even decided to rename the address of my blog.

Thanks for doing something I did not ask for, or want :-(

Well to be fair, the old address still works, but it now redirects.
The new design is ok, and who am I to stand in the way of progress (after all I don't use it very often)?
The new name is perhaps the worst of the three. blogger.... what was wrong with blogspot? I liked it.

Ok, I sound like an old man, which I am not, so I', just going to shut up, and move on to what I really needed/wanted to do here.... write something useful for other people, and my own reference.