I’m a big fan of BBC iPlayer. However, I’m not such a big fan of DRM-encumbered downloads, and the flash player doesn’t work on my netbook. For this reason, I use iplayer-dl, a clever little ruby app that pretends it’s an iPhone, and lets you download DRM-free versions on the videos.
The downside of this iplayer-dl is that it requires you to manually copy and paste the URL or ID of the video into the command line. I thought it would be handy if there was a link on the iPlayer page to download an episode through iplayer-dl.
After about an hour of messing, I was successful. The steps I followed are below. Please note that this is a VERY hacky solution, and probably isn’t the best way to do it, nor do I recommend anyone else does it this way. One stage of it potentially leaves your system vulnerable to attack.
- Install iplayer-dl
This bit’s pretty straightforward, the instructions are on the iplayer-dl site linked above.
- PHP Script
I run a local web server on my netbook for web development purposes. I created a script called iplayer.php in my public_html folder with code similar to the following:
This code essentially generates a shell script which will open a gnome-terminal window (it could equally use Konsole, xterm etc), and runs the iplayer-dl with the specified parameters. It gets the show’s ID or URL from the query string.
Note the Content-Type header. I haven’t actually included the Content-Type I used here, since I’ve told Firefox to open it in Bash automatically (remember the vulnerability I mentioned?). Suffice to say, I chose something fairly innocuous that I’m unlikely to ever come across on the web, so I won’t get weird things suddenly trying to execute in bash.
- Displaying a link to the PHP Script
I wrote a script to run on BBC iPlayer’s episode pages (the pages where the actually video player is displayed). It looks like this:
var dlFlash = document.getElementById('download-air'); dlFlash.innerHTML = '<a href="http://localhost/~mark/iplayer.php?id='+window.location+'" target="_blank">Download with iplayer-dl</a>';
Obviously this exact script only works for me. If you did it yourself, you’d have to change the href to the location of your iplayer.php. Essentially all this script does it replace the normal download link on the page (Which tries download the video in BBC’s Adobe AIR-based client) with a link to my PHP script (effectively, to the shell script generated by the PHP). By a happy accident, it even keeps the icon and background of the download button, so it’s nice and aesthetically pleasing.
- Click the Link
Clicking the link pops up the usual “What shall I do with this file?” dialogue. Now, I want as little faff as possible, so I set it to run with bash, and to do it every time without asking. This associates the MIME type I chose earlier with Bash, so in future all scripts produced from these links will open the download instantly. For this reason I didn’t use application/x-sh as the MIME type, as I didn’t want to accidentally click a link to a real shell script on another page and have it execute automatically! If you were happy to select bash and click “OK” each time you wanted to download from iPlayer, you could use this MIME type.
And that’s it! I’ve now got a handy DRM-free one-click download link on every iPlayer page.