2022-02-17 17:14:56 -03:00
|
|
|
<?php
|
2022-02-25 06:42:32 -03:00
|
|
|
require "config.php";
|
2022-02-24 07:30:15 -03:00
|
|
|
|
|
|
|
if (!isset($_REQUEST["q"]))
|
|
|
|
{
|
|
|
|
echo "API usage: <a href=\"https://github.com/hnhx/librex/#api\">https://github.com/hnhx/librex/</a>";
|
|
|
|
die();
|
|
|
|
}
|
2022-02-17 17:14:56 -03:00
|
|
|
|
2022-02-25 06:42:32 -03:00
|
|
|
$query_encoded = urlencode($_REQUEST["q"]);
|
2022-02-24 07:30:15 -03:00
|
|
|
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
|
|
|
|
$type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0;
|
2022-02-17 17:14:56 -03:00
|
|
|
|
2022-02-25 06:42:32 -03:00
|
|
|
$results = array();
|
|
|
|
|
|
|
|
switch ($type)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
require "engines/google/text.php";
|
|
|
|
$results = get_text_results($query_encoded, $page);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
require "engines/google/image.php";
|
|
|
|
$results = get_image_results($query_encoded);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
require "engines/google/video.php";
|
|
|
|
$results = get_video_results($query_encoded, $page);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if ($config_disable_bittorent_search)
|
|
|
|
$results = array("error" => "disabled");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
require "engines/bittorrent/thepiratebay.php";
|
|
|
|
$results = get_thepiratebay_results($query_encoded);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
require "engines/google/text.php";
|
|
|
|
$results = get_text_results($query_encoded, $page);
|
|
|
|
break;
|
|
|
|
}
|
2022-02-17 17:14:56 -03:00
|
|
|
|
2022-02-24 07:30:15 -03:00
|
|
|
header('Content-Type: application/json');
|
2022-02-21 18:00:59 -03:00
|
|
|
echo json_encode($results, JSON_PRETTY_PRINT);
|
2022-02-17 17:14:56 -03:00
|
|
|
?>
|