$DEBUG = $options{debug};
-
+binmode(STDOUT,":encoding(UTF-8)");
+binmode(STDERR,":encoding(UTF-8)");
if (not grep {exists $options{$_} and
defined $options{$_} and
my @possible_links = $m->find_all_links(text_regex => qr/to\s*read/i);
# try to find the other links
push @possible_links,
- grep {my $attr = $_->attrs(); exists $attr->{title} and $attr->{title} =~ qr/(?:Full\s*Text|PMC)/i}
+ grep {my $attr = $_->attrs();
+ exists $attr->{title} and
+ $attr->{title} =~ qr/(?:Full\s*Text|PMC)/i}
$m->links();
print STDERR map {"article link: ".$_->url_abs()."\n"} @possible_links if $DEBUG;
die "No links" unless @possible_links;
};
if ($@) {
print STDERR "$@\n" if $DEBUG;
- if ($options{use_links}) {
+ if ($options{use_links}) {
+ if ($ENV{DISPLAY}) {
+ system('chromium',
+ # links2 doesn't like the leading http:// of proxies for some reason
+ exists $options{http_proxy}?('--proxy-server',(map {s{http://}{}; $_} $options{http_proxy})):(),
+ '--temp-profile',
+ $url,
+ ) == 0 or next;
+ rename('temp.pdf',"${pmid}.pdf") if -e 'temp.pdf';
+ } else {
system('links2',
# links2 doesn't like the leading http:// of proxies for some reason
exists $options{http_proxy}?('-http-proxy',(map {s{http://}{}; $_} $options{http_proxy})):(),
) == 0 or next;
rename('temp.pdf',"${pmid}.pdf") if -e 'temp.pdf';
}
- }
+ }}
}
}
defined $_->text() and $_->text() =~ qr/Full\s*Text.*PDF/i
}
$m->find_all_links(text_regex => qr/PDF/i);
+ push @possible_links,
+ grep {my $temp = $_->attrs();
+ exists $temp->{rel} and $temp->{rel} =~ qr/alternate/i and
+ exists $temp->{type} and $temp->{type} =~ qr/pdf/i
+ }
+ $m->find_all_links(url_regex => qr/pdf/);
# this is to prioritize the real link at science direct
push @possible_links,
grep {my $temp = $_->attrs();