Quoting Pete Beardmore <[email protected]>:

#patch attached (hopefully!)

hi,

as a new user a few months ago i was a little frustrated as i couldn't work out where settings that were used came from. specifically with 'modes', as i wanted HD and it didn't work out of the box.

having tried combinations of 'flashhd,flashhd1,flashhd2' in option files and in the webserver to no avail, i settled on 'best' (having finally resorted to reading instructions!). this was set in my options files under /srv/www/iplayer/.get_iplayer but still, via the web server (be it my apache or the included standalone), i could not get the underlying flvstreamer/rtmpdump processes to behave and show me that attempts at flashhd1 etc. quality streams were being made.

so mistake #1. although the instruction state that one should ensure HOME is set correctly, don't assume that that is for reading any options files which you might have created there (/srv/www/iplayer/get_iplayer/options) whilst trying out the 'get_iplayer' script. the web server doesn't read them!

mistake #2. ALWAYS use the --prefs-add fuctionality to add options to the options file to ensure you get the right format! for example, the entry..

modes 'best,flashhd,flashhd1,flashhd2,flashvhigh'

..f@&Sed me over as i'd add quotes!

anyway. finally i got up and running and so on to the hackery. the attached patch makes the web server work as i want it to with regard to where defaults come from. specifically it:

1. only persists web setting as cookies when none default
2. adds ability to return settings back to defaults
3. bases defaults on get_iplayer option files
4. harmonises defaults structure through single opt_defaults array

use cases:

1. 20+ empty defaults is bad, particularly when i have to scroll through them all to find non get_iplayer related cookies on my (apache) server 2. i wanted to delete all get_iplayer related cookies and go back to the default set of columns 3. i've made the effort to add 'excludecategory' / 'excludechannel' options in my options file, i don't want to change those is multiple places. and if i've set something as important as 'modes' for use with 'get_iplayer' then i really want that same setting used in the web front end 4. specifically modes (originally default_modes) and cols (originally default_headings) which didn't even feature in the original option structure->default mechanism.

hope this is seen as an improvement, in spite of the rather clueless way i happened on requiring the changes :)

cheers

hi all,

apologies to anyone reading the above a second time. the original mail dated Jan 30 made it to the list, but after no feedback in several week a second look has made me realise that i'd broken list rules on html content. try again! if dinkypumpkin or anyone equally as active on the list could formally reject my offerings (if they aren't wanted), then i'd appreciate it so i can move on

since sending the initial patch, i've made a slight change to the button names as i wanted to make a better distinction between the 'persistence' settings mechanisms, and re-iterate that defaults come from files! i now have 'Apply Changes', 'Update Cookies', and 'Reset to Defaults'. a second patch is also appended to this modified patch, and this fixes the issue whereby checkboxes for selected programmes are disabled following an attempted record, instead of merely unselected

cheers,
Pete.

>From ef82520eb6e27308d7af2ffc8f6d8518369f25d1 Mon Sep 17 00:00:00 2001
From: Pete Beardmore <[email protected]>
Date: Wed, 30 Jan 2013 21:42:50 +0000
Subject: [PATCH 1/2] web settings and get_iplayer defaults harmonisation

---
 get_iplayer.cgi |  137 +++++++++++++++++++++++++++++++++----------------------
 1 files changed, 82 insertions(+), 55 deletions(-)

diff --git a/get_iplayer.cgi b/get_iplayer.cgi
index 6bbad3d..d1169c7 100755
--- a/get_iplayer.cgi
+++ b/get_iplayer.cgi
@@ -85,11 +85,8 @@ EOF
 	exit 1;
 }	
 
