From 1555ceddbd1b13c7fd2919632e45a2b7496af993 Mon Sep 17 00:00:00 2001 From: notnac <32044623+notnac@users.noreply.github.com> Date: Sat, 5 Jan 2019 02:06:37 +0000 Subject: [PATCH] Do not refresh or use cache with --pid by default Use new --pid-index option to refresh and use cache with --pid --- get_iplayer | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/get_iplayer b/get_iplayer index b581bbcb..7f7a4301 100755 --- a/get_iplayer +++ b/get_iplayer @@ -97,6 +97,7 @@ my $opt_format = { partialproxy => [ 1, "partial-proxy!", 'Recording', '--partial-proxy', "Only uses web proxy where absolutely required (try this extra option if your proxy fails)."], _url => [ 2, "", 'Recording', '--url ,,...', "Record the PIDs contained in the specified iPlayer episode URLs."], pid => [ 2, "pid|url=s@", 'Recording', '--pid ,,...', "Record arbitrary PIDs that do not necessarily appear in the index."], + pidindex => [ 1, "pidrefresh|pid-refresh|pidindex|pid-index!", 'Recording', '--pid-index', "Update (if necessary) and use programme index cache with --pid. Cache is not searched for programme by default with --pid. Synonym: --pid-refresh."], pidrecursive => [ 1, "pidrecursive|pid-recursive!", 'Recording', '--pid-recursive', "Record all related episodes if value of --pid is a series or brand PID. Requires --pid."], pidrecursivelist => [ 1, "pidrecursivelist|pid-recursive-list!", 'Recording', '--pid-recursive-list', "If value of --pid is a series or brand PID, list available episodes but do not download. Implies --pid-recursive. Requires --pid."], proxy => [ 0, "proxy|p=s", 'Recording', '--proxy, -p ', "Web proxy URL, e.g., http://username:password\@server:port or http://server:port. Value of http_proxy environment variable (if present) will be used unless --proxy is specified. Used for both HTTP and HTTPS. Overridden by --no-proxy."], @@ -443,7 +444,7 @@ logger Options->copyright_notice if not $opt->{nocopyright}; if ( $opt->{verbose} ) { my $ct = time(); - logger "INFO: Start: ".(strftime('%Y-%m-%dT%H:%M:%S+00:00', gmtime($ct)))." ($ct)\n"; + logger "INFO: Start: ".(strftime('%Y-%m-%dT%H:%M:%S', localtime($ct)))." ($ct)\n"; # show encodings in use logger "INFO: $_ = $opt->{$_}\n" for @encoding_opts; logger "INFO: \${^UNICODE} = ${^UNICODE}\n" if $opt->{verbose}; @@ -844,10 +845,6 @@ sub find_pid_matches { my %ep_types; my ( $type, $prog, $index_prog ) = init_search(); my $now = time(); - # load caches from file only - for my $t ( progclass() ) { - get_links( $prog, $index_prog, $t, 1, $now ); - } for my $opt_pid ( @opt_pids ) { my $opt_type = "tv"; # If $pid is in the form of ':' and is a valid type @@ -863,6 +860,15 @@ sub find_pid_matches { $ep_seen{$ep->{pid}} = 1; next if ( $opt->{hide} && ! $opt->{force} && $hist->check( $ep->{pid}, 1 ) ); $ep_types{$ep->{type}} = 1 unless $ep_types{$ep->{type}}; + push @ep_list, $ep; + } + } + if ( $opt->{pidindex} ) { + for my $t ( keys %ep_types ) { + get_links( $prog, $index_prog, $t, 0, $now ); + } + } + for my $ep ( @ep_list ) { my $this; if ( $prog->{$ep->{pid}}->{pid} ) { $this = $prog->{$ep->{pid}}; @@ -870,33 +876,24 @@ sub find_pid_matches { $this = $ep; } push @match_list, $this; - push @ep_list, $ep; - } - } - unless ( @match_list ) { - main::logger "INFO: 0 total programmes\n"; - return; } - if ( @ep_list ) { + if ( @match_list ) { my $show_type = keys %ep_types > 1; if ( $opt->{sortreverse} ) { - @ep_list = reverse @ep_list; + @match_list = reverse @match_list; } main::logger "Episodes:\n"; - for my $ep ( @ep_list ) { + for my $ep ( @match_list ) { my $ep_desc = " - $ep->{desc}" if $opt->{long} && $ep->{desc}; my $ep_type = "$ep->{type}, " if $show_type; main::logger "${ep_type}$ep->{name} - $ep->{episode}, $ep->{channel}, $ep->{pid}${ep_desc}\n"; } } - main::logger "INFO: ".(scalar @ep_list)." total programmes\n"; + main::logger "INFO: ".(scalar @match_list)." total programmes\n"; # return empty list if not downloading if ( $opt->{pidrecursivelist} ) { return; } - if ( $opt->{sortreverse} ) { - @match_list = reverse @match_list; - } return @match_list; } @@ -5103,7 +5100,7 @@ sub fetch_pid_info { $prog_episode = $doc->{programme}->{display_title}->{subtitle}; $prog_channel = $doc->{programme}->{ownership}->{service}->{title}; $prog_desc = $doc->{programme}->{short_synopsis}; - if ( $prog_episode =~ s/(Series \d+)[, :]+// ) { + if ( $prog_episode =~ s/((?:Series|Cyfres) \d+)[, :]+// ) { $prog_name .= ": $1"; } } else { @@ -5154,7 +5151,7 @@ sub fetch_episodes_recursive { next if $seen{$pid}; $seen{$pid} = 1; my $prog_episode = $episode->findvalue('.//span[contains(@class,"programme__title")]/span'); - my $name2 = $episode->findvalue('.//span[contains(@class,"programme__subtitle")]/span/span'); + my $name2 = $episode->findvalue('.//span[contains(@class,"programme__subtitle")]/span'); my $prog_name = $name2 ? "$title: $name2" : $title; my $prog_desc = $episode->findvalue('.//p[contains(@class,"programme__synopsis")]/span'); unless ( $name2 ) {