AutoTV
Link |
by
on 2009-11-25 01:34:59 (edited 2009-12-01 00:01:48)
|
I want to share a supremely convenient script I just thought to write. The script will search EZTV's twitter for shows you want to watch. When new content is posted, the script begins to download it automatically. The script can be executed periodically using crontab. For example, I run it every ten minutes, like this: */10 * * * * /usr/bin/php /path/to/AutoTV.phpSimply add whichever shows you like to watch to the $shows array. This script is designed to work with MacOS, but you can edit $tmp and $log for compatibility with any other OS. To schedule a task in windows, see this tutorial. <?php // AutoTV.php require_once 'xml2Array.class.php'; $tmp = "$_ENV[HOME]/Downloads/Temporary.torrent"; $log = "$_ENV[HOME]/Library/Logs/AutoTV.log"; $url = 'http://twitter.com/statuses/user_timeline/37039456.rss'; $shows = array( 'Colbert Report', 'Daily Show', 'Big Bang Theory', 'Mythbusters', 'Dollhouse', 'Numb3rs', 'Dexter', ); $seen = array(); foreach(file($log) as $entry) { $args = preg_split('/ /', $entry); if(strlen($args[2])) $seen[] = $args[2]; } $parser = new xml2Array(); $data = $parser->parse(file_get_contents($url)); $data = $data[0]['children'][0]['children']; foreach($data as $item) { if($item['name'] != 'ITEM') continue; $line = $item['children'][0]['tagData']; if(!preg_match('/eztv_it: (.*) .*? - (http:.*)/', $line, $args)) continue; if(preg_match('/ 720p /', $args[1])) continue; if(in_array($args[2], $seen)) continue; foreach($shows as $show) { if(preg_match("/^$show /", $args[1])) { shell_exec("echo " . escapeShellArg(date('Y-m-d H:i:s') . " $args[2] $args[1]") . " >> $log"); shell_exec("curl -s " . escapeShellArg($args[2]) . " > $tmp"); shell_exec("open $tmp"); sleep(1); break; } } } ?> |