Continuing this weeks theme of XSL transforms, and my usual love of multimedia and home automation applications I've decided to release my TV preview scripts. They're very simple, but serve a purpose. Namely, building a web page containing images from each TV station, and describing the programmes. This page is built automatically in the background, so I can idlely channel surf without leaving my web browser. Here's a screenshot of it in action.
The structure is thus:
1. Every morning, at 3.00am, the gettoday.sh script is called which retrieves the days TV listings from bleb.org. This works, as you'd expect, with cron (0 3 * * * steev /my/machine/gettoday.sh).
2. Throughout the day, the tvgrab.sh script is called every five minutes (also through cron) which interfaces with the TV tuner card to grab bbc1.jpg, bbc2.jpg and so on. It also generates the HTML, using the whatsonnow.xsl stylesheet I blogged yesterday to build the textual descriptions.
3. Er, that's it!
gettoday.sh is nothing more adventurous than a series of wget commands to retrieve bbc1.xml, bbc2.xml, itv1.xml and... you get the idea!
tvgrab.sh makes use of the magical v4lctl command that not only lets you set the TV card's tuner, but grab images from it. This magic is encapsulated in the commands:v4lctl setstation $CURRENT_STATIONv4lctl snap jpeg 160x100 $TVDIR/tv_ch$CURRENT_STATION.jpg
The rest of the code is a feature list: the use of a lock file, the directory into which the files will be placed, the "last updated" information, and the layout. All simple. However, the end result is very effective.
There is some question on the legality of re-publishing images from the TV - even if they are 160 pixels wide, and very fuzzy. I am not a lawyer, but since this page is private, and only accessible from my home network, it should consistute fair use.