>From 9595e5be38d025abd6c5307a4388e58908b4986d Mon Sep 17 00:00:00 2001 From: Pete Beardmore Date: Sun, 14 Apr 2013 15:13:13 +0100 Subject: [PATCH] web settings and get_iplayer defaults harmonisation --- get_iplayer | 1 + get_iplayer.cgi | 247 ++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 153 insertions(+), 95 deletions(-) diff --git a/get_iplayer b/get_iplayer index 5451ac9..4210e7c 100755 --- a/get_iplayer +++ b/get_iplayer @@ -142,6 +142,7 @@ my $opt_format = { thumbonly => [ 1, "thumbonly|thumbnailonly|thumbnail-only|thumb-only!", 'Recording', '--thumbnail-only', "Only Download Thumbnail image if available, not the programme"], aactomp3 => [ 1, "aactomp3", 'Recording', '--aactomp3', "Transcode AAC audio to MP3 with ffmpeg (CBR 128k unless --mp3vbr is specified)"], mp3vbr => [ 1, "mp3vbr=n", 'Recording', '--mp3vbr', "Set LAME VBR mode to N (0 to 9) for AAC transcoding. 0 = target bitrate 245 Kbit/s, 9 = target bitrate 65 Kbit/s (requires --aactomp3)"], + holdoff => [ 1, "holdoff=n", 'Recording', '--before', "Wait this number of hours before allowing the PVR to record a programme [webpvr only]"], # Search before => [ 1, "before=n", 'Search', '--before', "Limit search to programmes added to the cache before N hours ago"], diff --git a/get_iplayer.cgi b/get_iplayer.cgi index e41cb54..1b335dc 100755 --- a/get_iplayer.cgi +++ b/get_iplayer.cgi @@ -85,11 +85,7 @@ 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 +# 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 +95,6 @@ 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}; # Path to get_iplayer (+ set HOME env var cos apache seems to not set it) my $home = $ENV{HOME}; @@ -142,9 +126,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', @@ -236,9 +217,10 @@ my %nextpages = ( 'update_script' => \&update_script, ); - - -##### Options ##### +# default options +my %opt_default; +set_default_options(); +# state options my $opt; # Options Layout on page tabs @@ -269,20 +251,17 @@ $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 / ]; -# Any params that should never get into the get_iplayer pvr-add search -my @nosearch_params = qw/ /; - ### Perl CGI Web Server ### use Socket; use IO::Socket; my $IGNOREEXIT = 0; # If the port number is specified then run embedded web server -if ( $opt_cmdline->{port} > 0 ) { +if ( $opt_default{port} > 0 ) { # Autoreap zombies $SIG{CHLD} = 'IGNORE'; # Need this because with $SIG{CHLD} = 'IGNORE', backticks and systems calls always return -1 @@ -291,14 +270,14 @@ if ( $opt_cmdline->{port} > 0 ) { # Setup and create socket my $server = new IO::Socket::INET( Proto => 'tcp', - LocalAddr => $opt_cmdline->{listen}, - LocalPort => $opt_cmdline->{port}, + LocalAddr => $opt_default{listen}, + LocalPort => $opt_default{port}, Listen => SOMAXCONN, Reuse => 1, ); $server or die "Unable to create server socket: $!"; - print $se "INFO: Listening on $opt_cmdline->{listen}:$opt_cmdline->{port}\n"; - print $se "WARNING: Insecure Remote access is allowed, use --listen=127.0.0.1 to limit to this host only\n" if $opt_cmdline->{listen} ne '127.0.0.1'; + print $se "INFO: Listening on $opt_default{listen}:$opt_default{port}\n"; + print $se "WARNING: Insecure Remote access is allowed, use --listen=127.0.0.1 to limit to this host only\n" if $opt_default{listen} ne '127.0.0.1'; # Await requests and handle them as they arrive while (my $client = $server->accept()) { my $procid = fork(); @@ -366,12 +345,14 @@ if ( $opt_cmdline->{port} > 0 ) { # remove any vars that might affect the CGI #%ENV = (); @ARGV = (); + # ensure default options in forks + set_default_options() if defined $query_string; # Setup CGI http vars print $se "QUERY_STRING = $query_string\n" if defined $query_string; $ENV{'QUERY_STRING'} = $query_string; $ENV{'REQUEST_URI'} = $request{URL}; $ENV{'COOKIE'} = $request{cookie}; - $ENV{'SERVER_PORT'} = $opt_cmdline->{port}; + $ENV{'SERVER_PORT'} = $opt_default{port}; # respond OK to browser print $client "HTTP/1.1 200 OK", Socket::CRLF; # Invoke CGI @@ -430,7 +411,35 @@ sub cleanup { exit 0; } - +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')); + # ensure defaults + $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{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}; + $opt_default{fields} = 'name' if not defined $opt_default{fields}; + $opt_default{type} = 'tv' if not defined $opt_default{type}; + $opt_default{history} = 0 if not defined $opt_default{history}; + $opt_default{hide} = 0 if not defined $opt_default{hide}; + $opt_default{pagesize} = 25 if not defined $opt_default{pagesize}; + $opt_default{cols} = 'thumbnail,type,name,episode,desc,channel,categories,timeadded'; + $opt_default{modes} = 'flashaachigh,flashaacstd,flashaudio,flashhigh,flashstd,flashnormal,realaudio,flashaaclow' if not defined $opt_default{modes}; + $opt_default{subtitles} = 0 if not defined $opt_default{subtitles}; + $opt_default{thumb} = 0 if not defined $opt_default{thumb}; + $opt_default{force} = 0 if not defined $opt_default{force}; + $opt_default{autowebrefresh} = 1 if not defined $opt_default{autowebrefresh}; + $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}; +} sub parse_post_form_string { my $form = $_[0]; @@ -822,7 +831,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_default{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"; @@ -966,7 +975,7 @@ sub build_ffmpeg_args { } @cmd = ( - $opt_cmdline->{ffmpeg}, + $opt_default{ffmpeg}, #'-f', $src_ext, # not required? '-i', $filename, @cmd_aopts, @@ -977,7 +986,7 @@ sub build_ffmpeg_args { # Audio } else { @cmd = ( - $opt_cmdline->{ffmpeg}, + $opt_default{ffmpeg}, #'-f', $src_ext, # not required? '-i', $filename, '-vn', @@ -2194,7 +2203,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_default{modes}, $prog{$pid}->{type}, $cgi->param( 'OUTTYPE' ) || 'out.flv', $cgi->param( 'STREAMTYPE' ), $cgi->param( 'BITRATE' ), $cgi->param( 'VSIZE' ), $cgi->param( 'VFR' ) ), }, 'Play' ), @@ -2452,8 +2461,11 @@ sub build_cmd_options { for ( @_ ) { # skip non-options next if $opt->{$_}->{optkey} eq '' || not defined $opt->{$_}->{optkey} || not $opt->{$_}->{optkey}; - my $value = $opt->{$_}->{current}; - push @options, "$opt->{$_}->{optkey}=$value" if $value ne ''; + my $option = "$opt->{$_}->{optkey}=$opt->{$_}->{current}" if $opt->{$_}->{current} ne ''; + # overrides + $option =~ s/^holdoff/before/; + # add option + push @options, $option if $option ne ''; } return @options; } @@ -2465,7 +2477,7 @@ sub get_search_params { for ( keys %{ $opt } ) { # skip non-options next if $opt->{$_}->{optkey} eq '' || not defined $opt->{$_}->{optkey} || not $opt->{$_}->{optkey}; - next if grep /^$_$/, @nosearch_params; + next if grep /^$_$/, split(/,/, $opt_default{nosearch}); push @params, $_; } return @params; @@ -2886,7 +2898,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' ).'
'; + $links .= a( { -class=>$search_class, -title=>"Play from file on web server", -href=>build_url_playlist( '', 'playlist', 'pid', $pid, $opt->{MODES}->{current} || $opt_default{modes}, $prog{$pid}->{type}, basename( $pid ) , $opt->{STREAMTYPE}->{current}, $opt->{BITRATE}->{current}, $opt->{VSIZE}->{current}, $opt->{VFR}->{current} ) }, 'Play' ).'
'; # 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' ).'
'; # PlayDirect @@ -2905,7 +2917,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' ).'
'; + $links .= a( { -class=>$search_class, -title=>"Play from Internet", -href=>build_url_playlist( '', 'playlist', 'pid', $pid, $opt->{MODES}->{current} || $opt_default{modes}, $prog{$pid}->{type}, 'out.flv', $opt->{STREAMTYPE}->{current}, $opt->{BITRATE}->{current}, $opt->{VSIZE}->{current}, $opt->{VFR}->{current} ) }, 'Play' ).'
'; # 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' ).'
'; # Queue @@ -3034,7 +3046,7 @@ sub search_progs { ) } - # add a save button on 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') @@ -3043,15 +3055,23 @@ 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', + -title => 'Save Current Non-Default Options as Cookies', -onClick => "BackupFormVars(form); form.SAVE.value=1; form.submit(); RestoreFormVars(form);", }, - 'Save As Default', + 'Update Cookies', + ), + # Reset to Defaults button + label( { + -class => 'options_outer pointer_noul', + -title => 'Clear Cookies and Reset Current Options to Defaults', + -onClick => "form.NEXTPAGE.value='search_progs'; form.PAGENO.value=1; form.RESET.value=1; form.submit(); BackupFormVars(form);", + }, + 'Reset to Defaults', ), ] ) ); @@ -3108,7 +3128,7 @@ sub search_progs { { -class => 'action', -title => 'Queue selected programmes (or Quick URL) for one-off recording', - -onClick => "if(! ( check_if_selected(document.form, 'PROGSELECT') || form.URL.value ) ) { alert('No Quick URL or programmes were selected'); return false; } BackupFormVars(form); form.SEARCH.value=''; form.NEXTPAGE.value='pvr_queue'; form.submit(); RestoreFormVars(form); form.URL.value=''; checkbox_toggle(document.form, 'PROGSELECT');", + -onClick => "if(! ( check_if_selected(document.form, 'PROGSELECT') || form.URL.value ) ) { alert('No Quick URL or programmes were selected'); return false; } BackupFormVars(form); form.SEARCH.value=''; form.NEXTPAGE.value='pvr_queue'; form.submit(); RestoreFormVars(form); form.URL.value=''; check_toggle(document.form, 'PROGSELECT');", }, 'Queue' ); @@ -3116,7 +3136,7 @@ sub search_progs { { -class => 'action', -title => 'Immediately Record selected programmes (or Quick URL) in a new tab', - -onClick => "if(! ( check_if_selected(document.form, 'PROGSELECT') || form.URL.value ) ) { alert('No Quick URL or programmes were selected'); return false; } BackupFormVars(form); form.SEARCH.value=''; form.NEXTPAGE.value='record_now'; var random=Math.floor(Math.random()*99999); form.target='_newtab_'+random; form.submit(); RestoreFormVars(form); form.target=''; form.URL.value=''; checkbox_toggle(document.form, 'PROGSELECT');", + -onClick => "if(! ( check_if_selected(document.form, 'PROGSELECT') || form.URL.value ) ) { alert('No Quick URL or programmes were selected'); return false; } BackupFormVars(form); form.SEARCH.value=''; form.NEXTPAGE.value='record_now'; var random=Math.floor(Math.random()*99999); form.target='_newtab_'+random; form.submit(); RestoreFormVars(form); form.target=''; form.URL.value=''; check_toggle(document.form, 'PROGSELECT');", }, 'Record' ); @@ -3368,14 +3388,12 @@ sub get_display_cols { # Set default status for columns options tab checkboxes my %cols_status; - # Add some default headings for history mode - push @headings_default, '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 @columns = split /,/, $cols; + # set columns to display, add to default headings for history mode + my $cols = join(",", $opt->{COLS}->{current} ) || + join(",", $opt_default{cols}, $opt->{HISTORY}->{current} ? 'mode' : ''); # Re-sort selected display columns into original header order + my @columns = split /,/, $cols; for my $heading (@headings) { if ( grep /^$heading$/, @columns ) { # Remove display of mode and filename if not history mode @@ -3389,7 +3407,7 @@ sub get_display_cols { } # Make sure we select all if no cols are specified - @displaycols = @headings_default if $#displaycols < 0; + @displaycols = split(/,/, $opt_default{cols}) if $#displaycols < 0; # Set defaults for checkboxes $opt->{COLS}->{status} = \%cols_status; @@ -3503,7 +3521,7 @@ sub process_params { webvar => 'SEARCH', # webvar optkey => 'search', # option key type => 'text', # type - default => '.*', # default + default => $opt_default{search}, # default value => 20, # width values save => 0, }; @@ -3512,8 +3530,9 @@ sub process_params { title => 'Quick URL', # Title tooltip => "Enter your URL for Recording (then click 'Record' or 'Play')", # Tooltip webvar => 'URL', # webvar + optkey => 'url', # option key type => 'text', # type - default => '', # default + default => $opt_default{url}, # default value => 36, # width values save => 0, }; @@ -3525,7 +3544,7 @@ sub process_params { optkey => 'fields', # option type => 'popup', # type label => \%fieldname, # labels - default => 'name', # default + default => $opt_default{fields}, # default value => [ (@headings,'name,episode','name,episode,desc') ], # values save => 1, }; @@ -3534,8 +3553,9 @@ sub process_params { title => 'Programmes per Page', # Title tooltip => 'Select the number of search results displayed on each page', # Tooltip webvar => 'PAGESIZE', # webvar + optkey => 'pagesize', # option type => 'popup', # type - default => 20, # default + default => $opt_default{pagesize}, # 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, @@ -3570,7 +3590,7 @@ sub process_params { optkey => 'type', # option type => 'multiboolean', # type label => \%prog_types, # labels - default => 'tv', + default => $opt_default{type}, #status => \%type, # default status value => \%prog_types_order, # order of values save => 1, @@ -3582,18 +3602,19 @@ sub process_params { webvar => 'MODES', # webvar optkey => 'modes', # option type => 'text', # type - default => 'flashaachigh,flashaacstd,flashaudio,flashhigh,flashstd,flashnormal,realaudio,flashaaclow', # default + default => $opt_default{modes}, value => 30, # width values save => 1, + empty => 0, # disallow empty string }; $opt->{OUTPUT} = { - title => 'Override Recordings Folder', # Title + title => 'Output Folder', # Title tooltip => 'Folder on the server where recordings should be saved', # Tooltip webvar => 'OUTPUT', # webvar optkey => 'output', # option type => 'text', # type - default => '', # default + default => $opt_default{output}, # default value => 30, # width values save => 1, }; @@ -3604,7 +3625,7 @@ sub process_params { webvar => 'PROXY', # webvar optkey => 'proxy', # option type => 'text', # type - default => '', # default + default => $opt_default{proxy}, # default value => 30, # width values save => 1, }; @@ -3615,7 +3636,7 @@ sub process_params { webvar => 'VERSIONLIST', # webvar optkey => 'versionlist', # option type => 'text', # type - default => 'default', # default + default => $opt_default{versionlist}, # default value => 30, # width values save => 1, }; @@ -3626,7 +3647,7 @@ sub process_params { webvar => 'EXCLUDE', # webvar optkey => 'exclude', # option type => 'text', # type - default => '', # default + default => $opt_default{exclude}, # default value => 30, # width values save => 1, }; @@ -3637,7 +3658,7 @@ sub process_params { webvar => 'CATEGORY', # webvar optkey => 'category', # option type => 'text', # type - default => '', # default + default => $opt_default{category}, # default value => 30, # width values save => 1, }; @@ -3648,7 +3669,7 @@ sub process_params { webvar => 'EXCLUDECATEGORY', # webvar optkey => 'excludecategory', # option type => 'text', # type - default => '', # default + default => $opt_default{excludecategory}, # default value => 30, # width values save => 1, }; @@ -3659,7 +3680,7 @@ sub process_params { webvar => 'CHANNEL', # webvar optkey => 'channel', # option type => 'text', # type - default => '', # default + default => $opt_default{channel}, # default value => 30, # width values save => 1, }; @@ -3670,7 +3691,7 @@ sub process_params { webvar => 'EXCLUDECHANNEL', # webvar optkey => 'excludechannel', # option type => 'text', # type - default => '', # default + default => $opt_default{excludechannel}, # default value => 30, # width values save => 1, }; @@ -3681,7 +3702,7 @@ sub process_params { webvar => 'HIDE', # webvar optkey => 'hide', # option type => 'radioboolean', # type - default => '0', # value + default => $opt_default{hide}, # value save => 1, }; @@ -3691,7 +3712,7 @@ sub process_params { webvar => 'FORCE', # webvar optkey => 'force', # option type => 'radioboolean', # type - default => '0', # value + default => $opt_default{force}, # value save => 1, }; @@ -3701,7 +3722,7 @@ sub process_params { webvar => 'REFRESHFUTURE', # webvar optkey => 'refreshfuture', # option type => 'radioboolean', # type - default => '0', # value + default => $opt_default{refreshfuture}, # value save => 1, }; @@ -3714,7 +3735,7 @@ sub process_params { type => 'popup', # type #label => \%fieldname, # labels label => \%metadata_labels, # labels - default => '', # default + default => $opt_default{metadata}, # default value => [ ( '', 'xbmc', 'xbmc_movie', 'generic', 'freevo' ) ], # values save => 1, }; @@ -3725,7 +3746,7 @@ sub process_params { webvar => 'SUBTITLES', # webvar optkey => 'subtitles', # option type => 'radioboolean', # type - default => '0', # value + default => $opt_default{subtitles}, # value save => 1, }; @@ -3735,7 +3756,7 @@ sub process_params { webvar => 'THUMB', # webvar optkey => 'thumb', # option type => 'radioboolean', # type - default => '0', # value + default => $opt_default{thumb}, # value save => 1, }; @@ -3743,8 +3764,9 @@ sub process_params { title => 'Auto-Refresh Cache Interval', # Title tooltip => 'Automatically refresh the default caches in another browser tab (hours)', # Tooltip webvar => 'AUTOWEBREFRESH', # webvar + optkey => 'autowebrefresh', # option type => 'text', # type - default => 1, # default + default => $opt_default{autowebrefresh}, # default value => 3, # width values save => 1, }; @@ -3753,8 +3775,9 @@ sub process_params { title => 'Auto-Run PVR Interval', # Title tooltip => 'Automatically run the PVR in another browser tab (hours)', # Tooltip webvar => 'AUTOPVRRUN', # webvar + optkey => 'autopvrrun', # option type => 'text', # type - default => 4, # default + default => $opt_default{autopvrrun}, # default value => 3, # width values save => 1, }; @@ -3765,7 +3788,7 @@ sub process_params { webvar => 'HISTORY', # webvar optkey => 'history', # option type => 'boolean', # type - default => '0', # value + default => $opt_default{history}, # value save => 0, }; @@ -3786,7 +3809,7 @@ sub process_params { optkey => 'since', # option type => 'text', # type value => 3, # width values - default => '', + default => $opt_default{since}, save => 1, }; @@ -3797,7 +3820,7 @@ sub process_params { optkey => 'before', # option type => 'text', # type value => 3, # width values - default => '', + default => $opt_default{before}, save => 1, }; @@ -3805,10 +3828,10 @@ sub process_params { title => 'PVR Hold off period (hours)', # Title tooltip => 'Wait this number of hours before allowing the PVR to record a programme. This sometimes helps when the flashhd version is delayed in being made available.', # Tooltip webvar => 'PVRHOLDOFF', # webvar - optkey => 'before', # option + optkey => 'holdoff', # option type => 'text', # type value => 3, # width values - default => '', + default => $opt_default{holdoff}, save => 1, }; @@ -3878,6 +3901,7 @@ sub process_params { label => \%cols_names, # labels #status => \%cols_status, # default status value => \%cols_order, # order of values + default => $opt_default{cols}, save => 1, }; @@ -3905,7 +3929,7 @@ sub process_params { save => 0, }; - # Remeber the status of the tab options display + # Remember the status of the tab options display for my $tabname ( grep !/BASICTAB/, @{ $layout->{taborder} } ) { my $default = 'no'; # By default only show advanced search tab @@ -3926,6 +3950,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', @@ -3937,8 +3969,22 @@ 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 ( defined $cgi->param($_) && $cgi->param($_) eq '' && + defined $opt->{$_}->{empty} && $opt->{$_}->{empty} == 0 ) { + $cgi->param($_, $opt->{$_}->{default}); # no empty string allowed for this option + } + 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 + if ( $_ =~ m/ACTION|PAGENO|NEXTPAGE|TAB|RESET|SAVE$/ ) { + $opt->{$_}->{current} = $cgi->param($_) if defined $cgi->param($_); + } else { + $cgi->param($_, $opt->{$_}->{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($_); @@ -3949,9 +3995,6 @@ 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}; } } } @@ -3969,20 +4012,34 @@ sub process_params { 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 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 -- 1.7.4.4