Changeset 183
- Timestamp:
- 10/23/08 20:52:39 (3 months ago)
- Files:
-
- 1 modified
-
hellaworld/branches/autonzb/cron.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
hellaworld/branches/autonzb/cron.php
r180 r183 15 15 $dataset = new XML_Dataset('feeds.xml'); 16 16 17 // Have a look for command-line options. 18 array_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. 23 if ($verbose) 24 unset($args[array_search('-v', $args)]); 25 26 // Flag to track if we did any work. 27 $did_run = FALSE; 28 17 29 // Loop over each feed, parse it, see if the latest episode has changed. 18 30 foreach ($dataset->feed as $feed) { 19 31 $attrs =& $feed->attributes(); 20 32 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); 21 46 $atom = new Atom_Feed($attrs->url); 22 47 $latest = $atom->entry[0]; 23 48 $parsed = nzb::parse($latest->title); 24 49 50 // Is the 1st item newer than the latest we recorded? 25 51 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. 29 56 $nzb_id = end(explode('/', substr($latest->id, 0, -1))); 30 57 … … 36 63 } 37 64 } else { 38 // echo 'Same old. '.$parsed->episode, "\n";65 $verbose AND printf("No new episode for %s (%d)\n", $attrs->name, $parsed->episode); 39 66 } 40 67 } 41 68 69 // Write the data back out. 42 70 $dataset->save(); 71 72 // Check we did some work. 73 if (! $did_run) 74 echo 'Warning: Did not check anything. Are you sure you spelled the show name right?', "\n";
