Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement