ソースを参照

More checks, including some guidance on aged and empty series/seasons

Zachary Kotlarek 13 年 前
親
コミット
d4eb43d6f3
3 ファイル変更、100 行追加、17 行削除
  1. 1 0
      web/includes/config.php
  2. 17 0
      web/includes/series.php
  3. 82 17
      web/seasonMaint.php

+ 1 - 0
web/includes/config.php

@@ -6,5 +6,6 @@ $EXISTS_FILES  = array('no_quality_checks', 'more_number_formats', 'skip');
 $CONTENT_FILES = array('must_match', 'search_name');
 $TVDB_URL      = 'http://thetvdb.com/?tab=series';
 $TVDB_LANG_ID  = 7;
+$MAX_AGE       = 86400 * 90;
 
 ?>

+ 17 - 0
web/includes/series.php

@@ -63,6 +63,23 @@ function readFlags($series) {
 	}
 	$path = seriesPath($series);
 
+	# Find the most recent mtime in the series directory
+	$flags['mtime'] = filemtime($path);
+	$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
+	foreach($objects as $name => $object) {
+
+		# Skip junk
+		if (isJunk($name)) {
+			continue;
+		}
+
+		# Track the most recent mtime
+		$mtime = filemtime($name);
+		if ($mtime > $flags['mtime']) {
+			$flags['mtime'] = $mtime;
+		}
+	}
+
 	# Look for all the exists files
 	foreach ($EXISTS_FILES as $name) {
 		$flags[ $name ] = false;

+ 82 - 17
web/seasonMaint.php

@@ -1,17 +1,24 @@
 #!/usr/local/bin/php
 <?
 
+$DEBUG = false;
 set_time_limit(0);
 require_once 'includes/main.php';
 
 global $TV_PATH;
 $all_series = allSeriesSeasons($TV_PATH);
+$old_series = array();
+$added_seasons = array();
+$multi_seasons = array();
+$empty_seasons = array();
 
 # Check each series for new seasons listed on TVDB but not locally
 foreach ($all_series as $series => $seasons) {
 
 	# Long wait between series, to avoid TVDB bans
-	sleep(rand(20, 40));
+	if (!$DEBUG) {
+		sleep(rand(20, 40));
+	}
 
 	# Grab the season parameters
 	$flags = readFlags($series);
@@ -22,27 +29,27 @@ foreach ($all_series as $series => $seasons) {
 	}
 
 	# Grab the TVDB season list
-	$tvdb_seasons = getTVDBSeasons($flags['tvdb-id'], $flags['tvdb-lid']);
+	$tvdb_seasons = array();
+	if (!$DEBUG) {
+		$tvdb_seasons = getTVDBSeasons($flags['tvdb-id'], $flags['tvdb-lid']);
+	} else {
+		$tvdb_seasons[1] = true;
+	}
 
 	# We only care about "new" seasons -- don't force old seasons into the local tree
 	$tvdb_max = @max(array_keys($tvdb_seasons));
 	$local_max = @max(array_keys($seasons));
 
-	# If we detect one or more missing seasons
-	if ($tvdb_max > $local_max) {
-
-		# Sanity check
-		if ($tvdb_max - $local_max > 5) {
-			echo 'TheTVDB lists ' . $tvdb_max . ' season for ' . $series. ". Skipping...\n";
-			continue;
-		}
+	# Sanity check
+	if ($tvdb_max - $local_max > 5) {
+		echo 'TheTVDB lists ' . $tvdb_max . ' season for ' . $series. ". Skipping...\n";
+		continue;
+	}
 
-		# Add the seasons
-		echo $series . "\n";
-		for ($season = $local_max + 1; $season <= $tvdb_max; $season++) {
-			echo "\tAdding season: " . $season . "\n";
-			addSeason($series, $season);
-		}
+	# Add missing seasons
+	for ($season = $local_max + 1; $season <= $tvdb_max; $season++) {
+		$added_seasons[] = $series . ' - Season ' . $season;
+		addSeason($series, $season);
 	}
 
 	# Check for multiple monitored seasons in a series
@@ -54,8 +61,66 @@ foreach ($all_series as $series => $seasons) {
 		}
 	}
 	if ($monitored_count > 1) {
-		echo 'Multiple seasons monitored for: ' . $series . "\n";
+		$multi_seasons[] = $series;
+	}
+
+	# Check for seasons with no episodes
+	foreach ($seasons as $season => $status) {
+		if ($status) {
+			$episodes = findEpisodes($series, $season);
+			if (count($episodes) < 1) {
+				$empty_seasons[] = $series . ' - Season ' . $season;
+			}
+		}
+	}
+
+	# Check for "old" but still monitored series
+	foreach ($seasons as $season => $status) {
+		if ($status) {
+			if ($flags['mtime'] < time() - $MAX_AGE) {
+				$old_series[] = $series;
+				break;
+			}
+		}
+	}
+}
+
+# Display series with multiple monitored seasons
+if (count($multi_seasons) > 0) {
+	echo "\n";
+	echo "Series with multiple monitored seasons:\n";
+	foreach ($multi_seasons as $val) {
+		echo "\t" . $val . "\n";
+	}
+}
+
+# Display added seasons
+if (count($added_seasons) > 0) {
+	echo "\n";
+	echo "Added seasons:\n";
+	foreach ($added_seasons as $val) {
+		echo "\t" . $val . "\n";
 	}
 }
 
+# Display "old" series
+if (count($old_series) > 0) {
+	echo "\n";
+	echo "Monitored series with no recent updates:\n";
+	foreach ($old_series as $val) {
+		echo "\t" . $val . "\n";
+	}
+}
+
+# Display empty seasons
+if (count($empty_seasons) > 0) {
+	echo "\n";
+	echo "Monitored seasons with no episodes:\n";
+	foreach ($empty_seasons as $val) {
+		echo "\t" . $val . "\n";
+	}
+}
+
+# Display "old" seasons
+
 ?>