-
-# Some defaults
-my $default_modes = 'flashaachigh,flashaacstd,flash,realaudio,flashaaclow';
-$opt_cmdline->{listen} = '0.0.0.0' if ! $opt_cmdline->{listen};
-# Search for get_iplayer
+# defaults
+# ensure get_iplayer
 if ( ! $opt_cmdline->{getiplayer} ) {
 	for ( './get_iplayer', './get_iplayer.cmd', './get_iplayer.pl', '/usr/bin/get_iplayer' ) {
 		$opt_cmdline->{getiplayer} = $_ if -x $_;
@@ -99,18 +96,18 @@ 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;
 }
-if ( ! $opt_cmdline->{ffmpeg} ) {
-	chomp(my @ffmpegs = map { s/^\s*ffmpeg\s*=\s*// ? $_ : () } 
-		get_cmd_output(
-			$opt_cmdline->{getiplayer},
-			'--nopurge',
-			'--nocopyright',
-			'--show-options'
-		)
-	);
-	$opt_cmdline->{ffmpeg} = pop @ffmpegs;
-}
-$opt_cmdline->{ffmpeg} = 'ffmpeg' if ! $opt_cmdline->{ffmpeg};
+# source get_iplayer file options
+my %opt_defaults = map { m/.*=+.*/ ? s/^\s*(.*?)\s*=\s*(.*?)\s*\n/\1:\2/ && split ":" : () } 
+  get_cmd_output($opt_cmdline->{getiplayer}, '--nopurge', '--nocopyright', '--show-options');
+# ensure basic defaults
+$opt_defaults{cols} = 'thumbnail,type,name,episode,desc,channel,categories,timeadded';
+$opt_defaults{modes} = 'best' if not defined $opt_defaults{modes};
+$opt_defaults{ffmpeg} = 'ffmpeg' if not defined $opt_defaults{ffmpeg};
+$opt_defaults{listen} = '0.0.0.0' if not defined $opt_defaults{listen};
+
+# ensure cmd defaults
+$opt_cmdline->{listen} = $opt_defaults{listen};
+$opt_cmdline->{ffmpeg} = $opt_defaults{ffmpeg};
 
 # Path to get_iplayer (+ set HOME env var cos apache seems to not set it)
 my $home = $ENV{HOME};
@@ -142,9 +139,6 @@ my @headings = qw(
 	mode
 );
 
-# Default Displayed headings
-my @headings_default = qw( thumbnail type name episode desc channel categories timeadded );
-
 # Lookup table for nice field name headings
 my %fieldname = (
 	index			=> 'Index',
@@ -269,7 +263,7 @@ $layout->{STREAMINGTAB}->{order} = [ qw/ BITRATE VSIZE VFR STREAMTYPE / ];
 
 $layout->{HIDDENTAB}->{title} = '';
 $layout->{HIDDENTAB}->{heading} = '';
-$layout->{HIDDENTAB}->{order} = [ qw/ SAVE SEARCHTAB COLUMNSTAB DISPLAYTAB RECORDINGTAB STREAMINGTAB PAGENO INFO NEXTPAGE ACTION / ];
+$layout->{HIDDENTAB}->{order} = [ qw/ 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 / ];
@@ -822,7 +816,7 @@ sub record_now {
 sub stream_prog {
 	my ( $mimetype, $pid , $type, $modes, $ext, $notranscode, $abitrate, $vsize, $vfr ) = ( @_ );
 	# Default modes to try
-	$modes = $default_modes if ! $modes;
+	$modes = $opt_defaults{modes} if ! $modes;
 	
 	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";
 
@@ -2187,7 +2181,7 @@ sub show_info {
 					{
 						-class => 'action',
 						-title => "Play '$prog{$pid}->{name} - $prog{$pid}->{episode}' Now",
-						-href => build_url_playlist( '', 'playlist', 'pid', $pid, $prog{$pid}->{mode} || $default_modes, $prog{$pid}->{type}, $cgi->param( 'OUTTYPE' ) || 'out.flv', $cgi->param( 'STREAMTYPE' ), $cgi->param( 'BITRATE' ), $cgi->param( 'VSIZE' ), $cgi->param( 'VFR' ) ),
+						-href => build_url_playlist( '', 'playlist', 'pid', $pid, $prog{$pid}->{mode} || $opt_defaults{modes}, $prog{$pid}->{type}, $cgi->param( 'OUTTYPE' ) || 'out.flv', $cgi->param( 'STREAMTYPE' ), $cgi->param( 'BITRATE' ), $cgi->param( 'VSIZE' ), $cgi->param( 'VFR' ) ),
 					},
 					'Play'
 				),
@@ -2879,7 +2873,7 @@ sub search_progs {
 		if ( $pid =~ m{^/} ) {
 			if ( -f $pid ) {
 				# Play
-				$links .= a( { -class=>$search_class, -title=>"Play from file on web server", -href=>build_url_playlist( '', 'playlist', 'pid', $pid, $opt->{MODES}->{current} || $default_modes, $prog{$pid}->{type}, basename( $pid ) , $opt->{STREAMTYPE}->{current}, $opt->{BITRATE}->{current}, $opt->{VSIZE}->{current}, $opt->{VFR}->{current} ) }, 'Play' ).'<br />';
+				$links .= a( { -class=>$search_class, -title=>"Play from file on web server", -href=>build_url_playlist( '', 'playlist', 'pid', $pid, $opt->{MODES}->{current} || $opt_defaults{modes}, $prog{$pid}->{type}, basename( $pid ) , $opt->{STREAMTYPE}->{current}, $opt->{BITRATE}->{current}, $opt->{VSIZE}->{current}, $opt->{VFR}->{current} ) }, 'Play' ).'<br />';
 				# PlayFile
 				$links .= a( { -id=>'nowrap', -class=>$search_class, -title=>"Play from local file", -href=>build_url_playlist( '', 'playlistfiles', 'pid', $pid, $prog{$pid}->{mode}, $prog{$pid}->{type}, undef, undef ) }, 'PlayFile' ).'<br />';
 				# PlayDirect
@@ -2898,7 +2892,7 @@ sub search_progs {
 		# Search mode
 		} else {
 			# Play
-			$links .= a( { -class=>$search_class, -title=>"Play from Internet", -href=>build_url_playlist( '', 'playlist', 'pid', $pid, $opt->{MODES}->{current} || $default_modes, $prog{$pid}->{type}, 'out.flv', $opt->{STREAMTYPE}->{current}, $opt->{BITRATE}->{current}, $opt->{VSIZE}->{current}, $opt->{VFR}->{current} ) }, 'Play' ).'<br />';
+			$links .= a( { -class=>$search_class, -title=>"Play from Internet", -href=>build_url_playlist( '', 'playlist', 'pid', $pid, $opt->{MODES}->{current} || $opt_defaults{modes}, $prog{$pid}->{type}, 'out.flv', $opt->{STREAMTYPE}->{current}, $opt->{BITRATE}->{current}, $opt->{VSIZE}->{current}, $opt->{VFR}->{current} ) }, 'Play' ).'<br />';
 			# Record
 			$links .= label( { -id=>'nowrap', -class=>$search_class, -title=>"Record '$prog{$pid}->{name} - $prog{$pid}->{episode}' Now", -onClick => "BackupFormVars(form); form.NEXTPAGE.value='record_now'; form.SEARCH.value='".encode_entities("$prog{$pid}->{type}|$pid|$prog{$pid}->{name}|$prog{$pid}->{episode}|$prog{$pid}->{mode}")."'; form.target='_newtab_$pid'; form.submit(); RestoreFormVars(form); form.target='';" }, 'Record' ).'<br />';
 			# Queue
@@ -3027,7 +3021,7 @@ sub search_progs {
 		)
 	}
 
-	# add a save button on to end of list
+	# add apply/save/reset buttons to end of list
 	my $options_buttons = ul( { -class=>'options_tab' },
 		li( { -class=>'options_button' }, [
 			# Apply button (same as 'Search')
@@ -3038,7 +3032,7 @@ sub search_progs {
 				},
 				'Apply Settings',
 			),
-			# Save as Default  button
+			# Save as Default button
 			label( {
 				-class		=> 'options_outer pointer_noul',
 				-title		=> 'Remember Current Options as Default',
@@ -3046,6 +3040,14 @@ sub search_progs {
 				},
 				'Save As Default',
 			),
+			# Reset to Defaults button
+			label( {
+				-class		=> 'options_outer pointer_noul',
+				-title		=> 'Reset Current Options to Defaults and Remove Cookies',
+				-onClick	=> "form.NEXTPAGE.value='search_progs'; form.PAGENO.value=1; form.RESET.value=1; form.submit(); RestoreFormVars(form);",
+				},
+				'Reset To Defaults',
+			),
 		] )
 	);
 
@@ -3362,10 +3364,10 @@ sub get_display_cols {
 	my %cols_status;
 
 	# Add some default headings for history mode
-	push @headings_default, 'mode' if $opt->{HISTORY}->{current};
+	push split(/,/, $opt_defaults{cols}), 'mode' if $opt->{HISTORY}->{current};
 
 	# Determine which columns to display (all if $cols not defined)
-	my $cols = join(",", $opt->{COLS}->{current} ) || join ',', @headings_default;
+	my $cols = join(",", $opt->{COLS}->{current} ) || $opt_defaults{cols};
 	my @columns = split /,/, $cols;
 
 	# Re-sort selected display columns into original header order
@@ -3382,7 +3384,7 @@ sub get_display_cols {
 	}
 
 	# Make sure we select all if no cols are specified
-	@displaycols = @headings_default if $#displaycols < 0;
+	@displaycols = split(/,/, $opt_defaults{cols}) if $#displaycols < 0;
 
 	# Set defaults for checkboxes
 	$opt->{COLS}->{status} = \%cols_status;
@@ -3528,7 +3530,7 @@ sub process_params {
 		tooltip	=> 'Select the number of search results displayed on each page', # Tooltip
 		webvar	=> 'PAGESIZE', # webvar
 		type	=> 'popup', # type
-		default	=> 20, # default
+		default	=> 25, # default
 		value	=> ['10','25','50','100','200','400'], # values
 		onChange=> "BackupFormVars(form); form.NEXTPAGE.value='search_progs'; form.PAGENO.value=1; form.submit(); RestoreFormVars(form);",
 		save	=> 1,
@@ -3575,7 +3577,7 @@ sub process_params {
 		webvar	=> 'MODES', # webvar
 		optkey	=> 'modes', # option
 		type	=> 'text', # type
-		default	=> 'flashaachigh,flashaacstd,flashaudio,flashhigh,flashstd,flashnormal,realaudio,flashaaclow', # default
+		default	=> $opt_defaults{modes},
 		value	=> 30, # width values
 		save	=> 1,
 	};
@@ -3586,7 +3588,7 @@ sub process_params {
 		webvar	=> 'OUTPUT', # webvar
 		optkey	=> 'output', # option
 		type	=> 'text', # type
-		default	=> '', # default
+		default	=> $opt_defaults{output}, # default
 		value	=> 30, # width values
 		save	=> 1,
 	};
@@ -3619,7 +3621,7 @@ sub process_params {
 		webvar	=> 'EXCLUDE', # webvar
 		optkey	=> 'exclude', # option
 		type	=> 'text', # type
-		default	=> '', # default
+		default	=> $opt_defaults{exclude}, # default
 		value	=> 30, # width values
 		save	=> 1,
 	};
@@ -3630,7 +3632,7 @@ sub process_params {
 		webvar	=> 'CATEGORY', # webvar
 		optkey	=> 'category', # option
 		type	=> 'text', # type
-		default	=> '', # default
+		default	=> $opt_defaults{category}, # default
 		value	=> 30, # width values
 		save	=> 1,
 	};
@@ -3641,7 +3643,7 @@ sub process_params {
 		webvar	=> 'EXCLUDECATEGORY', # webvar
 		optkey	=> 'excludecategory', # option
 		type	=> 'text', # type
-		default	=> '', # default
+		default	=> $opt_defaults{excludecategory}, # default
 		value	=> 30, # width values
 		save	=> 1,
 	};
@@ -3652,7 +3654,7 @@ sub process_params {
 		webvar	=> 'CHANNEL', # webvar
 		optkey	=> 'channel', # option
 		type	=> 'text', # type
-		default	=> '', # default
+		default	=> $opt_defaults{channel}, # default
 		value	=> 30, # width values
 		save	=> 1,
 	};
@@ -3663,7 +3665,7 @@ sub process_params {
 		webvar	=> 'EXCLUDECHANNEL', # webvar
 		optkey	=> 'excludechannel', # option
 		type	=> 'text', # type
-		default	=> '', # default
+		default	=> $opt_defaults{excludechannel}, '', # default
 		value	=> 30, # width values
 		save	=> 1,
 	};
@@ -3707,7 +3709,7 @@ sub process_params {
 		type	=> 'popup', # type
 		#label	=> \%fieldname, # labels
 		label	=> \%metadata_labels, # labels
-		default	=> '', # default
+		default	=> 'generic', # default
 		value	=> [ ( '', 'xbmc', 'xbmc_movie', 'generic', 'freevo' ) ], # values
 		save	=> 1,
 	};
@@ -3718,7 +3720,7 @@ sub process_params {
 		webvar	=> 'SUBTITLES', # webvar
 		optkey	=> 'subtitles', # option
 		type	=> 'radioboolean', # type
-		default	=> '0', # value
+		default	=> 1, # value
 		save	=> 1,
 	};
 
@@ -3728,7 +3730,7 @@ sub process_params {
 		webvar	=> 'THUMB', # webvar
 		optkey	=> 'thumb', # option
 		type	=> 'radioboolean', # type
-		default	=> '0', # value
+		default	=> 1, # value
 		save	=> 1,
 	};
 
@@ -3865,13 +3867,14 @@ sub process_params {
 	$opt->{COLS} = {
 		title	=> 'Enable Columns', # Title
 		tooltip	=> 'Select the columns you wish to display', # Tooltip
-		webvar	=> 'COLS', # webvar
+		webvar => 'COLS', # webvar
 		#optkey	=> 'type', # option
-		type	=> 'multiboolean', # type
+		type => 'multiboolean', # type
 		label	=> \%cols_names, # labels
 		#status	=> \%cols_status, # default status
 		value	=> \%cols_order, # order of values
-		save	=> 1,
+		default => $opt_defaults{cols}, 
+		save => 1,
 	};
 
 	# Make sure we go to the correct nextpage for processing
@@ -3919,6 +3922,14 @@ sub process_params {
 		save	=> 0,
 	};
 
+	# Reset the Advanced Search options and preferences settings to defaults / remove cookies
+	$opt->{RESET} = {
+		webvar	=> 'RESET', # webvar
+		type	=> 'hidden', # type
+		default	=> '0', # value
+		save	=> 0,
+	};
+
 	# INFO for page info if clicked
 	$opt->{INFO} = {
 		webvar  => 'INFO',
@@ -3930,8 +3941,13 @@ sub process_params {
 
 	# Go through each of the options defined above
 	for ( keys %{ $opt } ) {
-		# Ignore cookies if we are saving new ones
-		if ( not $cgi->param('SAVE') ) {
+		if ( $cgi->param('SAVE') ) {
+	  		# Ignore cookies if we are saving new ones
+			$opt->{$_}->{current} = join(",", $cgi->param($_) ) || $opt->{$_}->{default} if not defined $opt->{$_}->{current};
+		} elsif ( $cgi->param('RESET') ) {
+ 	  		# Set current back to default
+     		$opt->{$_}->{current} = $opt->{$_}->{default}; 
+		} else {
 			if ( defined $cgi->param($_) ) {
 				print $se "DEBUG: GOT Param  $_ = ".$cgi->param($_)."\n" if $opt_cmdline->{debug};
 				$opt->{$_}->{current} = join ",", $cgi->param($_);
@@ -3942,10 +3958,7 @@ sub process_params {
 				$opt->{$_}->{current} =  join ",", $opt->{$_}->{default};
 			}
 			print $se "DEBUG: Using $_ = $opt->{$_}->{current}\n--\n" if $opt_cmdline->{debug};
-			
-		} else {
-			$opt->{$_}->{current} = join(",", $cgi->param($_) ) || $opt->{$_}->{default} if not defined $opt->{$_}->{current};
-		}
+		} 
 	}
 }
 
@@ -3963,20 +3976,34 @@ sub begin_html {
 	my $request_host = shift;
 	my $mimetype = 'text/html';
 	
-	# Save settings if selected
+	# save or reset settings
 	my @cookies;
 	if ( $cgi->param('SAVE') ) {
 		print $se "DEBUG: Sending cookies\n";
 		for ( %{ $opt } ) {
-			# skip if opt not allowed to be saved
+			# skip if opt not allowed to be saved 
 			next if not $opt->{$_}->{save};
-			my $cookie = $cgi->cookie( -name=>$_, -value=>$opt->{$_}->{current}, -expires=>'+1y' );
+			# ensure cookie for none default settings only
+			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};
+			} else {
+				$cookie = $cgi->cookie( -name=>$_, -value=>'', -expires=>'-1s' );
+			}
 			push @cookies, $cookie;
-			print $se "DEBUG: Sending cookie: $cookie\n" if $opt_cmdline->{debug};
 		}
 		# Ensure SAVE state is reset to off
 		$opt->{SAVE}->{current} = 0;
-	}
+	} elsif ( $cgi->param('RESET') ) {
+		print $se "DEBUG: Deleting cookies\n";
+		for ( %{ $opt } ) {
+			my $cookie = $cgi->cookie( -name=>$_, -value=>'', -expires=>'-1s' );
+			push @cookies, $cookie;
+		}
+		# Ensure RESET state is reset to off
+		$opt->{RESET}->{current} = 0;
+	} 
 
 	# Send the headers to the browser
 	my $headers = $cgi->header(
-- 
1.7.4.4


>From e9afba538184eab45d99526b157289bcf2350c01 Mon Sep 17 00:00:00 2001
From: Pete Beardmore <[email protected]>
Date: Wed, 6 Feb 2013 11:28:49 +0000
Subject: [PATCH 2/2] web settings and get_iplayer defaults harmonisation #2

---
 get_iplayer.cgi |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/get_iplayer.cgi b/get_iplayer.cgi
index d1169c7..b7fc5bb 100755
--- a/get_iplayer.cgi
+++ b/get_iplayer.cgi
@@ -3021,7 +3021,7 @@ sub search_progs {
 		)
 	}
 
-	# add apply/save/reset buttons to end of list
+	# add apply/store/reset buttons to end of list
 	my $options_buttons = ul( { -class=>'options_tab' },
 		li( { -class=>'options_button' }, [
 			# Apply button (same as 'Search')
@@ -3030,15 +3030,15 @@ sub search_progs {
 				-title		=> 'Apply Current Options',
 				-onClick	=> "BackupFormVars(form); form.NEXTPAGE.value='search_progs'; form.PAGENO.value=1; form.submit(); RestoreFormVars(form);",
 				},
-				'Apply Settings',
+				'Apply Changes',
 			),
-			# Save as Default button
+			# Update Cookies button
 			label( {
 				-class		=> 'options_outer pointer_noul',
 				-title		=> 'Remember Current Options as Default',
 				-onClick	=> "BackupFormVars(form); form.SAVE.value=1; form.submit(); RestoreFormVars(form);",
 				},
-				'Save As Default',
+				'Update Cookies',
 			),
 			# Reset to Defaults button
 			label( {
-- 
1.7.4.4

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

Reply via email to