This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

piratebay magnet scrape

By: a guest on Feb 8th, 2012  |  syntax: Perl  |  size: 1.31 KB  |  views: 50,514  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. use warnings;
  2. use strict;
  3. use Parallel::ForkManager;
  4. use 5.010;
  5. my $pm=new Parallel::ForkManager(50);
  6.  
  7. use Fcntl qw(:flock SEEK_END);
  8.  
  9. $pm->run_on_finish(sub{
  10.     my (undef, undef, undef, undef, undef, $res_ref) = @_;
  11.     my ($res, $line) = @$res_ref;
  12.     if ($res == 1) {
  13.             open my $outf, ">>", "outf";
  14.             flock($outf, LOCK_EX) or next;
  15.             seek($outf, 0, SEEK_END);
  16.             say $outf $line;
  17.             say $line;
  18.             flock($outf, LOCK_UN);
  19.     }
  20. });
  21.  
  22. my $i = 1;
  23. while (1) {
  24.     $i++;
  25.     $pm->start and next;
  26.     my $res;
  27.     my $page="";
  28.  
  29.     $page = `curl -s http://thepiratebay.se/torrent/$i -m 120`
  30.         while ($page !~ /<!DOCTYPE html/);
  31.     my $line = "";
  32.     if ($page =~ m{<title>Not Found}) {
  33.         $res = 0;
  34.     } else {
  35.         $res = 1;
  36.         my ($title) = $page =~ /<div id="title">\s*(.*?)\s*<\/div>/s;
  37.         my ($size) = $page =~ /<dt>Size:<\/dt>\s*<dd>.*?\((\d*)&nbsp;Bytes\)<\/dd>/s;
  38.         my ($seeders) = $page =~ /<dt>Seeders:<\/dt>\s*<dd>(\d*)<\/dd>/;
  39.         my ($leechers) = $page =~ /<dt>Leechers:<\/dt>\s*<dd>(\d*)<\/dd>/;
  40.         my ($magnet) = $page =~ /magnet:\?xt=urn:btih:(.*?)(&|")/;
  41.         $line =
  42.         $i."|".$title."|".$size."|".$seeders."|".$leechers."|".$magnet;
  43.     }
  44.     $pm->finish(0,[$res, $line]);
  45. }
clone this paste RAW Paste Data