Guest User

4chan desktop thread downloader

a guest
Dec 20th, 2013
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.78 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use Cwd;
  4. use LWP::Simple;
  5.  
  6. $catalog = get('http://boards.4chan.org/g/catalog');
  7. @thread_ids = ($catalog =~ /"(\d+)":{"date":\d+,"r":\d+,"i":\d+,"lr":{"id":\d+,"date":\d+,"author":"[^"]+"},"author":"[^"]+","imgurl":"\d+","tn_w":\d+,"tn_h":\d+,"sub":"desktop thread"/gi);
  8. foreach (@thread_ids) {
  9.     $id = $_;
  10.     mkdir $id;
  11.     chdir $id;
  12.     $thread = get("http://boards.4chan.org/g/res/$id");
  13.     @posts = ($thread =~ /<div class="fileText" id="[^ "]+">File: <a href="([^ "]+)" target="[^"]+">[^ <]+<\/a>/ig);
  14.     foreach (@posts) {
  15.         $url = $_;
  16.         $url =~ s/\/\//http:\/\//g;
  17.         ($filename) = ($url =~ /\/([^ \/]+)$/);
  18.         $filename = cwd()."/$filename";
  19.         unless (-e $filename) {
  20.             print "Downloading to $filename\n";
  21.             getstore($url, $filename); 
  22.         }
  23.     }
  24.     chdir '..';
  25. }
Add Comment
Please, Sign In to add comment