Просмотр исходного кода

Add generic support for "extras" -- additional data items parsed from the same file.
Add specific support for playback-related items, like title, position, length, series, etc.

Zachary Kotlarek 13 лет назад
Родитель
Сommit
4e1e83fd7e
2 измененных файлов с 51 добавлено и 2 удалено
  1. 1 1
      dmx/DMX.pm
  2. 50 1
      dmx/state.pl

+ 1 - 1
dmx/DMX.pm

@@ -134,7 +134,7 @@ sub parseState($$$) {
 	}
 	if (defined($exists_text)) {
 		foreach my $exists_val (split(/\s*,\s*/, $exists_text)) {
-			my ($name, $value, $time) = $exists_val =~ /(\w+)\:([\w\.\- ]*)\:(\d*)/;
+			my ($name, $value, $time) = $exists_val =~ /(\w+)\:([^\,\:]*)\:(\d*)/;
 			if (!defined($name) || !defined($value) || !defined($time)) {
 				print STDERR 'State parse error (exists): ' . $text . "\n";
 				next;

+ 50 - 1
dmx/state.pl

@@ -42,6 +42,19 @@ my %MON_FILES     = (
 
 	$MEDIA_PATH . '/DMX/cmd/GARAGE_CMD' => 'EXISTS_CLEAR',
 );
+my %EXTRAS = (
+	'PLAYING' => {
+		'URL'      => qr/^\<li\>Filename\:(.+)$/m,
+		'YEAR'     => qr/^\<li\>Year\:(\d+)/m,
+		'SERIES'   => qr/^\<li\>Show Title\:(.+)$/m,
+		'SEASON'   => qr/^\<li\>Season\:(\d+)/m,
+		'EPISODE'  => qr/^\<li\>Episode\:(\d+)/m,
+		'TITLE'    => qr/^\<li\>Title\:(.+)$/m,
+		'LENGTH'   => qr/^\<li\>Duration\:([\d\:]+)/m,
+		'POSITION' => qr/^\<li\>Time\:([\d\:]+)/m,
+		'SIZE'     => qr/^\<li\>File size\:(\d+)/m,
+	}
+);
 
 # App config
 my $SOCK_TIMEOUT = 5;
@@ -80,6 +93,13 @@ my $statusLast = $status;
 my $updateLast = 0;
 my $pushLast   = 0;
 
+# Add the extras to the main file list
+foreach my $file (keys(%EXTRAS)) {
+	foreach my $extra (keys(%{ $EXTRAS{$file} })) {
+		$MON_FILES{ $file . '_' . $extra } = 'NONE';
+	}
+}
+
 # Init the file tracking structure
 my %files = ();
 foreach my $file (keys(%MON_FILES)) {
@@ -170,6 +190,11 @@ while (1) {
 	# Monitor files of all types
 	foreach my $file (values(%files)) {
 
+		# Skip "NONE" files -- they are data stores handled in other actions
+		if ($file->{'type'} eq 'NONE') {
+			next;
+		}
+
 		# Always record the previous status and clear the new one
 		$file->{'last'}   = $file->{'status'};
 		$file->{'status'} = 0;
@@ -195,6 +220,7 @@ while (1) {
 				}
 			}
 
+			# Record the main status for the file
 			if ($file->{'type'} eq 'STATUS_PLAYING') {
 				if ($text =~ /PlayStatus\:Playing/) {
 					$file->{'status'} = 1;
@@ -214,6 +240,25 @@ while (1) {
 			if ($DEBUG) {
 				print STDERR 'Status: ' . $file->{'name'} . ': ' . $file->{'status'} . "\n";
 			}
+
+			# Handle extras, if any
+			if ($EXTRAS{ $file->{'name'} }) {
+				foreach my $extra (keys(%{ $EXTRAS{ $file->{'name'} } })) {
+
+					my $name = $file->{'name'} . '_' . $extra;
+					$files{$name}{'last'}   = $files{$name}{'status'};
+					$files{$name}{'status'} = '';
+					$files{$name}{'update'} = $file->{'update'};
+
+					if ($text =~ $EXTRAS{ $file->{'name'} }{$extra}) {
+						$files{$name}{'status'} = $1;
+					}
+
+					if ($DEBUG) {
+						print STDERR 'Status (extra): ' . $name . ': ' . $files{$name}{'status'} . "\n";
+					}
+				}
+			}
 		}
 
 		# Check for the presence of EXISTS files and record their last change
@@ -283,7 +328,11 @@ while (1) {
 	{
 		my @statTime = ();
 		foreach my $file (values(%files)) {
-			push(@statTime, $file->{'name'} . ':' . $file->{'status'} . ':' . $file->{'update'});
+			my $text = $file->{'status'};
+			$text =~ s/\s/ /g;
+			$text =~ s/\,/_/g;
+			$text =~ s/\:/-/g;
+			push(@statTime, $file->{'name'} . ':' . $text . ':' . $file->{'update'});
 		}
 		$status = ' (' . join(', ', @statTime) . ')';
 	}