Fun with XMLTV

XMLTV is a free substitute for Digiguide (supplying personalised TV listings), for those who don't mind a bit of tinkering. Having already installed Fink, Fink Commander and Perl, here are some steps for using XMLTV on OS X:

Download XMLTV, and install it as normal using 'perl, make, make test, make install'.
If any dependencies are missing, use sudo perl -MCPAN -eshell to start CPAN, then 'install whatever' to install the required modules.
Use Fink Commander to install libxslt and latex2html.

Inside '/library/webserver/cgi-executables', make a directory called 'tv'. Inside that directory, make a directory called 'imdb'. Inside that directory, make a directory called 'lists'. Use Get Info to set read/write permissions for all users on the 'tv' directory and all enclosed items.

Copy tv_pick.cgi,, xmltv.dtd and prog2ical.xsl into the 'tv' directory. Use chmod 755 tv_pick.cgi to set the permissions for the scripts.

cd to '/library/webserver/cgi-executables/tv/imdb/lists' and run these commands to download the IMDB data:
curl -o actors.list.gz
curl -o directors.list.gz
curl -o actresses.list.gz
curl -o movies.list.gz

cd to ' /library/webserver/cgi-executables/tv' and run tv_imdb --imdbdir imdb --prepStage all

Run tv_grab_uk (or the version for your country) to make sure it works - it might ask for some channel configuration.

Run the following command to grab the programme data and munge it around a bit:
tv_grab_uk | tv_sort | tv_extractinfo_en | tv_sort | tv_grep --on-after now | tv_imdb --imdbdir imdb --output tv.xml

In a web browser, run http://localhost/cgi-bin/tv/tv_pick.cgi and set viewing preferences for each programme to never, no, yes or always. Now you have an xml file containing your personal viewing list for the next few days.

To make a text file for printing, run tv_to_text --output towatch.txt towatch.xml
To make a PDF file for printing, you should be able to run tv_to_latex towatch.xml | latex | dvips | ps2pdf - towatch.pdf, but it doesn't work for me.
To make each channel into an iCal-subscribable calendar, run xsltproc prog2ical.xsl towatch.xml. Then make a directory called 'tv' in '/library/webserver/documents' and run cp *.ics /library/webserver/documents/tv/. In iCal, select Calendar>Subscribe, then enter http://localhost/tv/FILENAME.ics where FILENAME is the name of one of the .ics files you just made. Repeat for the other channels as necessary.