Wednesday, 15 August 2007

Control the BBC iPlayer

When the BBC recently opened up their iPlayer to more beta testers I signed up and got an invite quite quickly. I've been playing with it for a week or so now and it has been great to catch up with old episodes of Doctor Who which are currently showing on BBC 3!

The programmes are downloaded using the Kontiki Delivery Management System. This is a peer-to-peer system and this is causing some users to complain quite vocally on the iPlayer messages boards. The problem is that rather than downloading TV programmes directly from the BBC each user is actually downloading shows from other users of the system. The delivery manager starts with Windows and cannot easily be turned off. This means that once you have downloaded a single TV show the software will continue to use your broadband connection to send the show to other iPlayer users. If not monitored this could cause users with a capped monthly download limit to quickly exceed their monthly allowance.

Knowing how the system works I'm quite happy to allow it to use a small amount of my bandwidth to provide the shows I've downloaded to other users. I did, however, want to install the iPlayer on my laptop so that I can catch up on TV when I'm away and this presents me with a problem. My laptop is often connected to networks where I don't pay the broadband bill or where peer-to-peer software is not allowed. So I needed a simple way of controlling the player.

Note that I'm not saying that everyone should stop uploading the TV shows they have downloaded. If they did the service would stop working properly and I would be unhappy. Rather I'm offering a solution for those people, like me, who have a genuine need to be able to limit the software's ability to upload data.

The iPlayer message boards are littered with people suggesting ways to stop the iPlayer using your bandwidth but they all involve manually stopping the software, something I could easily forget to do. So being an inquisitive software engineer I've had a think and a little bit of tinkering later and I have a totally transparent solution to the problem. I think that this solution is OK within the Terms and Conditions you agree to when installing the iPlayer as Term 15 states that "When you use the BBC iPlayer library you shall not have the option to 'switch off' the peer-to-peer functionality". As the only time I use the iPlayer is when it is open and running then there should be no problems with stopping the peer-to-peer functionality service when I have choosen to exit the iPlayer interface. However, I will not be held responsible for your use of this solutuion.

For those of you who simply want to regain control of your computer you can download the solution and instructions without reading any further. If however you are interested to see how the solution works then read on.

Firstly it's important to know that the iPlayer consists of two parts: the interface and a background service that actually controls the downloading and uploading of TV shows. We can easily make sure the user interface does not start with Windows from the iPlayer preferences. The second half of the problem is ensuring that the background service only runs when you have the iPlayer interface open.

The background service which handles the downloading and uploading of the TV shows is called KService. There are two parts to ensuring that it only runs when we want it to: making sure it does not run when Windows starts and stopping it when we exit the iPlayer. We can manage all of this from a command line, so we are going to write an old style batch file to implement this.

I'll show you the whole batch file first, then I'll explain what it does:

sc config KService start= demand
start /wait KHost.exe %*
net stop KService

OK so lets take the file a line at a time:

  1. this line configures the KService so that it only starts when it is needed. In theory we only need to do this once but we will do it every time we start the iPlayer just to ensure that it has not been reset to automatic.

  2. this line starts the KHost application, which is the iPlayer interface, and then waits for it to be closed by the user. This will continue to wait until the user chooses to exit the application by right clicking on the icon in the system tray and choosing "Exit". The %* at the end of the line means pass on any command line parameters the batch file had been given to the KHost application.

  3. by the time we get to the last line we know that the user has finished using the iPlayer so we stop the KService which stops the software from uploading or downloading any more data.

So save this as KHost.bat in the iPlayer installation directory alongside the real KHost.exe (by default this will be "C:\Program Files\Kontiki"). Now from a command prompt we can run the batch file and pass in the same arguments as the shortcut on the start menu uses and iPlayer runs correctly. Now this may seem like we have fixed the problem, but there is one thing left.

If you are browsing the list of TV shows that can be downloaded without the local application already running then it will be started as needed. From what I can tell it runs the KHost application with some different arguments to correctly embed it and then communicates with the running KHost process. To get our batch file to mimic this behaviour we have to be a little more clever and turn the batch file into a proper Windows application to replace KHost.

