DISCLAIMER: THIS HACK DOES NOT WORK WITH 40D ANY LONGER
I quite like using the 4oD service from Channel 4, I can watch their programs at a time that suits me without the regular ad breaks on live TV. The adverts appear just before the program starts instead, and although you can skip to the right part of a program once it's playing, you can't fast forward the adverts.
The program is delivered to the 4oD player as a play list for Windows Media Player in the ASX file format. The first few items in the play list are the URLs for adverts, and the last one is the actual TV program. To avoid having to sit through these adverts, I saw there was the potential to to intercept this play list and remove the entries pertaining to advertising.
To achieve this, I made use of the redirect_program feature of the Squid web proxy. In this case, it allows me to tell Squid to fetch the play list from my website rather than directly from Channel 4. I wrote the following Perl script based on the example in the Squid documentation:
#!/usr/bin/perl
use URI::Escape;
$|=1;
while (<>) {
s@(http://vodapp\.grid\.channel4\.com/c4site-web/playlist\.do\?[^ ]*)@"http://www.trollied.org/~blimey/4oD.php?url=" . uri_escape($1)@e;
print;
}
So when the 4oD client requests a play list from the vodapp.grid.channel4.com server, it instead requests the playlist from my website. My website then downloads the desired play list, and does the required filtering using PHP and XSLT.
This PHP, very simply downloads the play list into a DOM document and applies the the required XSLT to it.
<?php
$basename = basename($_SERVER['SCRIPT_NAME'], '.php');
$xslfile = $basename . '.xsl';
$xmlfile = $_GET['url'];
$xml = new DOMDocument;
$xml->load($xmlfile);
$xsl = new DOMDocument;
$xsl->load($xslfile);
$xslProc = new XSLTProcessor();
$xslProc->importStylesheet($xsl);
header('Content-Type: video/x-ms-asf');
$doc = $xslProc->transformToDoc($xml);
echo $doc->saveXML($doc->firstChild);
?>
Here's the XSL, that simply copies everything in the document except for any ENTRY that has a TITLE starting with the word advert.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
omit-xml-declaration="yes"
method="xml"
media-type="video/x-ms-asf"/>
<xsl:template match="/ASX/ENTRY">
<xsl:if test="not(starts-with(TITLE, 'Advert'))">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:template>
<xsl:template match="/ASX/*[name() != 'ENTRY']">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="/">
<ASX VERSION="3.0">
<xsl:apply-templates/>
</ASX>
</xsl:template>
</xsl:stylesheet>