1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
| use LWP::UserAgent;
use HTML::LinkExtor;
use URI::URL;
use warnings;
use strict;
use Thread;
use constant {
NB_THRD_MAX => 3
};
my $launch_url = "http://interfacelift.com/wallpaper/downloads/date/any"; # for instance
my $base_url= "http://interfacelift.com";
my $url=$launch_url;
my $repertoire="./download";
mkdir ($repertoire, 755);
my @tabres= ("1280x1024","1920x1080");
my $page=1;
my $nbr_thrd=0;
# Download everything on $url
# and write into /download
sub download_url
{
my ($url)=@_;
my @tablines=();
my %links=();
my $nomfichier;
my $urlfichier;
my $mystream;
my $cpt=0;
my $ua = LWP::UserAgent->new;
$ua->agent("zero-agent");
$ua->timeout(30);
my $response = $ua->get($url);
#print "\n Thread Launched\n";
if ($response->is_success) {
@tablines=split('\n',$response->decoded_content); # or whatever
} else { print "\n HTTP KO";}
foreach (@tablines)
{
#if ($_=~/javascript\:imgload\('(.*?)',.*?,'(.*?)'\).*?$/mi)
if ($_=~/javascript\:imgload\('(.*?)',.*?,'(.*?)'\).*?$/mi)
{
foreach (@tabres)
{
#$links{$1.'_'.$_}="$base_url/wallpaper/7yz4ma1/0".$2."_".$1."_".$_.".jpg";
$links{$1.'_'.$_}="$base_url/wallpaper/D47cd523/0".$2."_".$1."_".$_.".jpg";
}
}
}
for my $nomfichier ( keys %links )
{
$urlfichier=$links{$nomfichier};
print "Downloading => ".$urlfichier;
$response = $ua->get($urlfichier);
if ($response->is_success) {print " -- HTTP OK\n";}
$mystream=$response->decoded_content;
$nomfichier=$repertoire.'/'.$nomfichier.'.jpg';
open(FILE, ">$nomfichier") || die "Erreur E/S:$!\n";
binmode FILE;
print FILE $mystream;
close(FILE);
}
#print "\n Done on $url\n";
}
sub search_nextpage
{
my ($ref_tablines)=shift;
for (@$ref_tablines)
{
#if ($_=~m/^.*?href="(.*?)".*?next\spage.*?$/i)
if ($_=~m/[.|\s]*?href="(.*?)".*?next\spage.*?$/i)
{
return $1;
}
}
return "";
}
sub lis_url
{
my ($url)=shift;
my ($ref_tablines)=shift;
my $ua = LWP::UserAgent->new;
$ua->agent("zero-agent");
$ua->timeout(30);
my $response = $ua->get($url);
if ($response->is_success) {
@$ref_tablines=split('\n',$response->decoded_content); # or whatever
#print "\n HTTP OK sur $url \n";
return 1;
}
else
{
#print "\n HTTP KO sur $url \n";
return 0;
}
}
sub count_thrd
{
my $nbr=0;
foreach my $thr (threads->list()) {$nbr++;}
return $nbr;
}
sub start_leeching
{
my ($url)=shift;
my @tablines=();
my $nextpage=$url;
my %thrd;
my $thr;
while (lis_url($nextpage,\@tablines))
{
# Download everything on url
#print "\n Launching Thread ".count_thrd();
$thrd{$nextpage} = new Thread \&download_url,$nextpage;
$nbr_thrd++;
print"\n Current number of threads launched : $nbr_thrd over ".count_thrd()." actives\n";
if (count_thrd()>=NB_THRD_MAX)
{
# Loop through all the threads
# and wait the last to finished
#print "\n ---- COOL DOWN -------------------------------------\n";
#print "\n ---- ".NB_THRD_MAX." maximum threads is reached ----\n";
foreach $thr (threads->list())
{
#print "\n ---- ".count_thrd()." threads are running ----\n";
#print "\n ---- Waiting for a thread to cool down ----\n";
$thr->join();
#print "\n ---- Done ----\n";
}
}
$nextpage=search_nextpage(\@tablines);
$nextpage=$base_url.$nextpage;
#print "Next page => $nextpage \n";
@tablines=();
}
}
#if ($ARGV[0] ne "") {$url=$ARGV[0];$base_url=$url;}
#if (!($url=~/^http/i)) {
# $base_url="http://".$url;
# $url="http://".$url;
# }
#print "Recherche de liens sur $url\n";
#print "Base url est : $base_url\n";
print "\n -------------------------------------";
print "\n - InterfaceLift WaLlPaPer LeeCher -";
print "\n -------------------------------------";
print "\n\nAll images are downloaded into ./download";
print "\n- Use ctrl-C to stop whenever you want";
print "\n\n => Starting";
start_leeching($url); |
Partager