Parcourir la source

Consistent show vs. series names

Zachary Kotlarek il y a 13 ans
Parent
commit
bf91b29236
5 fichiers modifiés avec 127 ajouts et 70 suppressions
  1. 35 25
      web/includes/display.php
  2. 13 17
      web/includes/season.php
  3. 50 11
      web/includes/series.php
  4. 2 2
      web/includes/tvdb.php
  5. 27 15
      web/index.php

+ 35 - 25
web/includes/display.php

@@ -2,30 +2,34 @@
 
 require 'config.php';
 
-function printShow($show) {
-	global $TV_PATH;
+function printSeries($series) {
 	global $EXISTS_FILES;
 	global $CONTENT_FILES;
 
-	# Construct our show path and make sure it's reasonable
-	$path = $TV_PATH . '/' . $show;
-	$show_html = htmlspecialchars($show);
-	if (!is_dir($path)) {
-		die('Unknown show: ' . $show_html);
+	# Ensure our series name is reasonable
+	$series_html = htmlspecialchars($series);
+	if (!seriesExists($series)) {
+		die('Unknown series: ' . $series_html);
 	}
 
 	# Check the flags
-	$flags = readFlags($path);
+	$flags = readFlags($series);
 
 	# Check the seasons
-	$seasons = findSeasons($path);
+	$seasons = findSeasons($series);
 
 	# Header
-	echo '<h1>' . $show_html . '</h1>';
-	echo '<form action="' . $_SERVER['PHP_SELF'] . '?show=' . urlencode($show) . '" method="post">';
-	echo '<input type="hidden" name="show" value="' . $show_html . '"/>';
+	echo '<h1>' . $series_html . '</h1>';
+	echo '<form action="' . $_SERVER['PHP_SELF'] . '?series=' . urlencode($series) . '" method="post">';
+	echo '<input type="hidden" name="series" value="' . $series_html . '"/>';
+
+	# TVDB URL
+	echo '<h2>TVDB</h2>';
+	echo '<p><a target="_blank" href="' . 
+		htmlspecialchars($flags['url']) .
+		'">' . htmlspecialchars($flags['url']) . '</a></p>';
 
-	# Exists and content flags
+	# Series flags
 	echo '<h2>Series Parameters</h2>';
 	echo '<p>';
 	foreach ($EXISTS_FILES as $file) {
@@ -50,13 +54,11 @@ function printShow($show) {
 		echo '</p>';
 	}
 
-	# TVDB URL
-	echo '<h2>The TVDB URL</h2>';
-	echo '<p><a href="' . htmlspecialchars($flags['url']) . '">' . htmlspecialchars($flags['url']) . '</a></p>';
-
 	# Seasons
 	if (!$flags['skip']) {
 		echo '<h2>Season Parameters</h2>';
+
+		# Existing seasons
 		echo '<p>';
 		foreach ($seasons as $season => $monitored) {
 			$season_html = htmlspecialchars($season);
@@ -73,23 +75,31 @@ function printShow($show) {
 			echo '"/><br/>';
 		}
 		echo '</p>';
+
+		# Add a season
+		$next_season = max(array_keys($seasons)) + 1;
+		echo '<p>Add season: ';
+		echo '<input type="text" size="2" name="season_new" value="' . htmlspecialchars($next_season) . '"/>';
+		echo '<input type="submit" name="AddSeason" value="Add Season">';
+		echo '</p>';
+
 	}
 
-	# Footer
+	# Save button
 	echo '<p><input type="submit" name="Save" value="Save"/></p>';
+
+	# Footer
 	echo '</form>';
 }
 
-# Print a DL of all shows and note the available and monitored seasons
-function printAllShows() {
+# Print a DL of all series and note the available and monitored seasons
+function printAllSeries() {
 	global $TV_PATH;
-	global $MEDIA_PATH;
-
-	$shows = allShows($TV_PATH);
+	$all_series = allSeries($TV_PATH);
 
 	echo "<dl>\n";
-	foreach ($shows as $show => $seasons) {
-		echo '<dt><a href="?show=' . urlencode($show) . '">' . htmlspecialchars($show) . "</a></dt>\n";
+	foreach ($all_series as $series => $seasons) {
+		echo '<dt><a href="?series=' . urlencode($series) . '">' . htmlspecialchars($series) . "</a></dt>\n";
 		foreach ($seasons as $season => $monitored) {
 			echo '<dd>Season ' . htmlspecialchars($season);
 			if ($monitored) {

+ 13 - 17
web/includes/season.php

@@ -38,7 +38,7 @@ function seasonSearch($season_path) {
 }
 
 # Find all the season in a provided series folder and determine which are being monitored
-function findSeasons($path) {
+function findSeasons($series) {
 	$retval = array();
 
 	# Check for the skip file
@@ -47,6 +47,7 @@ function findSeasons($path) {
 		$skip = true;
 	}
 
+	$path = seriesPath($series);
 	$dir = opendir($path);
 	if ($dir === FALSE) {
 		die('Unable to opendir(): ' . htmlspecialchars($path) . "\n");
@@ -54,7 +55,7 @@ function findSeasons($path) {
 	while (false !== ($season = readdir($dir))) {
 
 		# Skip junk
-		if (isJunk($show)) {
+		if (isJunk($season)) {
 			continue;
 		}
 
@@ -78,19 +79,16 @@ function findSeasons($path) {
 }
 
 # Save the search status for all seasons in a series
-function saveSeasons($series_path, $data, $series_last, $seasons_last) {
+function saveSeasons($series, $data, $series_last, $seasons_last) {
 	# Do nothing if we are or just were in "skip" mode
-	if ($series['skip'] || $series_last['skip']) {
+	if ($data['skip'] || $series_last['skip']) {
 		return;
 	}
 
-	# Fresh data from disk
-	$series = readFlags($series_path);
-	$seasons = findSeasons($series_path);
-
 	# For each season
+	$seasons = findSeasons($series);
 	foreach ($seasons as $season => $status) {
-		$season_path = $series_path . '/Season ' . $season;
+		$season_path = seriesPath($series) . '/Season ' . $season;
 
 		$monitored = $data[ 'season_' . $season ];
 		$monitored_path = $season_path . '/season_done';
@@ -120,18 +118,16 @@ function saveSeasons($series_path, $data, $series_last, $seasons_last) {
 	}
 }
 
-# Add a folder for the provided show and season
-function addSeason($show, $season) {
-	global $TV_DIR;
+# Add a folder for the provided series and season
+function addSeason($series, $season) {
 
-	# Ensure the show exists
-	$show_path = $TV_DIR . '/' . $show;
-	if (!is_dir($show_path)) {
-		die('Invalid show: ' . htmlspecialchars($show) . "\n");
+	# Ensure the series exists
+	if (!seriesExists($series)) {
+		die('Invalid series: ' . htmlspecialchars($series) . "\n");
 	}
 
 	# Ensure the season does not exist
-	$season_path = $show_path . '/Season ' . intval($season);
+	$season_path = seriesPath($series) . '/Season ' . intval($season);
 	if (file_exists($season_path)) {
 		die('Invalid season: ' . htmlspecialchars($season) . "\n");
 	}

+ 50 - 11
web/includes/series.php

@@ -2,8 +2,17 @@
 
 require 'config.php';
 
-# Find all shows under the given path
-function allShows($base)	{
+function seriesExists($series) {
+	return is_dir(seriesPath($series));
+}
+
+function seriesPath($series) {
+	global $TV_PATH;
+	return $TV_PATH . '/' . $series;
+}
+
+# Find all seriess under the given path
+function allSeries($base) {
 	$retval = array();
 
 	# Look for series folders
@@ -11,21 +20,20 @@ function allShows($base)	{
 	if ($tv_dir === FALSE) {
 		die('Unable to opendir(): ' . htmlspecialchars($path) . "\n");
 	}
-	while (false !== ($show = readdir($tv_dir))) {
+	while (false !== ($series = readdir($tv_dir))) {
 
 		# Skip junk
-		if (isJunk($show)) {
+		if (isJunk($series)) {
 			continue;
 		}
 
-		# We only care about directories
-		$show_path = $base . '/' . $show;
-		if (!is_dir($show_path)) {
+		# Ensure the series is reasonable
+		if (!seriesExists($series)) {
 			continue;
 		}
 
-		# Record the show title and look for season folders
-		$retval[ $show ] = findSeasons($show_path);
+		# Record the series title and look for season folders
+		$retval[ $series ] = findSeasons($series);
 	}
 	closedir($tv_dir);
 	
@@ -33,11 +41,17 @@ function allShows($base)	{
 }
 
 # Read and parse all of the series-level exists, content, and *.webloc files
-function readFlags($path) {
+function readFlags($series) {
 	global $EXISTS_FILES;
 	global $CONTENT_FILES;
 	$flags = array();
 
+	# Ensure the series exists
+	if (!seriesExists($series)) {
+		die('Invalid series: ' . htmlspecialchars($series) . "\n");
+	}
+	$path = seriesPath($series);
+
 	# Look for all the exists files
 	foreach ($EXISTS_FILES as $name) {
 		$flags[ $name ] = false;
@@ -65,10 +79,35 @@ function readFlags($path) {
 }
 
 # Parse and save all of the serires-level exists and content files
-function saveFlags($series_path, $data, $series_last, $seasons_last) {
+function saveFlags($series, $data, $series_last, $seasons_last) {
 	global $EXISTS_FILES;
 	global $CONTENT_FILES;
 
+	# Ensure the series exists
+	if (!seriesExists($series)) {
+		die('Invalid series: ' . htmlspecialchars($series) . "\n");
+	}
+	$series_path = seriesPath($series);
+
+	# Special handling for "skip"
+	{
+		$path = $series_path . '/skip';
+		if ($data['skip']) {
+			if (!file_exists($path)) {
+				touch($path);
+			}
+		} else {
+			if (file_exists($path)) {
+				unlink($path);
+			}
+		}
+	}
+
+	# Ignore everything else if we are now or were just in "skip" mode
+	if ($series_last['skip'] || $data['skip']) {
+		return;
+	}
+	
 	# Exists files
 	foreach ($EXISTS_FILES as $file) {
 		$path = $series_path . '/' . $file;

+ 2 - 2
web/includes/tvdb.php

@@ -14,8 +14,8 @@ function getTVDBSeasons($id) {
 	return $retval;
 }
 
-# Search TVDB for the named show and return all likely results
-function findTVDBShow($show) {
+# Search TVDB for the named series and return all likely results
+function findTVDBSeries($series) {
 	$retval = false;
 	return $retval;
 }

+ 27 - 15
web/index.php

@@ -6,27 +6,39 @@ require_once 'includes/main.php';
 # Send our headers early
 header('Content-type: text/html; charset=utf-8');
 
-# Did the user request a specific show?
-$show = false;
-if (isset($_REQUEST['show'])) {
+# Did the user request a specific series?
+$series = false;
+if (isset($_REQUEST['series'])) {
 	# This is not a great filter, but it should make the string safe for use as a quoted path
-	$show = preg_replace('/[\0\n\r]/', '', $_REQUEST['show']);
-	$show = basename($show);
+	$series = preg_replace('/[\0\n\r]/', '', $_REQUEST['series']);
+	$series = basename($series);
 }
 
 # Did the user request an update?
-if ($show !== false && isset($_POST['Save'])) {
+if ($series !== false && isset($_POST['Save'])) {
 	# Require auth (or for the time being, specific IP addresses)
 	if (preg_match('/^(?:172\.19\.[17]\.|2602:3f:e50d:76|74\.93\.97\.65)/', $_SERVER['REMOTE_ADDR'])) {
+
 		# Grab the current settings for comparison
-		global $TV_PATH;
-		$series_path = $TV_PATH . '/'. $show;
-		$series_last = readFlags($series_path);
-		$seasons_last = findSeasons($series_path);
+		$series_last = readFlags($series);
+		$seasons_last = findSeasons($series);
 
 		# Save series and season data
-		saveFlags($series_path, $_POST, $series_last, $seasons_last);
-		saveSeasons($series_path, $_POST, $series_last, $seasons_last);
+		saveFlags($series, $_POST, $series_last, $seasons_last);
+		saveSeasons($series, $_POST, $series_last, $seasons_last);
+	} else {
+		echo '<h4 style="color: red;">Cannot save: User not authenticated</h4>';
+	}
+}
+
+# Did the user add a season?
+if ($series !== false && isset($_POST['AddSeason'])) {
+	# Require auth (or for the time being, specific IP addresses)
+	if (preg_match('/^(?:172\.19\.[17]\.|2602:3f:e50d:76|74\.93\.97\.65)/', $_SERVER['REMOTE_ADDR'])) {
+
+		# Add a season folder
+		$new_season = intval($_POST['season_new']);
+		addSeason($series, $new_season);
 	} else {
 		echo '<h4 style="color: red;">Cannot save: User not authenticated</h4>';
 	}
@@ -47,10 +59,10 @@ print <<<ENDOLA
 
 ENDOLA;
 
-if ($show === false) {
-	printAllShows();
+if ($series === false) {
+	printAllSeries();
 } else {
-	printShow($show);
+	printSeries($series);
 }
 
 # Generic XHTML 1.1 footer