Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

The Pirate Bay RAW to SQL dump

By: a guest on Feb 10th, 2012  |  syntax: PHP  |  size: 3.32 KB  |  views: 302  |  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. <?php
  2. // Script by Phate191
  3. // If php do "Maximum execution time exceeded", change the php.ini file
  4.  
  5. // set memory limit
  6. ini_set('memory_limit', '-1');
  7. // raw TPB file
  8. $tpb_file = "complete";
  9. // sql file
  10. $sql_file = "tpb.sql";
  11. // </br> HTML
  12. $br = "</br>";
  13.  
  14. // read file into array
  15. $file_array = file($tpb_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  16.  
  17. print ("Open file [OK]$br\nInsert to array [OK]$br\n");
  18.  
  19. $file_row_num = count($file_array);
  20.  
  21. // open sql file
  22. $var=fopen($sql_file,"w+");
  23.  
  24. printf ("Open $sql_file [OK]$br\n");
  25.  
  26. // sql header --- TABLE NAME: tpb
  27. $header = "-- SQL Dump
  28. --
  29. -- Scripted By: Phate191
  30. -- SQL Dump of The Pirate Bay
  31. -- RAW file by allisfine
  32. --
  33. -- Version: 1.0
  34.  
  35. --
  36. -- Table structure `tpb`
  37. --
  38.  
  39. CREATE TABLE IF NOT EXISTS `tpb` (
  40.  `ID` double NOT NULL,
  41.  `name` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  42.  `size` double NOT NULL,
  43.  `seeders` int(11) NOT NULL,
  44.  `leechers` int(11) NOT NULL,
  45.  `hash` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL
  46. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  47.  
  48. --
  49. -- Dump `tpb`
  50. --
  51.  
  52. INSERT INTO `tpb` (`ID`, `name`, `size`, `seeders`, `leechers`, `hash`) VALUES
  53. ";
  54.  
  55. // write to file
  56. fwrite($var, $header);
  57.  
  58. print ("Write header to $sql_file [OK]$br$br\n\nStart manipulate RAW code...$br\n");
  59.  
  60. // start with code manipulation--------
  61. for($i=0; $i < $file_row_num; $i++){
  62.   $original = $file_array[$i];
  63.  
  64.   // clean special chars --- use "htmlspecialchars_decode" to decode
  65.   $original = htmlspecialchars($original, ENT_QUOTES);
  66.  
  67.   // string lengh -1
  68.   $len = strlen($original);
  69.   $tpbid = substr($original, 0, 7); // TPD ID for database
  70.  
  71.   $original = substr($original, 8, $len);  // eliminate ID
  72.   $reverse = strrev($original); //reverse the string for check '|'
  73.   $pos = strpos($reverse, '|'); // last '|' [reversed]
  74.   $magnetlink = substr($reverse, 0, $pos); // magnet link [reversed]
  75.   $magnetlink = strrev($magnetlink); // MAGNET LINK for database
  76.  
  77.   $len = strlen($reverse);
  78.   $reverse = substr($reverse, $pos + 1, $len);
  79.   $pos = strpos($reverse, '|'); // last '|' [reversed]
  80.   $leechers = substr($reverse, 0, $pos); // leechers [reversed]
  81.   $leechers = strrev($leechers); // LEECHERS for database
  82.  
  83.   $len = strlen($reverse);
  84.   $reverse = substr($reverse, $pos + 1, $len);
  85.   $pos = strpos($reverse, '|'); // last '|' [reversed]
  86.   $seeders = substr($reverse, 0, $pos); // seeders [reversed]
  87.   $seeders = strrev($seeders); // SEEDERS for database
  88.  
  89.   $len = strlen($reverse);
  90.   $reverse = substr($reverse, $pos + 1, $len);
  91.   $pos = strpos($reverse, '|'); // last '|' [reversed]
  92.   $size = substr($reverse, 0, $pos); // size [reversed]
  93.   $size = strrev($size); // SIZE for database
  94.  
  95.   $len = strlen($reverse);
  96.   $name = substr($reverse, $pos + 1, $len); //name [reversed]
  97.   $name = strrev($name); // NAME for database
  98.  
  99.   // create the sql string
  100.   if($i == $file_row_num-1){
  101.     $sql_string = "($tpbid, '$name', $size, $seeders, $leechers, '$magnetlink');"; // if is the last row put ;
  102.   }
  103.   else{
  104.     $sql_string = "($tpbid, '$name', $size, $seeders, $leechers, '$magnetlink'),\n";
  105.   }
  106.  
  107.   // write to file
  108.   fwrite($var, $sql_string);
  109.  
  110. }
  111. print ("Manipulate code [OK]$br\n");
  112.  
  113. fclose($var); // close tpb.sql
  114.  
  115. print ("Close connection to $sql_file [OK]$br$br\n\nAll Operation are completed");
  116. ?>