Changeset 183

Show
Ignore:
Timestamp:
10/23/08 20:52:39 (3 months ago)
Author:
drarok
Message:

* Added the ability to manually run checks on certain feeds, and a verbose mode.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • hellaworld/branches/autonzb/cron.php

    r180 r183  
    1515$dataset = new XML_Dataset('feeds.xml'); 
    1616 
     17// Have a look for command-line options. 
     18array_shift($_SERVER['argv']); // Drop the cron.php arg. 
     19$args = array_map('strtolower', $_SERVER['argv']); 
     20$verbose = in_array('-v', $args); 
     21 
     22// Remove the -v arg. 
     23if ($verbose) 
     24        unset($args[array_search('-v', $args)]); 
     25 
     26// Flag to track if we did any work. 
     27$did_run = FALSE; 
     28 
    1729// Loop over each feed, parse it, see if the latest episode has changed. 
    1830foreach ($dataset->feed as $feed) { 
    1931        $attrs =& $feed->attributes(); 
    2032         
     33        // Only fetch the ones specified, if any. 
     34        if ((bool) count($args)) { 
     35                if (! in_array(strtolower($attrs->name), $args)) { 
     36                        $verbose AND printf("Skipping %s\n", $attrs->name); 
     37                        continue; 
     38                }; 
     39        }; 
     40         
     41        // Make a note that we did some work. 
     42        $did_run = TRUE; 
     43         
     44        // Fetch the data from newzbin. 
     45        $verbose AND printf("Fetching feed for %s\n", $attrs->name); 
    2146        $atom = new Atom_Feed($attrs->url); 
    2247        $latest = $atom->entry[0]; 
    2348        $parsed = nzb::parse($latest->title); 
    2449         
     50        // Is the 1st item newer than the latest we recorded? 
    2551        if ($parsed->episode > $attrs->latest_episode) { 
    26                 // There's a new ep!!! 
    27                 echo sprintf('New episode of %s (%s > %s)', 
    28                                 $attrs->name, $parsed->episode, $attrs->latest_episode), "\n"; 
     52                echo sprintf('Queueing new episode of %s (%s)', 
     53                                $attrs->name, $parsed->episode), "\n"; 
     54                 
     55                // Grab the nzb id off the url. 
    2956                $nzb_id = end(explode('/', substr($latest->id, 0, -1))); 
    3057                 
     
    3663                } 
    3764        } else { 
    38 //              echo 'Same old. '.$parsed->episode, "\n"; 
     65                $verbose AND printf("No new episode for %s (%d)\n", $attrs->name, $parsed->episode); 
    3966        } 
    4067} 
    4168 
     69// Write the data back out. 
    4270$dataset->save(); 
     71 
     72// Check we did some work. 
     73if (! $did_run) 
     74        echo 'Warning: Did not check anything. Are you sure you spelled the show name right?', "\n";