patch set part 2 attached

Quoting Pete Beardmore <[email protected]>:

Quoting [email protected]:

Your mail to 'get_iplayer' with the subject
   Re: web-settings-and-get_iplayer-defaults-harmonisation
Is being held until the list moderator can review it for approval.
The reason it is being held:
   Message body is too big: 87651 bytes with a limit of 40 KB

hello,

my post has been in limbo a few days now. could a list moderator please push it through? or would it be better to split the mail?

thanks,
Pete.

_______________________________________________
get_iplayer mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/get_iplayer


>From 41189137300c61776b0850b8d935fe1f56ce4445 Mon Sep 17 00:00:00 2001
From: Pete Beardmore <[email protected]>
Date: Sun, 14 Apr 2013 15:15:09 +0100
Subject: [PATCH] web pvr initialisation and options code refactoring

---
 get_iplayer.cgi |  276 ++++++++++++++++++++++++++----------------------------
 1 files changed, 133 insertions(+), 143 deletions(-)

diff --git a/get_iplayer.cgi b/get_iplayer.cgi
index 1b335dc..f66be88 100755
--- a/get_iplayer.cgi
+++ b/get_iplayer.cgi
@@ -46,25 +46,13 @@ my $fh;
 # Send log messages to this fh
 my $se = *STDERR;
 
-my $opt_cmdline;
-$opt_cmdline->{debug} = 0;
-# Allow bundling of single char options
-Getopt::Long::Configure ("bundling");
-# cmdline opts take precedence
-GetOptions(
-	"help|h"			=> \$opt_cmdline->{help},
-	"listen|address|l=s"		=> \$opt_cmdline->{listen},
-	"port|p=n"			=> \$opt_cmdline->{port},
-	"ffmpeg=s"			=> \$opt_cmdline->{ffmpeg},
-	"getiplayer|get_iplayer|g=s"	=> \$opt_cmdline->{getiplayer},
-	"debug"				=> \$opt_cmdline->{debug},
-) || die usage();
-
-# Display usage if old method of invocation is used or --help
-usage() if $opt_cmdline->{help} || @ARGV;
-
+#### state ####
+my $home = $ENV{HOME}; # path to get_iplayer (HOME env var not set by apache)
+my $cgi;
+my $opt;
+my $nextpage;
 
-# Usage
+#### usage ####
 sub usage {
 	my $text = sprintf "get_iplayer Web PVR Manager v%.2f, ", $VERSION;
 	$text .= <<'EOF';
@@ -85,24 +73,55 @@ EOF
 	exit 1;
 }	
 
