Skip to content

Commit

Permalink
Merge pull request #862 from ailin-nemui/sa-rateurl
Browse files Browse the repository at this point in the history
[scriptassist] update to 2023111700
  • Loading branch information
ailin-nemui authored Nov 28, 2023
2 parents 88186a9 + 185668a commit 1d3aeea
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions scripts/scriptassist.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use strict;

our $VERSION = '2023091200';
our $VERSION = '2023111700';
our %IRSSI = (
authors => 'Stefan \'tommie\' Tomanek',
contact => '[email protected]',
Expand Down Expand Up @@ -356,6 +356,8 @@ sub script_info {

sub get_rate_url {
my ($src) = @_;
if (ref $src) { ($src) = grep { $_ } map { $_->{source} } values %$src; }
die("No script source address found\n") unless $src;
my $ua = LWP::UserAgent->new(env_proxy=>1, keep_alive=>1, timeout=>30);
$ua->agent('ScriptAssist/'.$VERSION);
my $request = HTTP::Request->new('GET', $src);
Expand All @@ -364,6 +366,9 @@ sub get_rate_url {
my $error = join "\n", $response->status_line(), (grep / at .* line \d+/, split "\n", $response->content()), '';
die("Fetching ratings location failed: $error");
}
if (my $error = $response->header('X-Died')) {
die("$error\n");
}
my $votes_url;
for my $tag ($response->content() =~ /<script([^>]*)>/g) {
my $attr = " $tag ";
Expand All @@ -375,7 +380,7 @@ sub get_rate_url {
}
$request = HTTP::Request->new('GET', $votes_url);
$response = $ua->request($request);
if (!$response->is_success) {
if (!$response->is_success || $response->header('X-Died')) {
my $error = join "\n", $response->status_line(), (grep / at .* line \d+/, split "\n", $response->content()), '';
die("Fetching ratings failed: $error");
}
Expand All @@ -387,7 +392,7 @@ sub get_rate_url {
sub rate_script {
my ($script, $stars) = @_;
my $xml = get_scripts();
my $votes = get_rate_url(map { $_->{source} } values %$xml);
my $votes = get_rate_url($xml);
my $n = get_names($script, $xml, $votes);
die "Script $script not found\n" unless $n->{votes};
return $n->{votes}{u}
Expand All @@ -396,7 +401,7 @@ sub rate_script {
sub get_ratings {
my ($scripts, $limit) = @_;
my $xml = get_scripts();
my $votes = get_rate_url(map { $_->{source} } values %$xml);
my $votes = get_rate_url($xml);
foreach (keys %{$votes}) {
if ($xml->{$_}) {
$xml->{$_}{votes} = $votes->{$_}{v};
Expand Down Expand Up @@ -968,6 +973,10 @@ sub get_scripts {
$error = join "\n", $response->status_line(), (grep / at .* line \d+/, split "\n", $response->content()), '';
next;
}
if (my $died = $response->header('X-Died')) {
$error = $died;
next;
}
$fetched = 1;
my $data = $response->content();
my $src = $site;
Expand Down Expand Up @@ -1117,7 +1126,7 @@ sub download_script {
$ua->agent('ScriptAssist/'.2003020803);
my $request = HTTP::Request->new('GET', $site.'/scripts/'.$n->{plname});
my $response = $ua->request($request);
if ($response->is_success()) {
if ($response->is_success() && !$response->header('X-Died')) {
my $file = $response->content();
mkdir $dir.'/scripts/' unless (-e $dir.'/scripts/');
open(my $f, '>', $dir.'/scripts/'.$n->{plname}.'.new');
Expand All @@ -1128,7 +1137,7 @@ sub download_script {
$ua->agent('ScriptAssist/'.2003020803);
my $request2 = HTTP::Request->new('GET', $site.'/signatures/'.$n->{plname}.'.asc');
my $response2 = $ua->request($request2);
if ($response2->is_success()) {
if ($response2->is_success() && !$response->header('X-Died')) {
my $sig_dir = $dir.'/scripts/signatures/';
mkdir $sig_dir unless (-e $sig_dir);
open(my $s, '>', $sig_dir.$n->{plname}.'.asc');
Expand Down

0 comments on commit 1d3aeea

Please sign in to comment.