Greasemonkey Script. Play BBC iPlayer via XBMC
The BBC iPlayer plugin for XBMC works really well. In my experience, It’s much more stable (if less fancy looking) than the official Wii application. The only downside is that as with most XBMC video plugins, the navigation can be a little clunky.
I’ve written a small Greasemonkey script which adds a ‘Send to XBMC’ button to any iPlayer episode page. The script has a couple of requirements but it’s fairly easy to get up and running in a matter of minutes. When clicked, the script will invoke the iPlayer plugin on the target XBMC and start playing the relevant episode.
This works for both TV and Radio streams.


Requirements
The first requirement is that obviously you’ll need an XBMC Media Center which is network accessible and can access the Internet. The second glaringly obviously requirement is that you need to have the BBC iPlayer XBMC plugin installed. This greasemonkey script assumes the default plugin folder name of ‘iPlayer’.
If you haven’t enabled the Web Server in your XBMC Network Settings, you will need to do this. The script works by making an HTTP request to the XBMC HTTP API in order to invoke the iPlayer plugin.
There’s a single configuration option for the host name or IP address of your XBMC. This is configurable via a User Script Command (Hint: right click the Greasemonkey status bar icon)
Teh codez
// ==UserScript==
// @name BBC IPlayer Send to XBMC
// @namespace http://userscripts.org/users/218421
// @include http://www.bbc.co.uk/iplayer/episode/*
// ==/UserScript==
GM_registerMenuCommand("Change XBMC Host for IPlayer",set_xbmc_host);
if (GM_getValue("XBMC_HOST")==undefined) {
set_xbmc_host;
}
function hasClass(ele,cls) {
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
if (hasClass(ele,cls)) {
var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
ele.className=ele.className.replace(reg,' ');
}
}
getpid = function(){
return pid = document.location.toString().split('/')[5];
}
play = function(e){
e.preventDefault();
var xbmc_host = GM_getValue("XBMC_HOST");
var i = new Image();
i.src = 'http://'+xbmc_host+'/xbmcCmds/xbmcHttp?command=PlayFile(plugin://video/IPlayer/?pid='+getpid()+')';
}
init = function(){
var tools = document.getElementById('episodeTools');
var list = tools.getElementsByTagName('ul')[0];
removeClass(list,'no-badge');
var a = document.createElement('a');
a.setAttribute('href','#');
a.addEventListener('click', play, false);
var p = document.createElement('p');
p.setAttribute('class','hd-link');
p.appendChild(a);
a.style.backgroundImage = "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJUAAAAaCAAAAACbL0GeAAAACXBIWXMAAAsTAAALEwEAmpwYAAADGGlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjaY2BgnuDo4uTKJMDAUFBUUuQe5BgZERmlwH6egY2BmYGBgYGBITG5uMAxIMCHgYGBIS8/L5UBFTAyMHy7xsDIwMDAcFnX0cXJlYE0wJpcUFTCwMBwgIGBwSgltTiZgYHhCwMDQ3p5SUEJAwNjDAMDg0hSdkEJAwNjAQMDg0h2SJAzAwNjCwMDE09JakUJAwMDg3N+QWVRZnpGiYKhpaWlgmNKflKqQnBlcUlqbrGCZ15yflFBflFiSWoKAwMD1A4GBgYGXpf8EgX3xMw8BSMDVQYqg4jIKAUICxE+CDEESC4tKoMHJQODAIMCgwGDA0MAQyJDPcMChqMMbxjFGV0YSxlXMN5jEmMKYprAdIFZmDmSeSHzGxZLlg6WW6x6rK2s99gs2aaxfWMPZ9/NocTRxfGFM5HzApcj1xZuTe4FPFI8U3mFeCfxCfNN45fhXyygI7BD0FXwilCq0A/hXhEVkb2i4aJfxCaJG4lfkaiQlJM8JpUvLS19QqZMVl32llyfvIv8H4WtioVKekpvldeqFKiaqP5UO6jepRGqqaT5QeuA9iSdVF0rPUG9V/pHDBYY1hrFGNuayJsym740u2C+02KJ5QSrOutcmzjbQDtXe2sHY0cdJzVnJRcFV3k3BXdlD3VPXS8Tbxsfd99gvwT//ID6wIlBS4N3hVwMfRnOFCEXaRUVEV0RMzN2T9yDBLZE3aSw5IaUNak30zkyLDIzs+ZmX8xlz7PPryjYVPiuWLskq3RV2ZsK/cqSql01jLVedVPrHzbqNdU0n22VaytsP9op3VXUfbpXta+x/+5Em0mzJ/+dGj/t8AyNmf2zvs9JmHt6vvmCpYtEF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KpLxgLZTVsGDTG933zxteYeM48HrhHWG7MotBXPzBm9sQ9xhjj+/7vS6iu/Hp1058NuP868B6Onm1uWpquAOcs/HJfc8M07+hLncqk1/6yKwr4nop7z4T0zrJs//DynffOn6g4buwqtpirbyxmQdlVByqxgOmpqw1WWWqG8MW+kdgNzdZfpdQFRr1f2CDF+jEEJcaxsoFUSThquIJNjVVNjc1WvmrKcYEZ1yWCDk8DYS21oUEHWLpaauwiGiqEd9agpQk7m7Bz/GwrOt5CqWO0C+P28r8BALszeAljb82XAAAAAElFTkSuQmCC')";
tools.appendChild(p);
}
setTimeout(init,2000);
function set_xbmc_host() {
GM_setValue("XBMC_HOST",window.prompt("Enter your XBMC IP address", "192.168.0."));
}
The script can be obtained from userscripts.org – http://userscripts.org/scripts/show/85753
Posted in Web


September 11th, 2010 at 3:15 am
This script is excellent and works a treat in greasemonkey under firefox. Unfortunately I can’t get it working in Chrome, although the script will install and it will add the button to the relevant iplayer pages, I can find no way to edit a user script command under chrome. Also manually altering the script.js file has only led to me breaking it as I know no javascript. would you be able to provide some instruction?
September 11th, 2010 at 3:14 pm
Yeah currently it’ll only work under Greasemonkey because of it’s Greasemonkey API dependence. I hadn’t even considered other browsers to be honest. I’m fairly sure that just removed all the GM specific stuff and hardcoding your xbmc host (on line 33) would make it work perfectly in Chrome though. I might spend some time implementing this in a more cross browser way.
September 12th, 2010 at 12:28 am
Just to be clear, Chrome supports Greasemonkey add-ons, http://blog.chromium.org/2010/02/40000-more-extensions.html although apparently some things are not supported such as using user commands, to edit the script file. Unless I simply just can’t find how to do so.
Regards,
September 30th, 2010 at 2:22 am
Hi,
what build of XBMC are you using ? I’m having some problems with the Dharma Betas… the playback starts then stops immediately.