Skip to content

Commit

Permalink
Allow normal refresh functions with --ybbcy
Browse files Browse the repository at this point in the history
- Allow --refresh-future
- Don't force use of AOD data for radio indexing
- Move forced options setup to init_search
- force --refresh-exclude-groups-tv="local" as default
  • Loading branch information
dinkypumpkin committed Apr 13, 2017
1 parent 1032f22 commit 3522611
Showing 1 changed file with 87 additions and 83 deletions.
170 changes: 87 additions & 83 deletions get_iplayer
Expand Up @@ -755,6 +755,18 @@ sub init_search {
exit 0;
}

# force -ybbcy
#$opt->{ybbcy} = 1 unless defined $opt->{ybbcy};
# exclude local channels with --ybbcy
if ( $opt->{ybbcy} && ! defined $opt->{refreshexcludegroups} ) {
#if ( ! defined $opt->{refreshexcludegroupsradio} ) {
# $opt->{refreshexcludegroupsradio} = "local";
#}
if ( ! defined $opt->{refreshexcludegroupstv} ) {
$opt->{refreshexcludegroupstv} = "local";
}
}

# Show options
$opt->display('Current options') if $opt->{verbose};
# $prog->{pid}->object hash
Expand Down Expand Up @@ -3234,9 +3246,6 @@ sub channels_filtered {
(my $prog_type = $prog) =~ s/Programme:://;
my $exclude_groups = $opt->{'refreshexcludegroups'.$prog_type} || $opt->{'refreshexcludegroups'};
my $include_groups = $opt->{'refreshincludegroups'.$prog_type} || $opt->{'refreshincludegroups'};
if ( $opt->{ybbcy} && $prog_type eq "tv" && ! $exclude_groups ) {
$exclude_groups = "local";
}
my %channels;
my %group_channels;
# include/exclude matching channels as required
Expand Down Expand Up @@ -6519,12 +6528,8 @@ sub get_links {
$rc = $self->get_links_schedule($prog, $prog_type, 0, $now);
return 1 if $rc && $opt->{refreshabortonerror};
if ( $opt->{refreshfuture} ) {
if ( $opt->{ybbcy} ) {
main::logger "\nWARNING: --refresh-future is ignored with --ybbcy.\n";
} else {
$rc = $self->get_links_schedule($prog, $prog_type, 1, $now);
return 1 if $rc && $opt->{refreshabortonerror};
}
$rc = $self->get_links_schedule($prog, $prog_type, 1, $now);
return 1 if $rc && $opt->{refreshabortonerror};
}
main::logger "\n";
return 0;
Expand All @@ -6540,65 +6545,7 @@ sub get_links_schedule {
my $now = shift || time();
my $pm;
my $rc_pm;
if ( $opt->{ybbcy} ) {
eval "use XML::LibXML '1.70'";
if ( $@ ) {
main::logger "WARNING: Please download and run latest installer or install the XML::LibXML Perl module to index $prog_type programmes with --ybbcy.\n";
return;
}
if ( $opt->{indexconcurrent} && $prog_type eq "tv" ) {
if ( $^O eq "MSWin32" ) {
main::logger "WARNING: Concurrent indexing is not supported on Windows. Normal indexing will be performed.\n";
} else {
eval "use Parallel::ForkManager";
if ( ! $@ ) {
my $max_conn = $opt->{indexmaxconn} || 4;
$max_conn = 10 if $max_conn > 10;
$pm = Parallel::ForkManager->new($max_conn);
$pm->run_on_finish( sub {
my ($child_pid, $exit_code, $ident, $exit_signal, $core_dump, $data) = @_;
$rc_pm = $exit_code unless $rc_pm;
if ( defined $data ) {
for my $pid ( keys %{$data} ) {
if ( defined $prog->{$pid} ) {
main::logger "WARNING: '$pid, $prog->{$pid}->{name} - $prog->{$pid}->{episode}, $prog->{$pid}->{channel}' already exists (this channel = $data->{$pid}->{channel} $data->{$pid}->{available})\n" if $opt->{verbose};
# use listing with earliest availability
if ( $data->{$pid}->{available} lt $prog->{$pid}->{available} ) {
$prog->{$pid}->{available} = $data->{$pid}->{available};
}
# use listing with latest expiry
if ( $data->{$pid}->{expires} > $prog->{$pid}->{expires} ) {
$prog->{$pid}->{expires} = $data->{$pid}->{expires};
}
next;
} else {
$prog->{$pid} = $data->{$pid};
}
}
}
});
} else {
main::logger "WARNING: Concurrent indexing requires the Parallel::ForkManager Perl module. Normal indexing will be performed.\n";
}
}
}
}
my %channels = %{ main::progclass($prog_type)->channels_filtered( main::progclass($prog_type)->channels_schedule() ) };
my (%aod_channels, %aod_channel_ids);
if ( $prog_type eq "radio" ) {
%aod_channels = %{ main::progclass($prog_type)->channels_filtered( main::progclass($prog_type)->channels_aod() ) };
if ( $opt->{ybbcy} ) {
while ( my ($k1, $v1) = each %channels ) {
keys %aod_channels;
while ( my ($k2, $v2) = each %aod_channels ) {
if ( $v1 eq $v2 ) {
$aod_channel_ids{$k1} = $k2;
last;
}
}
}
}
}
my @channel_list = sort keys %channels;
my @schedule_dates;
my $limit = 0;
Expand All @@ -6618,7 +6565,12 @@ sub get_links_schedule {
$cache_last_week = ( $that_year == $cache_year && $that_week == $cache_week );
}
if ( $future ) {
push @schedule_dates, "this_week", "next_week";
if ( $opt->{ybbcy} ) {
push @schedule_dates, "this_week" unless $cache_this_week;
} else {
push @schedule_dates, "this_week";
}
push @schedule_dates, "next_week";
} else {
my $limit_days = $opt->{"refreshlimit".${prog_type}} || $opt->{"refreshlimit"};
$limit_days = 0 if $limit_days < 0;
Expand Down Expand Up @@ -6646,6 +6598,64 @@ sub get_links_schedule {
}
}
return unless @schedule_dates;
my (%aod_channels, %aod_channel_ids);
if ( $prog_type eq "radio" ) {
%aod_channels = %{ main::progclass($prog_type)->channels_filtered( main::progclass($prog_type)->channels_aod() ) };
if ( $opt->{ybbcy} ) {
while ( my ($k1, $v1) = each %channels ) {
keys %aod_channels;
while ( my ($k2, $v2) = each %aod_channels ) {
if ( $v1 eq $v2 ) {
$aod_channel_ids{$k1} = $k2;
last;
}
}
}
}
}
if ( $opt->{ybbcy} ) {
eval "use XML::LibXML '1.70'";
if ( $@ ) {
main::logger "WARNING: Please download and run latest installer or install the XML::LibXML Perl module to index $prog_type programmes with --ybbcy.\n";
return;
}
if ( $opt->{indexconcurrent} ) {
if ( $^O eq "MSWin32" ) {
main::logger "WARNING: Concurrent indexing is not supported on Windows. Normal indexing will be performed.\n";
} else {
eval "use Parallel::ForkManager";
if ( ! $@ ) {
my $max_conn = $opt->{indexmaxconn} || 4;
$max_conn = 10 if $max_conn > 10;
$pm = Parallel::ForkManager->new($max_conn);
$pm->run_on_finish( sub {
my ($child_pid, $exit_code, $ident, $exit_signal, $core_dump, $data) = @_;
$rc_pm = $exit_code unless $rc_pm;
if ( defined $data ) {
for my $pid ( keys %{$data} ) {
if ( defined $prog->{$pid} ) {
main::logger "WARNING: '$pid, $prog->{$pid}->{name} - $prog->{$pid}->{episode}, $prog->{$pid}->{channel}' already exists (this channel = $data->{$pid}->{channel} $data->{$pid}->{available})\n" if $opt->{verbose};
# use listing with earliest availability
if ( $data->{$pid}->{available} lt $prog->{$pid}->{available} ) {
$prog->{$pid}->{available} = $data->{$pid}->{available};
}
# use listing with latest expiry
if ( $data->{$pid}->{expires} > $prog->{$pid}->{expires} ) {
$prog->{$pid}->{expires} = $data->{$pid}->{expires};
}
next;
} else {
$prog->{$pid} = $data->{$pid};
}
}
}
});
} else {
main::logger "WARNING: Concurrent indexing requires the Parallel::ForkManager Perl module. Normal indexing will be performed.\n";
}
}
}
}
my $ua = main::create_ua( 'desktop', 1 );
$ua->timeout(60) if $opt->{ybbcy};
my $known_bad = "radiosolent";
Expand All @@ -6658,22 +6668,16 @@ sub get_links_schedule {
last if $opt->{refreshabortonerror} && $rc_pm;
my ($url, $rc);
if ( $opt->{ybbcy} ) {
if ( $prog_type eq "radio" ) {
my $aod_channel_id = $aod_channel_ids{$channel_id};
$aod_seen{$channel_id}++;
$rc = $self->get_links_aod($prog, $prog_type, $now, $aod_channel_id);
$url = "http://www.bbc.co.uk/${channel_id}/${schedule_date}";
if ($pm) {
$pm->start($url) and next SCHEDULES;
my ($rc2, $prog2);
$prog2 = {};
$rc2 = $self->get_links_schedule_html($ua, $prog2, $prog_type, $channel_id, $channels{$channel_id}, $future, $url, $limit, $now, $known_bad);
$pm->finish($rc2, $prog2)
} else {
$url = "http://www.bbc.co.uk/${channel_id}/${schedule_date}";
if ($pm) {
$pm->start($url) and next SCHEDULES;
my ($rc2, $prog2);
$prog2 = {};
$rc2 = $self->get_links_schedule_html($ua, $prog2, $prog_type, $channel_id, $channels{$channel_id}, $future, $url, $limit, $now, $known_bad);
$pm->finish($rc2, $prog2)
} else {
$rc = $self->get_links_schedule_html($ua, $prog, $prog_type, $channel_id, $channels{$channel_id}, $future, $url, $limit, $now, $known_bad);
};
}
$rc = $self->get_links_schedule_html($ua, $prog, $prog_type, $channel_id, $channels{$channel_id}, $future, $url, $limit, $now, $known_bad);
};
} else {
$url = "http://www.bbc.co.uk/${channel_id}/${schedule_date}.xml";
$rc = $self->get_links_schedule_page($ua, $prog, $prog_type, $channel_id, $channels{$channel_id}, $future, $url, $limit, $now, $known_bad);
Expand Down

0 comments on commit 3522611

Please sign in to comment.