merge.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. function get_merged_torrent_results($query)
  3. {
  4. global $config;
  5. require "engines/bittorrent/thepiratebay.php";
  6. require "engines/bittorrent/rutor.php";
  7. require "engines/bittorrent/nyaa.php";
  8. require "engines/bittorrent/yts.php";
  9. require "engines/bittorrent/torrentgalaxy.php";
  10. require "engines/bittorrent/1337x.php";
  11. $query = urlencode($query);
  12. $torrent_urls = array(
  13. $thepiratebay_url,
  14. $rutor_url,
  15. $nyaa_url,
  16. $yts_url,
  17. $torrentgalaxy_url,
  18. $_1337x_url
  19. );
  20. $mh = curl_multi_init();
  21. $chs = $results = array();
  22. foreach ($torrent_urls as $url)
  23. {
  24. $ch = curl_init($url);
  25. curl_setopt_array($ch, $config->curl_settings);
  26. array_push($chs, $ch);
  27. curl_multi_add_handle($mh, $ch);
  28. }
  29. $running = null;
  30. do {
  31. curl_multi_exec($mh, $running);
  32. } while ($running);
  33. for ($i=0; count($chs)>$i; $i++)
  34. {
  35. $response = curl_multi_getcontent($chs[$i]);
  36. switch ($i)
  37. {
  38. case 0:
  39. $results = array_merge($results, get_thepiratebay_results($response));
  40. break;
  41. case 1:
  42. $results = array_merge($results, get_rutor_results($response));
  43. break;
  44. case 2:
  45. $results = array_merge($results, get_nyaa_results($response));
  46. break;
  47. case 3:
  48. $results = array_merge($results, get_yts_results($response));
  49. break;
  50. case 4:
  51. $results = array_merge($results, get_torrentgalaxy_results($response));
  52. break;
  53. case 5:
  54. $results = array_merge($results, get_1337x_results($response));
  55. break;
  56. }
  57. }
  58. $seeders = array_column($results, "seeders");
  59. array_multisort($seeders, SORT_DESC, $results);
  60. return $results;
  61. }
  62. function print_merged_torrent_results($results)
  63. {
  64. echo "<div class=\"text-result-container\">";
  65. if (!empty($results))
  66. {
  67. foreach($results as $result)
  68. {
  69. $source = $result["source"];
  70. $name = $result["name"];
  71. $magnet = $result["magnet"];
  72. $seeders = $result["seeders"];
  73. $leechers = $result["leechers"];
  74. $size = $result["size"];
  75. echo "<div class=\"text-result-wrapper\">";
  76. echo "<a href=\"$magnet\">";
  77. echo "$source";
  78. echo "<h2>$name</h2>";
  79. echo "</a>";
  80. echo "<span>SE: <span class=\"seeders\">$seeders</span> - ";
  81. echo "LE: <span class=\"leechers\">$leechers</span> - ";
  82. echo "$size</span>";
  83. echo "</div>";
  84. }
  85. }
  86. else
  87. echo "<p>There are no results. Please try different keywords!</p>";
  88. echo "</div>";
  89. }
  90. ?>