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.

  1. Install iplayer-dl
This bit’s pretty straightforward, the instructions are on the iplayer-dl site linked above.   2. 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:</p> 
<pre><?php $proxy = ""; $dest = "/home/mark/downloads/iplayer";

$cmd = “gnome-terminal -x /usr/bin/iplayer-dl -d $dest -p $proxy {$_GET[‘id’]}”;

header(“Content-Type: text/something”); echo(“#!/bin/bash\n”); echo($cmd);

?> </pre>

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&#8217;s ID or URL from the query string.
  
Note the Content-Type header. I haven&#8217;t actually included the Content-Type I used here, since I&#8217;ve told Firefox to open it in Bash automatically (remember the vulnerability I mentioned?). Suffice to say, I chose something fairly innocuous that I&#8217;m unlikely to ever come across on the web, so I won&#8217;t get weird things suddenly trying to execute in bash. </li> 

  * Displaying a link to the PHP Script
  
    This piece of magic was done with the [Greasemonkey](https://addons.mozilla.org/en-US/firefox/addon/748) Firefox extension, which is well worth a play with, especially if you&#8217;re good with Javascript. Long story short, it lets you define scripts to run automatically after certain pages have loaded, allowing to you edit how they look.
  
    I wrote a script to run on BBC iPlayer&#8217;s episode pages (the pages where the actually video player is displayed). It looks like this:</p> 
    <pre>var dlFlash = document.getElementById('download-air'); dlFlash.innerHTML = '&lt;a href="http://localhost/~mark/iplayer.php?id='+window.location+'" target="_blank"&gt;Download with iplayer-dl&lt;/a&gt;';

</pre>

    Obviously this exact script only works for me. If you did it yourself, you&#8217;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&#8217;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&#8217;s nice and aesthetically pleasing.</li> </li> 
    
      * Click the Link
  
        Clicking the link pops up the usual &#8220;What shall I do with this file?&#8221; 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&#8217;t use application/x-sh as the MIME type, as I didn&#8217;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 &#8220;OK&#8221; each time you wanted to download from iPlayer, you could use this MIME type. </ol> 
    
    And that&#8217;s it! I&#8217;ve now got a handy DRM-free one-click download link on every iPlayer page.