merge.php 3.4 KB

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