Ver Fonte

Support individual episode processing

Zachary Kotlarek há 12 anos atrás
pai
commit
2bc41de17f
1 ficheiros alterados com 60 adições e 51 exclusões
  1. 60 51
      plexCmd/renameFromDisk.pl

+ 60 - 51
plexCmd/renameFromDisk.pl

@@ -16,9 +16,9 @@ if ($ENV{'DEBUG'}) {
 }
 }
 
 
 # Parameters
 # Parameters
-my ($host, $section, $series, $season) = @ARGV;
-if (!$host || (!$section && !$series && !$season)) {
-	die('Usage: ' . basename($0) . ' host[:port] [section_number] [series_metadata_number] [season_metadata_number]');
+my ($host, $section, $series, $season, $episode) = @ARGV;
+if (!$host || (!$section && !$series && !$season && !$episode)) {
+	die('Usage: ' . basename($0) . ' host[:port] [section_number] [series_metadata_id] [season_metadata_id] [episode_metadata_id]');
 }
 }
 
 
 # Globals
 # Globals
@@ -28,8 +28,8 @@ if (!($host =~ /\:\d+$/)) {
 my $baseURL = 'http://' . $host;
 my $baseURL = 'http://' . $host;
 my $xml     = new XML::Simple;
 my $xml     = new XML::Simple;
 
 
-my @shows = ();	
-if (!$season) {
+my @shows = ();
+if (!$season && !$episode) {
 	if ($series) {
 	if ($series) {
 
 
 		# Fetch just the provided show
 		# Fetch just the provided show
@@ -59,69 +59,78 @@ if (!$season) {
 }
 }
 
 
 my @seasons = ();
 my @seasons = ();
-if ($season) {
+if (!$episode) {
+	if ($season) {
 
 
-	# Fetch just the provided season
-	print STDERR 'Fetching season ' . $season . "\n";
-	@seasons = ('/library/metadata/' . $season . '/children');
-} else {
+		# Fetch just the provided season
+		print STDERR 'Fetching season ' . $season . "\n";
+		@seasons = ('/library/metadata/' . $season . '/children');
+	} else {
 
 
-	# Fetch the list of all seasons in each show
-	print STDERR "Fetching seasons...\n";
-	foreach my $show (@shows) {
-		my $content = get($baseURL . $show);
-		if ($DEBUG) {
-			print STDERR $baseURL . $show . "\n";
-		}
-		if (!$content) {
-			warn(basename($0) . ': Could not fetch seasons for show: ' . $show . "\n");
-			next;
-		}
+		# Fetch the list of all seasons in each show
+		print STDERR "Fetching seasons...\n";
+		foreach my $show (@shows) {
+			my $content = get($baseURL . $show);
+			if ($DEBUG) {
+				print STDERR $baseURL . $show . "\n";
+			}
+			if (!$content) {
+				warn(basename($0) . ': Could not fetch seasons for show: ' . $show . "\n");
+				next;
+			}
 
 
-		# Find all seasons in the show
-		{
-			my $tree = $xml->XMLin($content);
+			# Find all seasons in the show
+			{
+				my $tree = $xml->XMLin($content);
 
 
-			# XML::Simple retuns different structure depending on the number of same-named child elements
-			if ($tree->{'Directory'}->{'key'}) {
-				push(@seasons, $tree->{'Directory'}->{'key'});
-			} else {
-				push(@seasons, keys(%{ $tree->{'Directory'} }));
+				# XML::Simple retuns different structure depending on the number of same-named child elements
+				if ($tree->{'Directory'}->{'key'}) {
+					push(@seasons, $tree->{'Directory'}->{'key'});
+				} else {
+					push(@seasons, keys(%{ $tree->{'Directory'} }));
+				}
 			}
 			}
 		}
 		}
 	}
 	}
+	print STDERR 'Found ' . scalar(@seasons) . " seasons\n";
 }
 }
-print STDERR 'Found ' . scalar(@seasons) . " seasons\n";
 
 
 # Forget the list of shows
 # Forget the list of shows
 undef(@shows);
 undef(@shows);
 
 
 # Fetch the list of all episodes in each season
 # Fetch the list of all episodes in each season
 my @episodes = ();
 my @episodes = ();
-print STDERR "Fetching episodes...\n";
-foreach my $season (@seasons) {
-	my $content = get($baseURL . $season);
-	if ($DEBUG) {
-		print STDERR $baseURL . $season . "\n";
-	}
-	if (!$content) {
-		warn(basename($0) . ': Could not fetch episodes for season: ' . $season . "\n");
-		next;
-	}
+if ($episode) {
 
 
-	# Find all episodes in the season
-	{
-		my $tree = $xml->XMLin($content);
+	# Fetch just the provided episode
+	print STDERR 'Fetching episode ' . $episode . "\n";
+	@episodes = ('/library/metadata/' . $episode);
+} else {
+	print STDERR "Fetching episodes...\n";
+	foreach my $season (@seasons) {
+		my $content = get($baseURL . $season);
+		if ($DEBUG) {
+			print STDERR $baseURL . $season . "\n";
+		}
+		if (!$content) {
+			warn(basename($0) . ': Could not fetch episodes for season: ' . $season . "\n");
+			next;
+		}
+
+		# Find all episodes in the season
+		{
+			my $tree = $xml->XMLin($content);
 
 
-		# XML::Simple retuns different structure depending on the number of same-named child elements
-		if ($tree->{'Video'}->{'key'}) {
-			push(@episodes, $tree->{'Video'}->{'key'});
-		} else {
-			push(@episodes, keys(%{ $tree->{'Video'} }));
+			# XML::Simple retuns different structure depending on the number of same-named child elements
+			if ($tree->{'Video'}->{'key'}) {
+				push(@episodes, $tree->{'Video'}->{'key'});
+			} else {
+				push(@episodes, keys(%{ $tree->{'Video'} }));
+			}
 		}
 		}
 	}
 	}
+	print STDERR 'Found ' . scalar(@episodes) . " episodes\n";
 }
 }
-print STDERR 'Found ' . scalar(@episodes) . " episodes\n";
 
 
 # Forget the list of seasons
 # Forget the list of seasons
 undef(@seasons);
 undef(@seasons);
@@ -140,8 +149,8 @@ foreach my $episode (@episodes) {
 
 
 	# Parse the metadata
 	# Parse the metadata
 	{
 	{
-		my $tree  = $xml->XMLin($content);
-		my $title = $tree->{'Video'}->{'title'};
+		my $tree    = $xml->XMLin($content);
+		my $title   = $tree->{'Video'}->{'title'};
 		my $summary = $tree->{'Video'}->{'summary'};
 		my $summary = $tree->{'Video'}->{'summary'};
 		my $file    = $tree->{'Video'}->{'Media'}->{'Part'}->{'file'};
 		my $file    = $tree->{'Video'}->{'Media'}->{'Part'}->{'file'};