seasonMaint.php 2.7 KB

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