Advertisement
Guest User

LeechIt

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