moytrage

zoomgirls_downloader.pl

Jan 28th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.27 KB | None | 0 0
  1. use strict;
  2. use warnings;
  3.  
  4. sub norm($) {
  5.     my $n = shift;
  6.     $n = 0 unless $n;
  7.     $n =~ s/x/\./g;
  8.     return $n;
  9. }
  10.  
  11. our @main;
  12. our $siteroot = "http://zoomgirls.net";
  13. our $get_only_biggest = 1;
  14.                                                              
  15. our %rdb = (
  16.         '1280x1024' => 1.25,
  17.  
  18.         '800x600'   => 1.33,
  19.         '1024x768'  => 1.33,
  20.         '1152x864'  => 1.33,
  21.         '1280x960'  => 1.33,
  22.         '1600x1200' => 1.33,
  23.         '1920x1440' => 1.33,
  24.  
  25.         '1280x800'  => 1.6,
  26.         '1440x900'  => 1.6,
  27.         '1680x1050' => 1.6,
  28.         '1920x1200' => 1.6,
  29.         '1920x1200' => 1.6,
  30.         '2560x1600' => 1.6,
  31.  
  32.         '1280x720'  => 1.77,
  33.         '1366x768'  => 1.77,
  34.         '1600x900'  => 1.77,
  35.         '1920x1080' => 1.77,
  36.        );
  37.  
  38. push @main, "${_}_girls" for ('a'..'z');
  39. push @main, $_ for (
  40.     "anime_and_drawings",
  41.     "babes_and_bikes",
  42.     "babes_and_cars",
  43.     "sexy_girls"
  44. );
  45.  
  46. mkdir("root"); mkdir("pages"); mkdir("walls"); mkdir("pics");
  47.  
  48. for my $main_cat (@main) {
  49.     my $corpus = "girls";
  50.     $corpus = $main_cat unless $main_cat =~ /^[a-z]_girls$/;
  51.     mkdir("pics/$corpus");
  52.  
  53.     my ($url, $file);
  54.     $file = "$main_cat-desktop-wallpapers.html";
  55.  
  56.     unless (-e "root/$file") {
  57.         $url = "$siteroot/$file";
  58.         system("wget $url -O root/$file") == 0 or die;
  59.     }
  60.  
  61.     open F, "root/$file" or die;
  62.     my $maxpage = 1;
  63.     while (<F>) {
  64.         while (/desktop-wallpapers\/page\/(\d+)"/g) {
  65.             $maxpage = $1 if $1 > $maxpage;
  66.         }
  67.     }
  68.     close F;
  69.  
  70.     for my $i (1..$maxpage) {
  71.         $file = "pages/$main_cat-desktop-wallpapers_$i.html";
  72.         unless (-e $file) {
  73.             $url = "$siteroot/$main_cat-desktop-wallpapers/page/$i";
  74.             system("wget $url -O $file") == 0 or die;
  75.         }
  76.  
  77.         open F, "$file" or die;
  78.         while (<F>) {
  79.             next unless /<div class="thumb"><a href="\/(.+?)-wallpapers.html"><em>\d+ views<\/em>/;
  80.  
  81.             my $id = $1;
  82.             $file = "$id-wallpapers.html";
  83.  
  84.             unless (-e "walls/$file") {
  85.                 $url  = "$siteroot/$file";
  86.                 system("wget $url -O walls/$file") == 0 or die;
  87.             }
  88.  
  89.             open G, "walls/$file" or die;
  90.             print "$file\n";
  91.  
  92.             my $found = 0;
  93.             my $dlink = undef;
  94.             while (<G>) {
  95.                 if (/<a href="\/view\/(.*?).html"/) {
  96.                     $dlink = "$1.jpg";
  97.                 }
  98.                 next unless /and it is available in (.*?)resolutions/;
  99.                 my $res = $1;
  100.                 $res =~ s/,?\s*$//;
  101.                 unless ($res) {
  102.                     unless ($dlink) {
  103.                         warn "No IMAGE links found!" unless $dlink;
  104.                         $found = 0;
  105.                         last;
  106.                     }
  107.                     $found = 1;
  108.                     $file = $dlink;
  109.                     unless (-e "pics/$corpus/$file") {
  110.                         system("wget $siteroot/download/$file -O pics/$corpus/$file") == 0 or die;
  111.                     }
  112.                     last;
  113.                 }
  114.  
  115.                 my %maxr;
  116.  
  117.                 for my $raw (split /, /, $res) {
  118.                     die "raw=[$raw/$res]" unless $raw =~ /^(\d+) x (\d+)$/;
  119.                     my $r = "$1x$2";
  120.                     die "$r not in DB!" unless exists $rdb{$r};
  121.                     my $aspect = $rdb{$r};
  122.                     $maxr{$aspect} = $r if norm($maxr{$aspect}) < norm($r);
  123.                 }
  124.  
  125.                 if ($get_only_biggest) {
  126.                     my $mx = '';
  127.                     for my $curr (sort values %maxr) {
  128.                         $mx = $curr if norm($curr) > norm($mx);
  129.                     }
  130.                     %maxr = (1 => $mx);
  131.                 }
  132.  
  133.                 for my $curr (sort values %maxr) {
  134.                     $found = 1;
  135.                     $file = "$id-$curr.jpg";
  136.                     unless (-e "pics/$corpus/$file") {
  137.                         system("wget $siteroot/download/$file -O pics/$corpus/$file") == 0 or die;
  138.                     }
  139.                 }
  140.             }
  141.             warn "No images found in $file..." unless $found;
  142.             close G;
  143.         }
  144.         close F;
  145.     }
  146.  
  147. }
Add Comment
Please, Sign In to add comment