seasonMaint.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/local/bin/php
  2. <?
  3. set_time_limit(0);
  4. require_once 'includes/main.php';
  5. global $TV_PATH;
  6. $all_series = allSeriesSeasons($TV_PATH);
  7. # Check each series for new seasons listed on TVDB but not locally
  8. foreach ($all_series as $series => $seasons) {
  9. # Long wait between series, to avoid TVDB bans
  10. sleep(rand(20, 40));
  11. # Grab the season parameters
  12. $flags = readFlags($series);
  13. # Respect the "skip" flag
  14. if ($flags['skip']) {
  15. continue;
  16. }
  17. # Grab the TVDB season list
  18. $tvdb_seasons = getTVDBSeasons($flags['tvdb-id'], $flags['tvdb-lid']);
  19. # We only care about "new" seasons -- don't force old seasons into the local tree
  20. $tvdb_max = @max(array_keys($tvdb_seasons));
  21. $local_max = @max(array_keys($seasons));
  22. # If we detect one or more missing seasons
  23. if ($tvdb_max > $local_max) {
  24. # Sanity check
  25. if ($tvdb_max - $local_max > 5) {
  26. echo 'TheTVDB lists ' . $tvdb_max . ' season for ' . $series. ". Skipping...\n";
  27. continue;
  28. }
  29. # Add the seasons
  30. echo $series . "\n";
  31. for ($season = $local_max + 1; $season <= $tvdb_max; $season++) {
  32. echo "\tAdding season: " . $season . "\n";
  33. addSeason($series, $season);
  34. }
  35. }
  36. # Check for multiple monitored seasons in a series
  37. $seasons = findSeasons($series);
  38. $monitored_count = 0;
  39. foreach ($seasons as $season => $status) {
  40. if ($status) {
  41. $monitored_count++;
  42. }
  43. }
  44. if ($monitored_count > 1) {
  45. echo 'Multiple seasons monitored for: ' . $series . "\n";
  46. }
  47. }
  48. ?>