This one doesn't use BBC data at all!
It uses data from (cue Eric Morecambe style glasses waggling) the
other side. What would Bill Cotton say?
["the other side" is ITV for those of you not familiar with seminal
seventies comedy]
When I looked at the TV Anytime stuff it seemed remarkably
complicated. Many other sources of TV data either seem to be
complicated or lacking in important info (the radio times site has
very poor descriptions for example).
Mine is pretty simple, not as simple as it could be because I've got an
XSLT isshoo. But it's still not hard. ITV have marked their pages up
_quite_ well. And it was nice to get all the data from one place.
Anyway... for those who are interested I've attached my program to
generate a simple HTML file.
I've also attached an xslt that I use to turn it into something more
presentable.
Nic Ferrier
#!/bin/sh
DIRLOC=`dirname $0`
function getdetails
{
while read id url rest
do
echo $id $url
if [ "$id" != "" ]
then
xsltproc --html - $url 2> /dev/null > /tmp/$id.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<span class="detail"><xsl:value-of select="//[EMAIL PROTECTED]'lblBilling']"/></span>
</xsl:template>
</xsl:stylesheet>
EOF
fi
done
}
# Get a listing for a channel on a day
# And then convert it to simple XML (from ITV's HTML)
function transform_listing
{
channel=$1
uri=$2
day=$3
month=$4
year=$5
date=${day}${month}${year}
xsltproc --html --stringparam isodate "${year}${month}${day}" \
- "${uri}&channeldate=${day}/${month}/${year}" > /tmp/listing_${channel}_${date}_$$.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="isodate"/>
<xsl:template match="/">
<div>
<xsl:attribute name="id">
<xsl:choose>
<xsl:when test="//[EMAIL PROTECTED]'lblChannelSelection']">
<xsl:value-of select="//[EMAIL PROTECTED]'lblChannelSelection']"/>
</xsl:when>
<xsl:otherwise>ITV1</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<abbr class="date">
<xsl:attribute name="title"><xsl:value-of select="\$isodate"/></xsl:attribute>
<xsl:value-of select="//[EMAIL PROTECTED]'lblTodaysDate']"/>
</abbr>
<xsl:apply-templates select="//[EMAIL PROTECTED]'TV Listings Shown']" mode="listing-collection"/>
<xsl:apply-templates select="//[EMAIL PROTECTED]'TV Listings']" mode="listing-collection"/>
</div>
</xsl:template>
<xsl:template match="table" mode="listing-collection">
<xsl:apply-templates select="tr[td/@class='ListingsText']" mode="listing"/>
</xsl:template>
<xsl:template match="tr" mode="listing">
<div class="listing">
<span class="time"><xsl:value-of select="substring(td[1], 2)"/></span>
<span class="description"><xsl:value-of select="td[position() > 1]//text()"/></span>
<xsl:variable name="detail" select=".//[EMAIL PROTECTED]'ProgDet']/@href"/>
<xsl:if test="\$detail">
<span class="url" id="{generate-id(\$detail)}">http://www.itv.com/listings/<xsl:value-of select="\$detail"/></span>
</xsl:if>
</div>
</xsl:template>
</xsl:stylesheet>
EOF
# Rip out the uris
# Note that we do this because xsltproc won't retrieve these with the document() function
# If it did we could do everything inside the itvlistings.xslt script
xsltproc - /tmp/listing_${channel}_${date}_$$.xml > /tmp/justuris_$$ <<EOF
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:apply-templates select="//[EMAIL PROTECTED]'url']"/>
</xsl:template>
<xsl:template match="span"><xsl:value-of select="@id"/><xsl:text> </xsl:text><xsl:value-of select="."/><xsl:text>
</xsl:text></xsl:template>
</xsl:stylesheet>
EOF
# Put the detail text into a file named by the id
cat /tmp/justuris_$$ | getdetails
# Merge the details back into the main file
xsltproc - /tmp/listing_${channel}_${date}_$$.xml > /tmp/channels_$$/${channel}_${date}.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<div>
<xsl:copy-of select="/div/@*"/>
<xsl:copy-of select="/div/abbr"/>
<xsl:apply-templates select="/div/[EMAIL PROTECTED]'listing']"/>
</div>
</xsl:template>
<xsl:template match="div">
<div class="listing">
<xsl:copy-of select="span"/>
<xsl:if test="starts-with([EMAIL PROTECTED]'url']/@id, 'id')">
<span class="detail"><xsl:value-of select="document(concat('/tmp/', [EMAIL PROTECTED]'url']/@id, '.xml'))"/></span>
</xsl:if>
</div>
</xsl:template>
</xsl:stylesheet>
EOF
# Make sure the id files have been deleted
rm -f /tmp/id*.xml
}
# Transform the current week's listings
function do_week
{
channel=$1
uri=$2
month=`date "+%m"`
year=`date "+%Y"`
day=`date "+%d"`
# Get the week
for week_day in `cal | grep $day`
do
transform_listing $channel $uri $week_day $month $year
done
}
# For each line of the uri's file do a week's listing
function do_transform
{
while read channel uri rest
do
do_week $channel $uri
done
}
# Main program
mkdir -p /tmp/channels_$$
cat $DIRLOC/channel_uris | do_transform
echo "<channels>" > /tmp/channel_listing_$$.xml
find /tmp/channels_$$ -name "*.xml" | xargs -i_ echo "<channel>_</channel>" >> /tmp/channel_listing_$$.xml
echo "</channels>" >> /tmp/channel_listing_$$.xml
xsltproc - /tmp/channel_listing_$$.xml > all.xml <<EOF
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<div>
<xsl:for-each select="/channels/channel">
<xsl:copy-of select="document(.)"/>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>
EOF
# remove temporary stuff
#rm -rf /tmp/*_$$*
# End
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="trans_date" match="[EMAIL PROTECTED]" use="[EMAIL PROTECTED]'date']/@title"/>
<xsl:template match="/">
<html>
<head>
<title>The Ferrier Family TV Guide</title>
<link rel="stylesheet" href="listings.css" type="text/css"/>
</head>
<body>
<h1>Without it you're just flipping</h1>
<table>
<tr>
<xsl:for-each select="//[EMAIL PROTECTED](. | key('trans_date', [EMAIL PROTECTED]'date']/@title)[1]) = 1]">
<xsl:sort select="[EMAIL PROTECTED]'date']/@title"/>
<td>
<a>
<xsl:attribute name="href">#<xsl:value-of select="[EMAIL PROTECTED]'date']/@title"/></xsl:attribute>
<xsl:value-of select="[EMAIL PROTECTED]'date']//text()"/>
</a>
</td>
</xsl:for-each>
</tr>
</table>
<xsl:for-each select="//[EMAIL PROTECTED](. | key('trans_date', [EMAIL PROTECTED]'date']/@title)[1]) = 1]">
<xsl:sort select="[EMAIL PROTECTED]'date']/@title"/>
<a>
<xsl:attribute name="id"><xsl:value-of select="[EMAIL PROTECTED]'date']/@title"/></xsl:attribute>
<h2><xsl:value-of select="[EMAIL PROTECTED]'date']//text()"/></h2>
</a>
<xsl:for-each select="key('trans_date', [EMAIL PROTECTED]'date']/@title)">
<xsl:apply-templates select="." mode="channel"/>
</xsl:for-each>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template match="[EMAIL PROTECTED]" mode="channel">
<h3><xsl:value-of select="@id"/></h3>
<table>
<xsl:for-each select="[EMAIL PROTECTED]'listing']">
<tr>
<td valign="top">
<a href="#{generate-id(.)}" id="{generate-id(.)}">
<xsl:copy-of select="[EMAIL PROTECTED]'time']"/>
</a>
</td>
<td valign="top">
<a href="#{generate-id(.)}" id="{generate-id(.)}">
<xsl:copy-of select="[EMAIL PROTECTED]'description']"/>
</a>
<xsl:if test="[EMAIL PROTECTED]'detail']">
<br/>
<xsl:copy-of select="[EMAIL PROTECTED]'detail']"/>
</xsl:if>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>