Firstly we need to move the existing KHost.exe file somewhere new as we will still need it. I choose to create an subdirectory called orig and put it in there. Now we also need to change the batch file so that it can find KHost in the new location. So we now have a new version of the batch file:

sc config KService start= demand
start /wait orig\KHost.exe %*
net stop KService

Now we just need to compile this batch file into an executable. For this we use an existing compiler. Simply load the batch file we have built into the compiler tweak the options as you see fit (I checked both boxes but didn't bother with an icon) and then hit build and out will pop a executable version of the batch file named KHost.exe. Thats it, everything is now finished. Assuming you have followed the instructions properly the iPlayer should work exactly as it did before, but now the downloading and uploading will only take place when you choose to have the iPlayer loaded and will stop as soon as you choose to exit the interface.

So I can now safetly install the iPlayer on my laptop and not worry about what it's doing in the background when connected to networks on which I'm not allowed or don't want to run peer-to-peer software.

I'd like to stress that if you can you do not use this solution because if everyone stopped sharing the TV shows they had downloaded then the iPlayer would become useless -- something I do not want to see happen.
16 August 2007 at 12:11 , kerrala said...

Hi Mark

I'll give this a go and let you know how I am getting on.

Will this also work for Channel 4 player?


16 August 2007 at 14:09 , Mark said...

Hi James,

I haven't tried it with the Channel 4 player. Although as it simply wraps the KHost process ensuring that KService is started and stopped at the same time, then I assume it will work with both the Channel 4 and Sky software as well,


18 August 2007 at 13:24 , Jeffrey said...

Hi Mark
Thanks for the explanation!

I've followed your instructions, but iPlayer now refuses to start. An error message asks me to install v2.0.50727 of .NET Framework.

I have put the original KHost.exe file back, and iPlayer works as normal. I suppose I shall just use Task Manager to close KHost and KService when I close iPlayer.



18 August 2007 at 15:57 , Mark said...


Sorry you had a problem. The application does require .NET it's just that I forgot to mention it as most people already have it installed on Windows XP. It's worth installing .NET as lots of programs now require one version or another of it. You can download version 2.0 from Microsoft.


18 August 2007 at 17:56 , Jeffrey said...



Did as you recommended re NET, then followed your original suggestions....KHost and KService both close when exiting iPlayer via the System Tray.

Thanks again for your help.


21 September 2007 at 15:59 , mike2R said...

This was what I was looking for, thanks for taking the trouble!

25 October 2007 at 07:45 , FoxyLoxy said...

Sorry, 10 out of 10 for cheek, but this is not really worth bothering with. The first time the BBC put a new point release of their Kontiki implementation on their download servers, your little exe will get overwritten.
On the other hand, one day soon, said point release will include the tweaked Kontiki that is single-core friendly, and you won't need this fudge anyway.
In any case, the ability to switch off background uploads is already in the latest release.
Oh, and BTW, installing the whole of dot bloody NET to let you use a fudge to get around the bad behaviour of one poorly configured service is NUTS.

25 October 2007 at 14:14 , Mark said...

FoxyLoxy, sorry you didn't find this solution useful.

Yes you are right a point release of Kontiki does undo the changes but it's not hard to redo them again.

Also I never meant it to be a long term solution to the problem, it was just a quick hack to make controlling the iPlayer easier, saving people having to manually issuing the commands to stop the service.

As for installing .NET, many people will already have this installed as it's now in use by many different applications not just this one.


25 October 2007 at 14:34 , FoxyLoxy said...

Fair enough! Hope I didn't sound too negative.

When I read what you'd done I thought it was a really good wheeze, actually; I was a bit miffed because I hadn't thought of a bat file compiled as an exe myself.

Having to install the NET bloat is a shame, all the same. I was alarmed when installing the 4oD client for comparative testing (to iPlayer) to find that it downloads over 20Mb of NET crud anyway!

I may have to accept compromises from time to time, but bloated ones really take the biscuit.


25 October 2007 at 17:50 , Mark said...

Yeah, software bloat is one of my pet hates. I'm a software engineer so I do try and keep mine to a reasonable size. On this occasion though I used someone else's batch file compiler.

I didn't even notice the .NET requirement initially as I already had installed it with some other software.

As for 4OD, comparatively I'd say it is about the same, although the addition of the archive (especially given that a lot of it is free at the moment) is a nice addition that I hope we see on iPlayer at some point in the future.

13 December 2007 at 20:03 , Chris said...

I have just found your page moments after monkey-engineering my own idea. Don't know if you're interested but my version uses VBS. Instead of replacing the KHost exe it just acts as a launcher, so circumvents the update overwrite problems that are bound to arise. I can send you a copy of my VBS code if you like, it launches KService, waits for this to start then launches KHost with the required iPlayer parameters. It also has a nice GUI showing the user when the sevice is starting. The only thing I haven't added yet is a KService stopper when the program is quit, but i'm sure it will be easy to add.
E-mail me is you're interested (chris.pipe.07(at)googlemail(dot)com),

5 January 2008 at 16:38 , Strongbow24 said...

foxy wrote "In any case, the ability to switch off background uploads is already in the latest release"

I got the iplayer 3 days ago and I'm intrigued to know where this function is - because KService is running on my pc constantly

5 January 2008 at 16:44 , Mark said...

Hi strongbow24,

The function is there (it's the "Allow Programmes to be shared when you exit Download Manager"), however, like you I'm not sure if it actually does anything.

KService continues to run all the time, so I'm assuming that when KHost isn't running (this provides the GUI) KService doesn't upload, although I haven't been able to confirm this, so I still use my solution to ensure it gets shut off when I want it to.


8 January 2008 at 16:03 , Stephanie said...


It looks like iPlayer is going to team up with Xbox 360 - so in a few months you will be able to have TV on demand through your games console!

Broadband Genie

6 February 2008 at 12:06 , Graeme Coates said...

>The function is there (it's the
>"Allow Programmes to be shared when
>you exit Download Manager"),
>however, like you I'm not sure if it
>actually does anything.

Indeed - it does nothing. If you exit the Download Manager, Kservice still runs, and looking at network traffic using Wireshark, it is still sapping your upstream bandwidth and uploading programmes to others.

Thanks for the batch file - this looks like the way I will have to go.. :-/

4 April 2008 at 14:12 , mark.davey said...

Hi, Forget controlling iPlayer, I can't even install it. I keep getting an error trying to access C:\Program Files\Kontiki\KHost.exe - the problem - I don't have that directory. I have full admin rights, but it keeps failing. Any ideas?

18 January 2009 at 17:01 , exKiwi said...

Another option for controlling sharing is detailed on this guy's blog-

I would suggest sticking to his earlier version for thime being though as the version 2 seems rather buggy. I've just reverted!

4 May 2010 at 19:54 , Walter said...

Hi Mark,

You created this fix in 2007, and it's now 2010. Before I download iPlayer for the first time, does this fix still work?


4 May 2010 at 20:17 , Mark said...

Hi Walter, no the fix doesn't work anymore, but, you don't actually need it anymore.

If you just want to download the Windows Media Video files you don't need to install any software to use the iPlayer (these are the files under More Downloads).

If you want to use the main download link then this uses new software which doesn't (as far as I know) use the Kontiki P2P software.

I assume it is still P2P based (I don't actually have the iPlayer software installed as I always just use the WMV downloads) but I know after the initial outcry the BBC added an option to limit the bandwidth used when you didn't have the software open.

Hope that helps.

5 May 2010 at 11:17 , exKiwi said...

To the best of my knowledge there is no PtoP involved in the more recent BBC iPlayer desktop. Additionally there are now some FREE bits of s/w out there which allow you to d/l both audio and video (EVEN in HD!)Google ipdl14 and StreamTransport! Enjoy!!

5 May 2010 at 11:23 , Mark said...

Thanks exKiwi, it's nice to know they finally removed the rather annoying P2P component of iPlayer. As I say I don't use their software as I juse use the Windows Media downloads

Post a Comment