merge.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. function get_merged_torrent_results($query)
  3. {
  4. global $config;
  5. $results = array();
  6. $num = array_rand($config->instances);
  7. $instance = $config->instances[$num];
  8. $url = "https://$instance/api.php";
  9. $post_string = "q=$query&t=3";
  10. $api_ch = curl_init($url);
  11. curl_setopt_array($api_ch, $config->curl_settings);
  12. curl_setopt($api_ch, CURLOPT_CUSTOMREQUEST, "POST");
  13. curl_setopt($api_ch, CURLOPT_TIMEOUT, 20); // what
  14. curl_setopt($api_ch, CURLOPT_POSTFIELDS, $post_string);
  15. $results = json_decode(curl_exec($api_ch),true);
  16. //if($results == null) $results = "$instance is broken";
  17. return $results;
  18. }
  19. function print_merged_torrent_results($results)
  20. {
  21. echo "<div class=\"text-result-container\">";
  22. if (!empty($results))
  23. {
  24. foreach($results as $result)
  25. {
  26. $source = $result["source"];
  27. $name = $result["name"];
  28. $magnet = $result["magnet"];
  29. $seeders = $result["seeders"];
  30. $leechers = $result["leechers"];
  31. $size = $result["size"];
  32. echo "<div class=\"text-result-wrapper\">";
  33. echo "<a href=\"$magnet\">";
  34. echo "$source";
  35. echo "<h2>$name</h2>";
  36. echo "</a>";
  37. echo "<span>SE: <span class=\"seeders\">$seeders</span> - ";
  38. echo "LE: <span class=\"leechers\">$leechers</span> - ";
  39. echo "$size</span>";
  40. echo "</div>";
  41. }
  42. }
  43. else
  44. echo "<p>There are no results. Please try different keywords!</p>";
  45. echo "</div>";
  46. }
  47. ?>