#!/usr/bin/php
<?php
/*
Script by Ed Jellard - http://www.jellard.co.uk
Jan 2010
*/
$user="ed_mythtv";
$password="xxxx";
while (
true) {
    
$current file_get_contents("http://localhost:6544");
    
$current substr($currentstrpos($current"Encoder Status"));
    
$current substr($current0strpos($current"</div>"));
    
$parts explode("\n"$current);
    
$lastProgs unserialize(file_get_contents("old.ser"));
    foreach (
$parts as $key => $part) {
        
$part str_replace("\n"""$part);
        if ((
strpos($part"is recording") > 0) or (strpos($part"is watching") > 0)){
            
$program substr($partstrpos($part"'") + 1strrpos($part"'") - strpos($part"'") - 1);
            
$programmes[] = $program;
            if (!
in_array($program$lastProgs)) {
                echo 
$program."\n";
                if (
strpos($part"and is recording") > 0) {
                    `
wget -t 1 -q -O twitter.xml --user=$user --password=$password --post-data="status=MythTV recording: $program" https://twitter.com/statuses/update.xml`; 
                } else {
                    `
wget -t 1 -q -O twitter.xml --user=$user --password=$password --post-data="status=MythTV watching: $program" https://twitter.com/statuses/update.xml`; 
                }
            } 
        } 
    }
    
$fp fopen("old.ser""w");
    
fwrite($fpserialize($programmes));
    
fclose($fp);
    
usleep(6000000);
}
?>