TV Calendar Howto¶
The purpose of this document is to explain how to generate a calendar file in the iCal format containing television listings. The calendar will be constructed on Linux, and can be listed either by channel or by show. PLEASE NOTE: This was a fun weekend hacking project. It’s lashed together with various Linux program and a little perl and bash scripting. Don’t take it too seriously.
Programs and Files¶
You’ll need the programs and files in the following list.
Make sure you have perl installed. Zap2xml uses a number of perl modules from CPAN, notably Compress:Zlib and LWP:UserAgent from libwww. You can install these by running ‘perl -MCPAN -e shell’ then ‘install ‘. More information is on the zap2xml site.
In order to use zap2xml, you need to create an account with Zap2it and set it up as noted on the zap2xml site. That is, perform the steps under ‘Setup’. When you run
zap2xml -p firstname.lastname@example.org -p yourpassword
you will download several files, then end up with an xmltv listing named xmltv.xml. I also placed my most used options, including the username, password, and number of days to get in the ~/.zap2xmlrc configuration file.
After a pretty extensive google search I found one person that had a method for changing xmltv files into iCal calendar files. Their website had, unfortunately, dissapeared into the digital ether so I used archive.org’s wayback machine to get the file they used to do it and I’ve mirrored it on my site.
The prog2ical.xsl file was originally intended to create complete channel listings. At first that was great, but it makes for really big calendars and I really don’t care that ‘Blind Date’ is on WCCB when all I watch on that channel is Football. So with absolutely no previous experience with xsltproc I set about tracking shows instead of channels. It could be better, but hey, it gets the job done. I would be interested in making a few other versions of prog2ical.xsl; for example, one that could track all movies (programme entries with episode-num beginning with MV).
Anyway, to create a calendar put xmltv.xml (downloaded using zap2xml), xmltv.dtd (from the xmltv checkout link above), and my modified prog2ical.xsl in a directory. Then run:
xsltproc --stringparam show YOURSHOW \ --stringparam timezone YOUR_TZ \ prog2ical.xsl xmltv.xml
where YOURSHOW is part of the show title you want to list,YOUR_TZ is your timezone (such as US-Eastern), and the result will be YOURSHOW.ics created in the current directory. You can, for example, get all of the Stargate listings in Stargate.ics with:
xsltproc --stringparam show Stargate \ --stringparam timezone US-Eastern \ prog2ical.xsl xmltv.xml
Note that this will get Stargate SG-1, Stargate Atlantis, and the Stargate movie if it should happen to be playing. Now the Stargate.ics file can be loaded up in the Mozilla calendar through ‘File->Open Calendar File...’
A little weirdness (spaces and unicode)¶
Spaces are special characters. To pass them into a program from the shell, they usually have to be escaped or quoted or otherwise handled. In the case of xsltproc, they must be Unicode spaces. Rather than deal with character encoding at the shell level, I’ve opted to do a little search and replace in the new prog2ical.xsl file, using the ‘+’ character to represent a space. As an example, I keep track of NBA Basketball games. In the listing, the title for these programmes is appropriately ‘NBA Basketball’. I get those listings with
xsltproc --stringparam show NBA+Basketball \ --stringparam timezone US-Eastern \ prog2ical.xsl xmltv.xml
The resulting output file will contain a unicode space and be named NBA%20Basketball, which is easy enough to rename, replacing the %20 with an underscore.