seasonMaint.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/usr/local/bin/php
  2. <?
  3. set_time_limit(0);
  4. require_once 'includes/main.php';
  5. $all_series = allSeriesSeasons(TV_PATH, false);
  6. $old_series = array();
  7. $added_seasons = array();
  8. $multi_seasons = array();
  9. $empty_seasons = array();
  10. # Set this to "false" for offline testing
  11. #$ENABLE_TVDB = false;
  12. # Check each series for new seasons listed on TVDB but not locally
  13. foreach ($all_series as $series => $seasons) {
  14. # Grab the season parameters
  15. $flags = readFlags($series);
  16. # Respect the "skip" flag
  17. if ($flags['skip']) {
  18. continue;
  19. }
  20. # Grab the TVDB season list
  21. $tvdb_seasons = getTVDBSeasons($flags['tvdb-id'], $flags['tvdb-lid']);
  22. # We only care about "new" seasons -- don't force old seasons into the local tree
  23. $tvdb_max = @max(array_keys($tvdb_seasons));
  24. $local_max = @max(array_keys($seasons));
  25. # Sanity checks
  26. if (!is_array($tvdb_seasons) || $tvdb_max < 1) {
  27. echo 'Unable to retrive reasonable season data from TheTVDB for ' . $series. ". Skipping...\n";
  28. continue;
  29. }
  30. if ($tvdb_max - $local_max > 5) {
  31. echo 'TheTVDB lists ' . $tvdb_max . ' season for ' . $series. ". Skipping...\n";
  32. continue;
  33. }
  34. # Add missing seasons
  35. for ($season = $local_max + 1; $season <= $tvdb_max; $season++) {
  36. $added_seasons[] = $series . ' - Season ' . $season;
  37. addSeason($series, $season);
  38. }
  39. # Check for multiple monitored seasons in a series
  40. $seasons = findSeasons($series);
  41. $monitored_count = 0;
  42. foreach ($seasons as $season => $status) {
  43. if ($status) {
  44. $monitored_count++;
  45. }
  46. }
  47. if ($monitored_count > 1) {
  48. $multi_seasons[] = $series;
  49. }
  50. # Check for seasons with no episodes
  51. foreach ($seasons as $season => $status) {
  52. if ($status) {
  53. $episodes = findEpisodes($series, $season);
  54. if (count($episodes) < 1) {
  55. $empty_seasons[] = $series . ' - Season ' . $season;
  56. }
  57. }
  58. }
  59. # Check for "old" but still monitored series
  60. foreach ($seasons as $season => $status) {
  61. if ($status) {
  62. if ($flags['mtime'] < time() - $MAX_AGE) {
  63. $old_series[] = $series;
  64. break;
  65. }
  66. }
  67. }
  68. }
  69. # Display series with multiple monitored seasons
  70. if (count($multi_seasons) > 0) {
  71. echo "\n";
  72. echo "Series with multiple monitored seasons:\n";
  73. foreach ($multi_seasons as $val) {
  74. echo "\t" . $val . "\n";
  75. }
  76. }
  77. # Display added seasons
  78. if (count($added_seasons) > 0) {
  79. echo "\n";
  80. echo "Added seasons:\n";
  81. foreach ($added_seasons as $val) {
  82. echo "\t" . $val . "\n";
  83. }
  84. }
  85. # Display "old" series
  86. if (count($old_series) > 0) {
  87. echo "\n";
  88. echo "Monitored series with no recent updates:\n";
  89. foreach ($old_series as $val) {
  90. echo "\t" . $val . "\n";
  91. }
  92. }
  93. # Display empty seasons
  94. if (count($empty_seasons) > 0) {
  95. echo "\n";
  96. echo "Monitored seasons with no episodes:\n";
  97. foreach ($empty_seasons as $val) {
  98. echo "\t" . $val . "\n";
  99. }
  100. }
  101. # Display "old" seasons
  102. ?>