-# ensure get_iplayer
-if ( ! $opt_cmdline->{getiplayer} ) {
+#### options ####
+# command line options
+my %opt_cmdline;
+# Allow bundling of single char options
+Getopt::Long::Configure ("bundling");
+GetOptions(
+	"help|h"			=> \$opt_cmdline{help},
+	"listen|address|l=s"		=> \$opt_cmdline{listen},
+	"port|p=n"			=> \$opt_cmdline{port},
+	"ffmpeg=s"			=> \$opt_cmdline{ffmpeg},
+	"getiplayer|get_iplayer|g=s"	=> \$opt_cmdline{getiplayer},
+	"debug"				=> \$opt_cmdline{debug},
+) || die usage();
+# Display usage if old method of invocation is used or --help
+usage() if $opt_cmdline{help} || @ARGV;
+
+# default options
+my %opt_default;
+# ensure underlying get_iplayer script is available
+if ( ! $opt_cmdline{getiplayer} ) {
 	for ( './get_iplayer', './get_iplayer.cmd', './get_iplayer.pl', '/usr/bin/get_iplayer' ) {
-		$opt_cmdline->{getiplayer} = $_ if -x $_;
+		$opt_cmdline{getiplayer} = $_ if -x $_;
 	}
 }
-if ( ( ! $opt_cmdline->{getiplayer} ) || ! -f $opt_cmdline->{getiplayer} ) {
+if ( ( ! $opt_cmdline{getiplayer} ) || ! -f $opt_cmdline{getiplayer} ) {
 	print "ERROR: Cannot find get_iplayer, please specify its location using the --getiplayer option.\n";
 	exit 2;
 }
+$opt_default{getiplayer} = $opt_cmdline{getiplayer};
+set_default_options(); # command line options merged. use opt_default beyond here
 
-# Path to get_iplayer (+ set HOME env var cos apache seems to not set it)
-my $home = $ENV{HOME};
-
-my %prog;
-my @pids;
-my @displaycols;
-
+#### page ####
+# Page routing based on NEXTPAGE CGI parameter
+my %nextpages = (
+	'search_progs'		=> \&search_progs,	# Main Programme Listings
+	'search_history'	=> \&search_history,	# Recorded Programme Listings
+	'pvr_queue'		=> \&pvr_queue,		# Queue Recording of Selected Progs
+	'recordings_delete'	=> \&recordings_delete,	# Delete Files for Selected Recordings
+	'pvr_list'		=> \&show_pvr_list,	# Show all current PVR searches
+	'pvr_del'		=> \&pvr_del,		# Delete selected PVR searches
+	'pvr_add'		=> \&pvr_add,
+	'pvr_edit'		=> \&pvr_edit,
+	'pvr_save'		=> \&pvr_save,
+	'pvr_run'		=> \&pvr_run,
+	'record_now'		=> \&record_now,
+	'show_info'		=> \&show_info,
+	'refresh'		=> \&refresh,
+	'update_script'		=> \&update_script,
+);
 # Field names to be grabbed from get_iplayer
 my @headings = qw( 
 	index
@@ -125,7 +144,6 @@ my @headings = qw(
 	filename
 	mode
 );
-
 # Lookup table for nice field name headings
 my %fieldname = (
 	index			=> 'Index',
@@ -152,10 +170,6 @@ my %fieldname = (
 	'name,episode'		=> 'Name+Episode',
 	'name,episode,desc'	=> 'Name+Episode+Desc',
 );
-
-my %cols_order = ();
-my %cols_names = ();
-
 my %prog_types = (
 	tv	=> 'BBC TV',
 	radio	=> 'BBC Radio',
@@ -163,7 +177,6 @@ my %prog_types = (
 	livetv	=> 'Live BBC TV',
 	liveradio => 'Live BBC Radio',
 );
-
 my %prog_types_order = (
 	1	=> 'tv',
 	2	=> 'radio',
@@ -171,59 +184,14 @@ my %prog_types_order = (
 	4	=> 'livetv',
 	5	=> 'liveradio',
 );
+my %cols_order = ();
+my %cols_names = ();
+my %prog;
+my @pids;
+my @displaycols;
 
-# Get list of currently valid and prune %prog types and add new entry
-chomp( my @plugins = split /,/, join "\n", get_cmd_output( $opt_cmdline->{getiplayer}, '--nopurge', '--nocopyright', '--listplugins' ) );
-for my $type (keys %prog_types) {
-	if ( $prog_types{$type} && not grep /$type/, @plugins ) {
-		# delete from %prog_types hash
-		delete $prog_types{$type};
-		# Delete from %prog_types_order hash
-		for ( keys %prog_types_order ) {
-			delete $prog_types_order{$_} if $prog_types_order{$_} eq $type; 
-		}
-	}
-}
-for my $type ( @plugins ) {
-	if ( not $prog_types{$type} ) {
-		$prog_types{$type} = $type;
-		# Add to %prog_types_order hash
-		my $max = scalar( keys %prog_types_order ) + 1;
-		$prog_types_order{$max} = $type;
-	}
-}
-#print "DEBUG: prog_types_order: $_ => $prog_types_order{$_}\n" for sort keys %prog_types_order;
-
-my $icons_base_url = './icons/';
-
-my $cgi;
-my $nextpage;
-
-# Page routing based on NEXTPAGE CGI parameter
-my %nextpages = (
-	'search_progs'		=> \&search_progs,	# Main Programme Listings
-	'search_history'	=> \&search_history,	# Recorded Programme Listings
-	'pvr_queue'		=> \&pvr_queue,		# Queue Recording of Selected Progs
-	'recordings_delete'	=> \&recordings_delete,	# Delete Files for Selected Recordings
-	'pvr_list'		=> \&show_pvr_list,	# Show all current PVR searches
-	'pvr_del'		=> \&pvr_del,		# Delete selected PVR searches
-	'pvr_add'		=> \&pvr_add,
-	'pvr_edit'		=> \&pvr_edit,
-	'pvr_save'		=> \&pvr_save,
-	'pvr_run'		=> \&pvr_run,
-	'record_now'		=> \&record_now,
-	'show_info'		=> \&show_info,
-	'refresh'		=> \&refresh,
-	'update_script'		=> \&update_script,
-);
-
-# default options
-my %opt_default;
-set_default_options();
-# state options
-my $opt;
-
-# Options Layout on page tabs
+#### layout ####
+# Options on page tabs
 my $layout;
 $layout->{BASICTAB}->{title} = 'Search Options',
 $layout->{BASICTAB}->{heading} = 'Search Options:',
@@ -231,7 +199,7 @@ $layout->{BASICTAB}->{order} = [ qw/ SEARCH SEARCHFIELDS PROGTYPES HISTORY URL /
 
 $layout->{SEARCHTAB}->{title} = 'Advanced Search';
 $layout->{SEARCHTAB}->{heading} = 'Advanced Search Options:';
-$layout->{SEARCHTAB}->{order} = [ qw/ VERSIONLIST EXCLUDE CATEGORY EXCLUDECATEGORY CHANNEL EXCLUDECHANNEL SINCE BEFORE FUTURE / ],
+$layout->{SEARCHTAB}->{order} = [ qw/ VERSIONLIST EXCLUDE CATEGORY EXCLUDECATEGORY CHANNEL EXCLUDECHANNEL SINCE BEFORE FUTURE / ];
 
 $layout->{DISPLAYTAB}->{title} = 'Display';
 $layout->{DISPLAYTAB}->{heading} = 'Display Options:';
@@ -256,6 +224,29 @@ $layout->{HIDDENTAB}->{order} = [ qw/ RESET SAVE SEARCHTAB COLUMNSTAB DISPLAYTAB
 # Order of displayed tab buttoms (BASICTAB and HIDDEN are always displayed regardless of order)
 $layout->{taborder} = [ qw/ BASICTAB SEARCHTAB DISPLAYTAB COLUMNSTAB RECORDINGTAB STREAMINGTAB HIDDENTAB / ];
 
+#### plugins ####
+# Get list of currently valid and prune %prog types and add new entry
+chomp( my @plugins = split /,/, join "\n", get_cmd_output( $opt_default{getiplayer}, '--nopurge', '--nocopyright', '--listplugins' ) );
+for my $type (keys %prog_types) {
+	if ( $prog_types{$type} && not grep /$type/, @plugins ) {
+		# delete from %prog_types hash
+		delete $prog_types{$type};
+		# Delete from %prog_types_order hash
+		for ( keys %prog_types_order ) {
+			delete $prog_types_order{$_} if $prog_types_order{$_} eq $type;
+		}
+	}
+}
+for my $type ( @plugins ) {
+	if ( not $prog_types{$type} ) {
+		$prog_types{$type} = $type;
+		# Add to %prog_types_order hash
+		my $max = scalar( keys %prog_types_order ) + 1;
+		$prog_types_order{$max} = $type;
+	}
+}
+#print "DEBUG: prog_types_order: $_ => $prog_types_order{$_}\n" for sort keys %prog_types_order;
+
 ### Perl CGI Web Server ###
 use Socket;
 use IO::Socket;
@@ -311,7 +302,7 @@ if ( $opt_default{port} > 0 ) {
 							s/\s+$//;
 						}
 						$request{lc $type} = $val;
-						print "REQUEST HEADER: $type: $val\n" if $opt_cmdline->{debug};
+						print "REQUEST HEADER: $type: $val\n" if $opt_default{debug};
 					# POST data
 					} elsif (/^$/) {
 						read( $client, $request{CONTENT}, $request{'content-length'} ) if defined $request{'content-length'};
@@ -404,7 +395,6 @@ if ( $opt_default{port} > 0 ) {
 exit 0;
 
 
-
 sub cleanup {
 	my $signal = shift;
 	print $se "INFO: Cleaning up PID $$ (signal = $signal)\n";
@@ -413,9 +403,10 @@ sub cleanup {
 
 sub set_default_options {
 	# source get_iplayer file options
-	%opt_default = ( %opt_default,  map { m/.*=+.*/ ? s/^\s*(.*?)\s*=\s*(.*?)\s*\n/\1=\2/ && split "=" : () }
-		get_cmd_output($opt_cmdline->{getiplayer}, '--nopurge', '--nocopyright', '--show-options'));
+	%opt_default = ( getiplayer => $opt_default{getiplayer}, ( map { m/.*=+.*/ ? s/^\s*(.*?)\s*=\s*(.*?)\s*\n/\1=\2/ && split "=" : () }
+		get_cmd_output( $opt_default{getiplayer}, '--nopurge', '--nocopyright', '--show-options' ) ) );
 	# ensure defaults
+	$opt_default{debug} = 0;
 	$opt_default{listen} = '0.0.0.0';
 	$opt_default{port} = 0;
 	$opt_default{nosearch} = ''; # params that should never get into the get_iplayer pvr-add search
@@ -436,9 +427,10 @@ sub set_default_options {
 	$opt_default{autopvrrun} = 4 if not defined $opt_default{autopvrrun};
 	$opt_default{refreshfuture} = 0 if not defined $opt_default{refreshfuture};
 	# ensure command line overrides
-	$opt_default{listen} = $opt_cmdline->{listen} if defined $opt_cmdline->{listen};
-	$opt_default{port} = $opt_cmdline->{port} if defined $opt_cmdline->{port};
-	$opt_default{ffmpeg} = $opt_cmdline->{ffmpeg} if defined $opt_cmdline->{ffmpeg};
+	$opt_default{debug} = $opt_cmdline{debug} if defined $opt_cmdline{debug};
+	$opt_default{listen} = $opt_cmdline{listen} if defined $opt_cmdline{listen};
+	$opt_default{port} = $opt_cmdline{port} if defined $opt_cmdline{port};
+	$opt_default{ffmpeg} = $opt_cmdline{ffmpeg} if defined $opt_cmdline{ffmpeg};
 }
 
 sub parse_post_form_string {
@@ -534,7 +526,7 @@ sub run_cgi {
 			my $headers = $cgi->header( -type => $mimetypes{$ext}, -Connection => 'close' );
 
 			# Send the headers to the browser
-			print $se "\r\nHEADERS:\n$headers\n"; #if $opt_cmdline->{debug};
+			print $se "\r\nHEADERS:\n$headers\n"; #if $opt_default{debug};
 			print $fh $headers;
 
 			# Default Recipies
@@ -626,7 +618,7 @@ sub run_cgi {
 			my $headers = $cgi->header( -type => $mimetypes{$ext}, -Connection => 'close' );
 
 			# Send the headers to the browser
-			print $se "\r\nHEADERS:\n$headers\n"; #if $opt_cmdline->{debug};
+			print $se "\r\nHEADERS:\n$headers\n"; #if $opt_default{debug};
 			print $fh $headers;
 
 			stream_file( $filename, $mimetypes{$ext}, $src_ext, $ext, $notranscode, $cgi->param( 'BITRATE' ), $cgi->param( 'VSIZE' ), $cgi->param( 'VFR' ) );
@@ -640,7 +632,7 @@ sub run_cgi {
 		my $headers = $cgi->header( -type => 'audio/x-mpegurl' );
 
 		# Send the headers to the browser
-		print $se "\r\nHEADERS:\n$headers\n"; #if $opt_cmdline->{debug};
+		print $se "\r\nHEADERS:\n$headers\n"; #if $opt_default{debug};
 		print $fh $headers;
 
 		# determine output type
@@ -656,7 +648,7 @@ sub run_cgi {
 		my $headers = $cgi->header( -type => 'text/xml' );
 
 		# Send the headers to the browser
-		print $se "\r\nHEADERS:\n$headers\n"; #if $opt_cmdline->{debug};
+		print $se "\r\nHEADERS:\n$headers\n"; #if $opt_default{debug};
 		print $fh $headers;
 		# ( host, outtype, modes, type, bitrate )
 		print $fh get_opml( $request_host, $cgi->param('OUTTYPE') || 'flv', $opt->{MODES}->{current}, $opt->{PROGTYPES}->{current} , $cgi->param('BITRATE') || '', $opt->{SEARCH}->{current}, $cgi->param('LIST') || '' );
@@ -669,7 +661,7 @@ sub run_cgi {
 		#my $headers = $cgi->header( -type => 'audio/x-mpegurl', -attachment => 'get_iplayer.m3u' );
 
 		# Send the headers to the browser
-		print $se "\r\nHEADERS:\n$headers\n"; #if $opt_cmdline->{debug};
+		print $se "\r\nHEADERS:\n$headers\n"; #if $opt_default{debug};
 		print $fh $headers;
 		
 		# determine output type
@@ -687,7 +679,7 @@ sub run_cgi {
 		# Page Routing
 		form_header( $request_host );
 		#print $fh $cgi->Dump();
-		if ( $opt_cmdline->{debug} ) {
+		if ( $opt_default{debug} ) {
 			print $fh $cgi->Dump();
 			#for my $key (sort keys %ENV) {
 			#    print $fh $key, " = ", $ENV{$key}, "\n";
@@ -712,7 +704,7 @@ sub pvr_run {
 	print $fh "<strong><p>The PVR will auto-run every $opt->{AUTOPVRRUN}->{current} hour(s) if you leave this page open</p></strong>" if $opt->{AUTOPVRRUN}->{current};
 	print $se "INFO: Starting PVR Run\n";
 	my @cmd = (
-		$opt_cmdline->{getiplayer},
+		$opt_default{getiplayer},
 		'--nopurge',
 		'--nocopyright',
 		'--hash',
@@ -729,22 +721,22 @@ sub pvr_run {
 	my $autopvrrun = $cgi->cookie( 'AUTOPVRRUN' ) || $cgi->param( 'AUTOPVRRUN' );
 
 	# Render options actions
-	print $fh div( { -class=>'action' },
-		ul( { -class=>'action' },
-			li( { -class=>'action' }, [
+	print $fh div( { -class => 'action' },
+		ul( { -class => 'action' },
+			li( { -class => 'action' }, [
 				a(
 					{
-						-class=>'action',
+						-class => 'action',
 						-title => 'Run PVR Now',
-						-onClick  => "RefreshTab( '?NEXTPAGE=pvr_run&AUTOPVRRUN=$autopvrrun', ".(1000*3600*$autopvrrun).", 1 );",
+						-onClick => "RefreshTab( '?NEXTPAGE=pvr_run&AUTOPVRRUN=$autopvrrun', ".(1000*3600*$autopvrrun).", 1 );",
 					},
 					'PVR Run Now'
 				),
 				a(
 					{
-						-class=>'action',
+						-class => 'action',
 						-title => 'Close',
-						-onClick  => "window.close()",
+						-onClick => "window.close()",
 					},
 					'Close'
 				),
@@ -804,7 +796,7 @@ sub record_now {
 		next if ! ($type && $pid );
 		my $comment = "$name - $episode";
 		my @cmd = (
-			$opt_cmdline->{getiplayer},
+			$opt_default{getiplayer},
 			'--nopurge',
 			'--nocopyright',
 			'--expiry=999999999',
@@ -816,7 +808,7 @@ sub record_now {
 				build_cmd_options( grep !/^(HISTORY|SINCE|BEFORE|HIDEDELETED|FUTURE|SEARCH|SEARCHFIELDS|VERSIONLIST|PROGTYPES|EXCLUDEC.+)$/, @params )
 			),
 		);
-		print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_cmdline->{debug};
+		print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_default{debug};
 		print $fh '<pre>';
 		# Redirect both STDOUT and STDERR to client browser socket
 		run_cmd_autorefresh( $fh, $fh, 1, @cmd );
@@ -836,7 +828,7 @@ sub stream_prog {
 	print $se "INFO: Start Streaming $pid to browser using modes '$modes', output ext '$ext', audio bitrate '$abitrate', video size '$vsize', video frame rate '$vfr'\n";
 
 	my @cmd = (
-		$opt_cmdline->{getiplayer},
+		$opt_default{getiplayer},
 		'--nocopyright',
 		'--hash',
 		'--expiry=999999999',
@@ -927,7 +919,6 @@ sub stream_file {
 }
 
 
-
 sub build_ffmpeg_args {
 		my ( $filename, $mimetype, $ext, $abitrate, $vsize, $vfr, $src_ext ) = ( @_ );
 		my @cmd_aopts;
@@ -1021,7 +1012,7 @@ sub create_playlist_m3u_single {
 		
 	print $se "INFO: Getting playlist for type '$type' using modes '$modes' and bitrate '$bitrate'\n";
 	my @cmd = (
-		$opt_cmdline->{getiplayer},
+		$opt_default{getiplayer},
 		'--nocopyright',
 		'--expiry=999999999',
 		'--webrequest',
@@ -1175,7 +1166,7 @@ sub get_opml {
 
 		# Extract and rewrite into playlist format
 		my @out = get_cmd_output(
-			$opt_cmdline->{getiplayer},
+			$opt_default{getiplayer},
 			'--nocopyright',
 			'--expiry=999999999',
 			'--webrequest',
@@ -1216,7 +1207,7 @@ sub get_opml {
 
 		# Extract and rewrite into playlist format
 		my @out = get_cmd_output(
-			$opt_cmdline->{getiplayer},
+			$opt_default{getiplayer},
 			'--nocopyright',
 			'--expiry=999999999',
 			'--webrequest',
@@ -1322,7 +1313,7 @@ sub update_script {
 
 	print $se "INFO: Updating get_iplayer\n";
 	my @cmd = (
-		$opt_cmdline->{getiplayer},
+		$opt_default{getiplayer},
 		'--nocopyright',
 		'--expiry=999999999',
 		'--nopurge',
@@ -1824,7 +1815,7 @@ sub interpret_return_code {
 sub get_pvr_list {
 	my $pvrsearch;
 	my $out = join "\n", get_cmd_output(
-		$opt_cmdline->{getiplayer},
+		$opt_default{getiplayer},
 		'--nocopyright',
 		'--expiry=999999999',
 		'--pvrlist',
@@ -2132,13 +2123,13 @@ sub pvr_del {
 	for my $name (@record) {
 		chomp();
 		my @cmd = (
-			$opt_cmdline->{getiplayer},
+			$opt_default{getiplayer},
 			'--nocopyright',
 			'--expiry=999999999',
 			'--webrequest',
 			get_iplayer_webrequest_args( "pvrdel=$name" ),
 		);
-		print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_cmdline->{debug};
+		print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_default{debug};
 		my $cmdout = join "", get_cmd_output( @cmd );
 		return p("ERROR: ".$out) if $? && not $IGNOREEXIT;
 		print $fh p("Deleted: $name");
@@ -2164,13 +2155,13 @@ sub show_info {
 	# Queue all selected '<type>|<pid>' entries in the PVR
 	chomp();
 	my @cmd = (
-		$opt_cmdline->{getiplayer},
+		$opt_default{getiplayer},
 		'--nocopyright',
 		'--expiry=999999999',
 		'--webrequest',
 		get_iplayer_webrequest_args( 'nopurge=1', "type=$type", "future=$opt->{FUTURE}->{current}", "history=$opt->{HISTORY}->{current}", "skipdeleted=$opt->{HIDEDELETED}->{current}", 'info=1', 'fields=pid', "search=$pid" ),
 	);
-	print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_cmdline->{debug};
+	print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_default{debug};
 	my @cmdout = get_cmd_output( @cmd );
 	return p("ERROR: ".@cmdout) if $? && not $IGNOREEXIT;
 	for ( grep !/^(Added|INFO):/, @cmdout ) {
@@ -2250,13 +2241,13 @@ sub get_direct_filename {
 
 	# Get the 'filename' entry from --history --info for this pid
 	my @cmd = (
-		$opt_cmdline->{getiplayer},
+		$opt_default{getiplayer},
 		'--nocopyright',
 		'--expiry=999999999',
 		'--webrequest',
 		get_iplayer_webrequest_args( 'nopurge=1', "history=$history", 'fields=pid', "search=$pid", "type=$type", 'listformat=filename: <pid>|<filename>|<mode>' ),
 	);
-	print $se "Command: ".( join ' ', @cmd )."\n"; # if $opt_cmdline->{debug};
+	print $se "Command: ".( join ' ', @cmd )."\n"; # if $opt_default{debug};
 	my @cmdout = get_cmd_output( @cmd );
 	return p("ERROR: ".@cmdout) if $? && not $IGNOREEXIT;
 
@@ -2284,7 +2275,7 @@ sub search_absolute_path {
 	if ( IS_WIN32 ) {
 		# add a hardcoded prefix for now if relative path (assume relative to local get_iplayer script)
 		if ( $filename !~ m{^[A-Za-z]:} && $filename =~ m{^(\.|\.\.|[A-Za-z])} ) {
-			$filename = dirname( abs_path( $opt_cmdline->{getiplayer} ) ).'/'.$filename;
+			$filename = dirname( abs_path( $opt_default{getiplayer} ) ).'/'.$filename;
 		}
 		# twiddle the / to \
 		$filename =~ s!(\\/|/|\/)!\\!g;
@@ -2298,8 +2289,8 @@ sub search_absolute_path {
 		$abs_path = abs_path($filename);
 
 	# else try dir of get_iplayer
-	} elsif ( -f dirname( abs_path( $opt_cmdline->{getiplayer} ) ).'/'.$filename ) {
-		$abs_path = dirname( abs_path( $opt_cmdline->{getiplayer} ) ).'/'.$filename;
+	} elsif ( -f dirname( abs_path( $opt_default{getiplayer} ) ).'/'.$filename ) {
+		$abs_path = dirname( abs_path( $opt_default{getiplayer} ) ).'/'.$filename;
 
 	# else try dir current output dir option
 	} elsif ( $opt->{OUTPUT}->{current} && -f abs_path( $opt->{OUTPUT}->{current} ).'/'.$filename ) {
@@ -2354,7 +2345,7 @@ sub pvr_queue {
 		$comment =~ s/^_*//g;
 		$comment =~ s/_*$//g;
 		my @cmd = (
-			$opt_cmdline->{getiplayer},
+			$opt_default{getiplayer},
 			'--nocopyright',
 			'--expiry=999999999',
 			'--webrequest',
@@ -2366,7 +2357,7 @@ sub pvr_queue {
 				build_cmd_options( grep !/^(HISTORY|SINCE|BEFORE|HIDEDELETED|FUTURE|SEARCH|SEARCHFIELDS|VERSIONLIST|PROGTYPES|EXCLUDEC.+)$/, @params )
 			),
 		);
-		print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_cmdline->{debug};
+		print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_default{debug};
 		my $cmdout = join "", get_cmd_output( @cmd );
 		return p("ERROR: ".$out) if $? && not $IGNOREEXIT;
 		print $fh p("Queued: $type: '$name - $episode' ($pid)");
@@ -2509,14 +2500,14 @@ sub pvr_add {
 
 	# Remove a few options from leaking into a PVR search
 	my @cmd = (
-		$opt_cmdline->{getiplayer},
+		$opt_default{getiplayer},
 		'--nocopyright',
 		'--expiry=999999999',
 		'--webrequest',
 		get_iplayer_webrequest_args( "pvradd=$searchname", build_cmd_options( grep !/^(HISTORY|HIDEDELETED|SINCE|BEFORE|HIDE|FORCE|FUTURE)$/, @params ) ),
 	);
 	print $se "DEBUG: Command: ".( join ' ', @cmd )."\n";
-	print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_cmdline->{debug};
+	print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_default{debug};
 	$out = join "", get_cmd_output( @cmd );
 	return p("ERROR: ".$out) if $? && not $IGNOREEXIT;
 	print $fh p("Added PVR Search ($searchname):\n\tTypes: $opt->{PROGTYPES}->{current}\n\tSearch: $opt->{SEARCH}->{current}\n\tSearch Fields: $opt->{SEARCHFIELDS}->{current}\n");
@@ -2563,13 +2554,13 @@ sub pvr_save {
 	# Delete the original pvr entry
 	my $searchname = $cgi->param( 'PVRSEARCH' );
 	my @cmd = (
-		$opt_cmdline->{getiplayer},
+		$opt_default{getiplayer},
 		'--nocopyright',
 		'--expiry=999999999',
 		'--webrequest',
 		get_iplayer_webrequest_args( "pvrdel=$searchname" ),
 	);
-	print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_cmdline->{debug};
+	print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_default{debug};
 	my $cmdout = join "", get_cmd_output( @cmd );
 	return p("ERROR: ".$out) if $? && not $IGNOREEXIT;
 	print $fh p("Deleted: $searchname");
@@ -2577,7 +2568,7 @@ sub pvr_save {
 
 	# Add the new pvr entry
 	@cmd = (
-		$opt_cmdline->{getiplayer},
+		$opt_default{getiplayer},
 		'--nocopyright',
 		'--expiry=999999999',
 		'--webrequest',
@@ -2586,7 +2577,7 @@ sub pvr_save {
 		@search_args,
 	);
 	print $se "DEBUG: Command: ".( join ' ', @cmd )."\n";
-	print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_cmdline->{debug};
+	print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_default{debug};
 	$out = join "", get_cmd_output( @cmd );
 	return p("ERROR: ".$out) if $? && not $IGNOREEXIT;
 	print $fh p("Added Updated PVR Search '$newsearchname'\n");
@@ -2731,7 +2722,7 @@ sub refresh {
 	print $fh "<strong><p>The cache will auto-refresh every $opt->{AUTOWEBREFRESH}->{current} hour(s) if you leave this page open</p></strong>" if $opt->{AUTOWEBREFRESH}->{current};
 	print $se "INFO: Refreshing\n";
 	my @cmd = (
-		$opt_cmdline->{getiplayer},
+		$opt_default{getiplayer},
 		'--nocopyright',
 		'--webrequest',
 		get_iplayer_webrequest_args( 'expiry=30', 'nopurge=1', "type=$typelist", "refreshfuture=$refreshfuture", "search=no search just refresh" ),
@@ -3340,7 +3331,7 @@ sub get_progs {
 	push @webrequest_args, "sortmatches=$opt->{SORT}->{current}" if $opt->{SORT}->{current} && $opt->{SORT}->{current} ne 'name';
 	# Run command
 	my @list = get_cmd_output(
-		$opt_cmdline->{getiplayer},
+		$opt_default{getiplayer},
 		'--nocopyright',
 		'--expiry=999999999',
 		'--webrequest',
@@ -3966,7 +3957,6 @@ sub process_params {
 		save	=> 0,
 	};
 
-
 	# Go through each of the options defined above
 	for ( keys %{ $opt } ) {
 		if ( defined $cgi->param($_) && $cgi->param($_) eq '' &&
@@ -3986,15 +3976,15 @@ sub process_params {
 			}
 		} else {
 			if ( defined $cgi->param($_) ) {
-				print $se "DEBUG: GOT Param  $_ = ".$cgi->param($_)."\n" if $opt_cmdline->{debug};
+				print $se "DEBUG: GOT Param  $_ = ".$cgi->param($_)."\n" if $opt_default{debug};
 				$opt->{$_}->{current} = join ",", $cgi->param($_);
 			} elsif (  defined $cgi->cookie($_) ) {
-				print $se "DEBUG: GOT Cookie $_ = ".$cgi->cookie($_)."\n" if $opt_cmdline->{debug};
+				print $se "DEBUG: GOT Cookie $_ = ".$cgi->cookie($_)."\n" if $opt_default{debug};
 				$opt->{$_}->{current} = join ",", $cgi->cookie($_);
 			} else {
 				$opt->{$_}->{current} =  join ",", $opt->{$_}->{default};
 			}
-			print $se "DEBUG: Using $_ = $opt->{$_}->{current}\n--\n" if $opt_cmdline->{debug};
+			print $se "DEBUG: Using $_ = $opt->{$_}->{current}\n--\n" if $opt_default{debug};
 		}
 	}
 }
@@ -4024,7 +4014,7 @@ sub begin_html {
 			my $cookie;
 			if ( $opt->{$_}->{current} ne $opt->{$_}->{default} ) {
 				$cookie = $cgi->cookie( -name=>$_, -value=>$opt->{$_}->{current}, -expires=>'+1y' );
-				print $se "DEBUG: Sending cookie: $cookie\n" if $opt_cmdline->{debug};
+				print $se "DEBUG: Sending cookie: $cookie\n" if $opt_default{debug};
 			} else {
 				$cookie = $cgi->cookie( -name=>$_, -value=>'', -expires=>'-1s' );
 			}
@@ -4048,7 +4038,7 @@ sub begin_html {
 		-charset	=> 'utf-8',
 		-cookie		=> [@cookies],
 	);
-	print $se "\nHEADERS:\n$headers\n" if $opt_cmdline->{debug};
+	print $se "\nHEADERS:\n$headers\n" if $opt_default{debug};
 
 	# Build body element and page title differently depending on the type of page
 	# Load the refresh tab if required
-- 
1.7.4.4

>From fc3cd073e818e5a0f5b396eec44cb8ce2af8e1a5 Mon Sep 17 00:00:00 2001
From: Pete Beardmore <[email protected]>
Date: Mon, 15 Apr 2013 19:39:34 +0100
Subject: [PATCH] web pvr add hideoptions parameter

---
 get_iplayer     |    1 +
 get_iplayer.cgi |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/get_iplayer b/get_iplayer
index 4210e7c..b7f850a 100755
--- a/get_iplayer
+++ b/get_iplayer
@@ -213,6 +213,7 @@ my $opt_format = {
 	skipdeleted	=> [ 1, "skipdeleted!", 'Config', "--skipdeleted", "Skip the download of metadata/thumbs/subs if the media file no longer exists. Use with --history & --metadataonly/subsonly/thumbonly."],
 	update		=> [ 2, "update|u!", 'Config', '--update, -u', "Update get_iplayer if a newer one exists"],
 	webrequest	=> [ 1, "webrequest=s", 'Config', '--webrequest <urlencoded string>', 'Specify all options as a urlencoded string of "name=val&name=val&..."' ],
+	hideoptions	=> [ 1, "hideoptions|hideopts=s", 'Config', '--hideoptions <opt>,<opt>,...', 'List of options whose values should not be made visible in the front-end [webpvr only]"' ],
 
 	# Display
 	conditions	=> [ 1, "conditions!", 'Display', '--conditions', 'Shows GPLv3 conditions'],
diff --git a/get_iplayer.cgi b/get_iplayer.cgi
index f66be88..7c6866a 100755
--- a/get_iplayer.cgi
+++ b/get_iplayer.cgi
@@ -66,6 +66,7 @@ Options:
  --port,-p         Use the built-in web server and listen on this TCP port
  --getiplayer,-g   Path to the get_iplayer script
  --ffmpeg          Path to the ffmpeg binary
+ --hideoptions     List of options whose values should not be made visible
  --debug           Debug mode
  --help,-h         This help text
 EOF
@@ -84,6 +85,7 @@ GetOptions(
 	"port|p=n"			=> \$opt_cmdline{port},
 	"ffmpeg=s"			=> \$opt_cmdline{ffmpeg},
 	"getiplayer|get_iplayer|g=s"	=> \$opt_cmdline{getiplayer},
+	"hideoptions|hideopts=s"	=> \$opt_cmdline{hideoptions},
 	"debug"				=> \$opt_cmdline{debug},
 ) || die usage();
 # Display usage if old method of invocation is used or --help
@@ -189,6 +191,8 @@ my %cols_names = ();
 my %prog;
 my @pids;
 my @displaycols;
+my $hidestring = "-----";
+my $hidesuffix = " | [hidden]";
 
 #### layout ####
 # Options on page tabs
@@ -219,7 +223,7 @@ $layout->{STREAMINGTAB}->{order} = [ qw/ BITRATE VSIZE VFR STREAMTYPE / ];
 
 $layout->{HIDDENTAB}->{title} = '';
 $layout->{HIDDENTAB}->{heading} = '';
-$layout->{HIDDENTAB}->{order} = [ qw/ RESET SAVE SEARCHTAB COLUMNSTAB DISPLAYTAB RECORDINGTAB STREAMINGTAB PAGENO INFO NEXTPAGE ACTION / ];
+$layout->{HIDDENTAB}->{order} = [ qw/ HIDEOPTIONS RESET SAVE SEARCHTAB COLUMNSTAB DISPLAYTAB RECORDINGTAB STREAMINGTAB PAGENO INFO NEXTPAGE ACTION / ];
 
 # Order of displayed tab buttoms (BASICTAB and HIDDEN are always displayed regardless of order)
 $layout->{taborder} = [ qw/ BASICTAB SEARCHTAB DISPLAYTAB COLUMNSTAB RECORDINGTAB STREAMINGTAB HIDDENTAB / ];
@@ -410,6 +414,7 @@ sub set_default_options {
 	$opt_default{listen} = '0.0.0.0';
 	$opt_default{port} = 0;
 	$opt_default{nosearch} = ''; # params that should never get into the get_iplayer pvr-add search
+	$opt_default{hideoptions} = '' if not defined $opt_default{hideoptions};
 	$opt_default{ffmpeg} = 'ffmpeg' if not defined $opt_default{ffmpeg};
 	$opt_default{versionlist} = 'default' if not defined $opt_default{versionlist};
 	$opt_default{search} = '.*' if not defined $opt_default{search};
@@ -430,13 +435,14 @@ sub set_default_options {
 	$opt_default{debug} = $opt_cmdline{debug} if defined $opt_cmdline{debug};
 	$opt_default{listen} = $opt_cmdline{listen} if defined $opt_cmdline{listen};
 	$opt_default{port} = $opt_cmdline{port} if defined $opt_cmdline{port};
+	$opt_default{hideoptions} = $opt_cmdline{hideoptions} if defined $opt_cmdline{hideoptions};
 	$opt_default{ffmpeg} = $opt_cmdline{ffmpeg} if defined $opt_cmdline{ffmpeg};
 }
 
 sub parse_post_form_string {
 	my $form = $_[0];
 	my @data;
-	while ( $form =~ /Content-Disposition:(.+?)--/sg ) {
+	while ( $form =~ /Content-Disposition:(.+?)--+[0-9a-zA-Z]+/sg ) {
 		$_ = $1;
 		# form-data; name = "KEY"
 		m{name.+?"(.+?)"[\n\r\s]*(.+)}sg;
@@ -448,6 +454,7 @@ sub parse_post_form_string {
 		decode_entities($val);
 		# url encode each entry
 		$val =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
+		next if $val eq $hidestring;
 		push @data, "$key=$val";
 	}
 	return join '&', @data;
@@ -2604,6 +2611,7 @@ sub build_option_html {
 	my $current = $arg->{current};
 	my $value = $arg->{value};
 	my $status = $arg->{status};
+	my $hide = ( defined $arg->{hide} && $arg->{hide} == 1 ) ? 1 : 0;
 	my @html;
 
 	# On/Off
@@ -2698,6 +2706,7 @@ sub build_option_html {
 
 	# text field
 	} elsif ( $type eq 'text' ) {
+		$current = $hidestring if $hide; # override for hidden
 		push @html, th( { -class => 'options', -title => $tooltip }, $title ).
 		td( { -class => 'options', -title => $tooltip },
 			textfield(
@@ -2706,6 +2715,7 @@ sub build_option_html {
 				-value		=> $current,
 				-size		=> $value,
 				-onKeyDown	=> 'return submitonEnter(event);',
+				$hide ? ( -disabled => $hide ) : (),
 			)
 		);
 
@@ -3596,6 +3606,7 @@ sub process_params {
 		default	=> $opt_default{modes},
 		value	=> 30, # width values
 		save	=> 1,
+		hide	=> 0,
 		empty	=> 0, # disallow empty string
 	};
 	
@@ -3608,6 +3619,7 @@ sub process_params {
 		default	=> $opt_default{output}, # default
 		value	=> 30, # width values
 		save	=> 1,
+		hide	=> 0,
 	};
 	
 	$opt->{PROXY} = {
@@ -3619,6 +3631,7 @@ sub process_params {
 		default	=> $opt_default{proxy}, # default
 		value	=> 30, # width values
 		save	=> 1,
+		hide	=> 0,
 	};
 	
 	$opt->{VERSIONLIST} = {
@@ -3641,6 +3654,7 @@ sub process_params {
 		default	=> $opt_default{exclude}, # default
 		value	=> 30, # width values
 		save	=> 1,
+		hide	=> 0,
 	};
 
 	$opt->{CATEGORY} = {
@@ -3652,6 +3666,7 @@ sub process_params {
 		default	=> $opt_default{category}, # default
 		value	=> 30, # width values
 		save	=> 1,
+		hide	=> 0,
 	};
 
 	$opt->{EXCLUDECATEGORY} = {
@@ -3663,6 +3678,7 @@ sub process_params {
 		default	=> $opt_default{excludecategory}, # default
 		value	=> 30, # width values
 		save	=> 1,
+		hide	=> 0,
 	};
 
 	$opt->{CHANNEL} = {
@@ -3674,6 +3690,7 @@ sub process_params {
 		default	=> $opt_default{channel}, # default
 		value	=> 30, # width values
 		save	=> 1,
+		hide	=> 0,
 	};
 
 	$opt->{EXCLUDECHANNEL} = {
@@ -3685,6 +3702,7 @@ sub process_params {
 		default	=> $opt_default{excludechannel}, # default
 		value	=> 30, # width values
 		save	=> 1,
+		hide	=> 0,
 	};
 
 	$opt->{HIDE} = {
@@ -3957,8 +3975,27 @@ sub process_params {
 		save	=> 0,
 	};
 
-	# Go through each of the options defined above
+	# hideoptions persistance for 'stateful' web server deployment
+	$opt->{HIDEOPTIONS} = {
+		webvar => 'HIDEOPTIONS',
+		optkey => 'hideoptions',
+		type	=> 'hidden',
+		default	=> $opt_default{hideoptions},
+		save	=> 1,
+	};
+
+	# Go through each of the options defined above and set the 'current' value for display
+	# process any hideoptions first
+	my %hideopts = map { $_ => 1 } split(/,/, $opt->{HIDEOPTIONS}->{default});
+	if ( ! $cgi->param('RESET') && $cgi->param('HIDEOPTIONS') && 
+				$cgi->param('HIDEOPTIONS') ne $opt->{HIDEOPTIONS}->{default} ) {
+		# only shrink to default on explicit reset. merge existing hide options
+		%hideopts = ( %hideopts, map { $_ => 1 } split(/,/, $cgi->param('HIDEOPTIONS')) ); 
+	}
+	$opt->{HIDEOPTIONS}->{current} = join(",", keys %hideopts);
+	$cgi->param('HIDEOPTIONS', $opt->{HIDEOPTIONS}->{current});
 	for ( keys %{ $opt } ) {
+		next if $_ eq "HIDEOPTIONS";
 		if ( defined $cgi->param($_) && $cgi->param($_) eq '' &&
 			defined $opt->{$_}->{empty} && $opt->{$_}->{empty} == 0 ) {
 			$cgi->param($_, $opt->{$_}->{default}); # no empty string allowed for this option
@@ -3986,6 +4023,20 @@ sub process_params {
 			}
 			print $se "DEBUG: Using $_ = $opt->{$_}->{current}\n--\n" if $opt_default{debug};
 		}
+		if ( defined $opt->{$_}->{hide} ) {
+			if ( defined $hideopts{$opt->{$_}->{optkey}} ) { 
+				$opt->{$_}->{current} = $opt_default{$opt->{$_}->{optkey}};
+				$opt->{$_}->{hide} = 1;
+				if ( substr($opt->{$_}->{tooltip}, -length($hidesuffix) ) ne $hidesuffix ) {
+					$opt->{$_}->{tooltip} .= $hidesuffix;
+				}
+			} elsif ( $opt->{$_}->{hide} == 1 ) {
+				$opt->{$_}->{hide} = 0;
+				if ( substr($opt->{$_}->{tooltip}, -length($hidesuffix) ) eq $hidesuffix ) {
+				$opt->{$_}->{tooltip} = substr( $opt->{$_}->{tooltip}, 0, -length( $hidesuffix ) );
+				}
+			}
+		}
 	}
 }
 
@@ -4008,8 +4059,9 @@ sub begin_html {
 	if ( $cgi->param('SAVE') ) {
 		print $se "DEBUG: Sending cookies\n";
 		for ( %{ $opt } ) {
-			# skip if opt not allowed to be saved
-			next if not $opt->{$_}->{save};
+			# skip if opt not allowed to be saved. hard-coded, or hidden
+			next if ( not $opt->{$_}->{save} ||
+								( defined $opt->{$_}->{hide} && $opt->{$_}->{hide} == 1 ) );
 			# ensure cookie for none default settings only
 			my $cookie;
 			if ( $opt->{$_}->{current} ne $opt->{$_}->{default} ) {
-- 
1.7.4.4

_______________________________________________
get_iplayer mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/get_iplayer

Reply via email to