api.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. $config = require "config.php";
  3. require "misc/tools.php";
  4. if (!isset($_REQUEST["q"]))
  5. {
  6. echo "API usage: <a href=\"https://github.com/hnhx/librex/#api\">https://github.com/hnhx/librex/</a>";
  7. die();
  8. }
  9. $query = $_REQUEST["q"];
  10. $query_encoded = urlencode($query);
  11. $page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
  12. $type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0;
  13. $results = array();
  14. switch ($type)
  15. {
  16. case 0:
  17. require "engines/google/text.php";
  18. $results = get_text_results($query, $page);
  19. break;
  20. case 1:
  21. require "engines/google/image.php";
  22. $results = get_image_results($query_encoded);
  23. break;
  24. case 2:
  25. require "engines/google/video.php";
  26. $results = get_video_results($query_encoded, $page);
  27. break;
  28. case 3:
  29. if ($config->disable_bittorent_search)
  30. $results = array("error" => "disabled");
  31. else
  32. {
  33. require "engines/bittorrent/merge.php";
  34. $results = get_merged_torrent_results($query_encoded);
  35. }
  36. break;
  37. default:
  38. require "engines/google/text.php";
  39. $results = get_text_results($query_encoded, $page);
  40. break;
  41. }
  42. header('Content-Type: application/json');
  43. echo json_encode($results, JSON_PRETTY_PRINT);
  44. ?>