Skip to content

Commit

Permalink
Do not refresh or use cache with --pid by default
Browse files Browse the repository at this point in the history
Use new --pid-index option to refresh and use cache with --pid
  • Loading branch information
notnac committed Feb 24, 2019
1 parent b8e2bf0 commit 1555ced
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions get_iplayer
Original file line number Diff line number Diff line change
Expand Up @@ -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 <url>,<url>,...', "Record the PIDs contained in the specified iPlayer episode URLs."],
pid => [ 2, "pid|url=s@", 'Recording', '--pid <pid>,<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 <url>', "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."],
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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 '<type>:<pid>' and <type> is a valid type
Expand All @@ -863,40 +860,40 @@ 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}};
} else {
$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;
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 ) {
Expand Down

0 comments on commit 1555ced

Please sign in to comment.