>From ef82520eb6e27308d7af2ffc8f6d8518369f25d1 Mon Sep 17 00:00:00 2001 From: Pete Beardmore 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' ).'
'; + $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' ).'
'; # 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 @@ -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' ).'
'; + $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' ).'
'; # 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 @@ -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 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