Bobbie Smulders Freelance Software Developer

Reverse engineering the KPN IPTV recording system


A while back, I visited my parents to replace their current digital cable setup with an IPTV setup. This had some great advantages, as the set-top boxes only needed network cables instead of coax cables. I used power line communication so that I didn’t have to lay any cable. In the end, every TV-set in the house was able to watch high-definition television, and every iOS and Android device was capable of watching standard-definition television.

The provider (KPN) has an interesting approach to recording television. When you record a certain program, whether it’s currently on or in the future, you don’t record anything on the set-top box. It is recorded on their servers, and if you want to play it back, you can stream it from their servers to your set-top box. This complicated process is all brilliantly hidden from the user. The advantage of such a system is that a recording on one device can be played back on all devices in the house. Every set-top box can display a list of recorded programs that is retrieved from the server. Another advantage is that you can start a recording from the provider’s website or their mobile application, even when you’re not at home. And you don’t need to have your set-top box running 24/7, which saves power.

But there was one rather large issue with scheduling a recording…

It was not possible to automatically record recurring programs. A program that is repeated weekly can not be automatically recorded. You have to schedule every recording separately. And because the EPG (programming guide) only shows the next three days, you can’t schedule the recording for the next few weeks.

That is why I built the application called KPN Herhaald Opnemen (KPN Repeated Recording). The application checks the EPG hourly, looks if there are any series that I am following, and if so, schedules a recording.

The first step to building this application was reverse-engineering the iTV Online website, the website where you can view the EPG and schedule a recording. Luckily, the website was written entirely in jQuery, without any obfuscation. The underlying web-service was also trivial to figure out. I only needed to intercept the JSON pages (and the corresponding HTTP requests) that were requested on the website. After doing some logical reasoning, I figured out most of the API just by clicking a button on the website and seeing what kind of HTTP requests were done.

After writing a very simple proof of concept to see if everything would work, I designed a database to store the recording requests (the TV-shows that I’m watching), a PHP wrapper for the API and a PHP class that checks the database for recording requests, which are then looked-up on the EPG using the API wrapper. Recording requests can be confided to a certain day, time-schedule and channel (e.g. only look for this show on Friday evening on HBO). This is all kicked off by a cron-job to automate everything.

To add and remove entries from the database, I first used Arrest MySQL to make the MySQL database accessible to JavaScript by using a REST interface. I then developed a simple jQuery Mobile application to view the recording requests in the database, to remove them and to add a new one.

The end result is that it is now possible to grab the iPad from the coffee table, add a recording request for a certain TV-show and have that TV-show automatically recorded when it pops up in the EPG. It’s a true “Set it and Forget it” way of working.

A small note: The software was written in English, but the commentary, documentation and GitHub pages are all written in Dutch. Because this IPTV service is mainly used by Dutch citizens and because I wanted to attract Dutch software-developers, I deviated from my principle to only develop software in English.