now we handle all lists correctly
This commit is contained in:
@@ -8,8 +8,7 @@ use warnings "all";
|
|||||||
use URI::URL;
|
use URI::URL;
|
||||||
use Image::Magick;
|
use Image::Magick;
|
||||||
|
|
||||||
sub dlfunc(@);
|
sub dlfunc($); # thread, that checks and downloads stuff
|
||||||
sub cdlfunc($); # thread, that checks and downloads stuff
|
|
||||||
sub is_picture($);
|
sub is_picture($);
|
||||||
sub urlencode($);
|
sub urlencode($);
|
||||||
sub hookfn;
|
sub hookfn;
|
||||||
@@ -26,7 +25,7 @@ if (-f "/bin/wget") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $script_name = "Image URL Auto Grabber and Downloader, wget flavour";
|
my $script_name = "Image URL Auto Grabber and Downloader, wget flavour";
|
||||||
HexChat::register($script_name, '0.8.4', 'Automatically grabs and downloads image URLs via wget', \&freehooks);
|
HexChat::register($script_name, '0.8.5', 'Automatically grabs and downloads image URLs via wget', \&freehooks);
|
||||||
|
|
||||||
HexChat::print("$script_name loaded\n");
|
HexChat::print("$script_name loaded\n");
|
||||||
my @hooks;
|
my @hooks;
|
||||||
@@ -48,7 +47,7 @@ sub hookfn {
|
|||||||
my $t = undef;
|
my $t = undef;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$t = threads->create('cdlfunc', $_);
|
$t = threads->create('dlfunc', $_);
|
||||||
sleep 1 unless(defined($t));
|
sleep 1 unless(defined($t));
|
||||||
} unless (defined($t));
|
} unless (defined($t));
|
||||||
|
|
||||||
@@ -67,7 +66,7 @@ sub hookfn {
|
|||||||
return HexChat::EAT_NONE;
|
return HexChat::EAT_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub cdlfunc($) {
|
sub dlfunc($) {
|
||||||
my $url = shift;
|
my $url = shift;
|
||||||
my $extension = is_picture($url);
|
my $extension = is_picture($url);
|
||||||
|
|
||||||
@@ -80,7 +79,24 @@ sub cdlfunc($) {
|
|||||||
$savepath = HexChat::get_info("configdir") . "/imgsave/" . s/[^\w!., -#]/_/gr;
|
$savepath = HexChat::get_info("configdir") . "/imgsave/" . s/[^\w!., -#]/_/gr;
|
||||||
}
|
}
|
||||||
|
|
||||||
dlfunc($url, $savepath);
|
$url = urlencode($url);
|
||||||
|
system($wgetpath, '--no-check-certificate', '-q', '-T', '20', '-O', $file, '-o', '/dev/null', $url);
|
||||||
|
|
||||||
|
if ($file =~ /(png|jpe?g|gif)$/i){
|
||||||
|
my $im = Image::Magick->new();
|
||||||
|
my $rename = 1;
|
||||||
|
my (undef, undef, undef, $format) = $im->Ping($savepath);
|
||||||
|
|
||||||
|
if (defined($format)) {
|
||||||
|
$rename = 0 if (($format eq 'JPEG') and ($file =~ /jpe?g$/i));
|
||||||
|
$rename = 0 if (($format eq 'GIF') and ($file =~ /gif$/i));
|
||||||
|
$rename = 0 if (($format =~ /^PNG/) and ($file =~ /png$/i));
|
||||||
|
rename $savepath, sprintf("%s.%s", $savepath, lc($format)) if ($rename == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
undef $im; undef $rename;
|
||||||
|
}
|
||||||
|
|
||||||
undef $savepath;
|
undef $savepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,31 +104,6 @@ sub cdlfunc($) {
|
|||||||
undef $url; undef $extension;
|
undef $url; undef $extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub dlfunc(@) {
|
|
||||||
my $url = shift;
|
|
||||||
my $file = shift;
|
|
||||||
|
|
||||||
$url = urlencode($url);
|
|
||||||
system($wgetpath, '--no-check-certificate', '-q', '-T', '20', '-O', $file, '-o', '/dev/null', $url);
|
|
||||||
|
|
||||||
if ($file =~ /(png|jpe?g|gif)$/i){
|
|
||||||
my $im = Image::Magick->new();
|
|
||||||
my $rename = 1;
|
|
||||||
my (undef, undef, undef, $format) = $im->Ping($file);
|
|
||||||
|
|
||||||
if (defined($format)) {
|
|
||||||
$rename = 0 if (($format eq 'JPEG') and ($file =~ /jpe?g$/i));
|
|
||||||
$rename = 0 if (($format eq 'GIF') and ($file =~ /gif$/i));
|
|
||||||
$rename = 0 if (($format =~ /^PNG/) and ($file =~ /png$/i));
|
|
||||||
rename $file, sprintf("%s.%s", $file, lc($format)) if ($rename == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
undef $im; undef $rename;
|
|
||||||
}
|
|
||||||
|
|
||||||
undef $url; undef $file;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub is_picture($) {
|
sub is_picture($) {
|
||||||
my $url = shift;
|
my $url = shift;
|
||||||
$url = urlencode($url);
|
$url = urlencode($url);
|
||||||
@@ -121,23 +112,23 @@ sub is_picture($) {
|
|||||||
$r = `$wgetpath --no-check-certificate -q --method=HEAD -S --timeout=5 "$url" 2>&1`;
|
$r = `$wgetpath --no-check-certificate -q --method=HEAD -S --timeout=5 "$url" 2>&1`;
|
||||||
undef $url;
|
undef $url;
|
||||||
|
|
||||||
if ($? != 0) {
|
if ($? == 0) {
|
||||||
return undef;
|
foreach (split(/\n/, $r)) {
|
||||||
}
|
next unless($_ =~ /Content\-Type: (.+)/);
|
||||||
|
$r = ($1); chomp($r);
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (split(/\n/, $r)) {
|
if (defined($r)) {
|
||||||
next unless($_ =~ /Content\-Type: (.+)/);
|
if ($r =~ /^image\/gif/) { $r = 'gif'; }
|
||||||
$r = ($1); chomp($r);
|
elsif ($r =~ /^image\/jpe?g/){ $r = 'jpeg';}
|
||||||
last;
|
elsif ($r =~ /^image\/png/) { $r = 'png'; }
|
||||||
}
|
elsif ($r =~ /^video\/webm/) { $r = 'webm';}
|
||||||
|
elsif ($r =~ /^video\/mp4/) { $r = 'mp4'; }
|
||||||
if (defined($r)) {
|
else { $r = undef; }
|
||||||
if ($r =~ /^image\/gif/) { $r = 'gif'; }
|
} else {
|
||||||
elsif ($r =~ /^image\/jpe?g/){ $r = 'jpeg';}
|
$r = undef;
|
||||||
elsif ($r =~ /^image\/png/) { $r = 'png'; }
|
}
|
||||||
elsif ($r =~ /^video\/webm/) { $r = 'webm';}
|
|
||||||
elsif ($r =~ /^video\/mp4/) { $r = 'mp4'; }
|
|
||||||
else { $r = undef; }
|
|
||||||
} else {
|
} else {
|
||||||
$r = undef;
|
$r = undef;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
# TODO: handle quotes in "/notify add netname network" with space containing entities
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings "all";
|
use warnings "all";
|
||||||
use HexChat qw(:all);
|
use HexChat qw(:all);
|
||||||
@@ -26,7 +25,7 @@ my $help = 'Usage:
|
|||||||
/notify show - shows whitelists and their statuses
|
/notify show - shows whitelists and their statuses
|
||||||
';
|
';
|
||||||
|
|
||||||
register($script_name, '0.8', 'Sends *nix desktop notifications', \&freehooks);
|
register($script_name, '0.8.1', 'Sends *nix desktop notifications', \&freehooks);
|
||||||
|
|
||||||
HexChat::print("$script_name loaded\n");
|
HexChat::print("$script_name loaded\n");
|
||||||
my @hooks;
|
my @hooks;
|
||||||
@@ -128,9 +127,10 @@ sub timeraction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub notify_cmd {
|
sub notify_cmd {
|
||||||
my $cmd = $_[0][1] // undef;
|
shift(@{$_[0]});
|
||||||
my $entity = $_[0][2] // undef;
|
my $cmd = shift(@{$_[0]});
|
||||||
my $value = $_[0][3] // undef;
|
my $entity = shift(@{$_[0]});
|
||||||
|
my $value = join(' ', @{$_[0]});
|
||||||
|
|
||||||
unless (defined($cmd)) {
|
unless (defined($cmd)) {
|
||||||
HexChat::print($help);
|
HexChat::print($help);
|
||||||
@@ -304,10 +304,13 @@ sub notify_cmd {
|
|||||||
my @netlist;
|
my @netlist;
|
||||||
|
|
||||||
foreach (@list) {
|
foreach (@list) {
|
||||||
|
HexChat::printf("_: %s, value: %s", $_, $value);
|
||||||
next if($_ eq $value);
|
next if($_ eq $value);
|
||||||
push @netlist, $value;
|
push @netlist, $_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@list = -1; undef @list;
|
||||||
|
|
||||||
unless (defined(savelist('nets', @netlist))) {
|
unless (defined(savelist('nets', @netlist))) {
|
||||||
return HexChat::EAT_ALL;
|
return HexChat::EAT_ALL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user