2022-02-17 17:14:56 -03:00
|
|
|
<?php
|
2022-03-11 06:04:36 -03:00
|
|
|
$config = require "config.php";
|
|
|
|
require "misc/tools.php";
|
2022-02-24 07:30:15 -03:00
|
|
|
|
|
|
|
if (!isset($_REQUEST["q"]))
|
|
|
|
{
|
2022-10-25 08:02:01 -03:00
|
|
|
echo "<p>Example API request: <a href=\"./api.php?q=gentoo&p=2&t=0\">./api.php?q=gentoo&p=2&t=0</a></p>
|
2022-06-09 05:02:59 -04:00
|
|
|
<br/>
|
|
|
|
<p>\"q\" is the keyword</p>
|
|
|
|
<p>\"p\" is the result page (the first page is 0)</p>
|
2022-12-02 05:41:12 -03:00
|
|
|
<p>\"t\" is the search type (0=text, 1=image, 2=video, 3=torrent, 4=tor)</p>
|
2022-06-09 05:02:59 -04:00
|
|
|
<br/>
|
|
|
|
<p>The results are going to be in JSON format.</p>
|
|
|
|
<p>The API supports both POST and GET requests.</p>";
|
|
|
|
|
2022-02-24 07:30:15 -03:00
|
|
|
die();
|
|
|
|
}
|
2022-02-17 17:14:56 -03:00
|
|
|
|
2022-03-03 06:58:11 -03:00
|
|
|
$query = $_REQUEST["q"];
|
|
|
|
$query_encoded = urlencode($query);
|
2022-02-24 07:30:15 -03:00
|
|
|
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
|
2022-10-25 08:02:01 -03:00
|
|
|
$type = isset($_REQUEST["t"]) ? (int) $_REQUEST["t"] : 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";
|
2022-03-03 06:58:11 -03:00
|
|
|
$results = get_text_results($query, $page);
|
2022-02-25 06:42:32 -03:00
|
|
|
break;
|
|
|
|
case 1:
|
2022-07-08 15:52:26 -04:00
|
|
|
require "engines/qwant/image.php";
|
|
|
|
$results = get_image_results($query_encoded, $page);
|
2022-02-25 06:42:32 -03:00
|
|
|
break;
|
|
|
|
case 2:
|
2023-01-27 14:17:57 -03:00
|
|
|
require "engines/invidious/video.php";
|
2022-09-11 10:54:40 -03:00
|
|
|
$results = get_video_results($query_encoded);
|
2022-02-25 06:42:32 -03:00
|
|
|
break;
|
|
|
|
case 3:
|
2022-03-11 06:04:36 -03:00
|
|
|
if ($config->disable_bittorent_search)
|
2022-02-25 06:42:32 -03:00
|
|
|
$results = array("error" => "disabled");
|
|
|
|
else
|
|
|
|
{
|
2022-02-25 16:26:15 -03:00
|
|
|
require "engines/bittorrent/merge.php";
|
|
|
|
$results = get_merged_torrent_results($query_encoded);
|
2023-01-01 10:43:21 -03:00
|
|
|
}
|
2022-02-25 06:42:32 -03:00
|
|
|
break;
|
2022-11-20 15:00:45 -03:00
|
|
|
case 4:
|
|
|
|
if ($config->disable_hidden_service_search)
|
|
|
|
$results = array("error" => "disabled");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
require "engines/ahmia/hidden_service.php";
|
|
|
|
$results = get_hidden_service_results($query_encoded);
|
2023-01-01 10:43:21 -03:00
|
|
|
}
|
2022-11-20 15:00:45 -03:00
|
|
|
break;
|
2022-02-25 06:42:32 -03:00
|
|
|
default:
|
|
|
|
require "engines/google/text.php";
|
|
|
|
$results = get_text_results($query_encoded, $page);
|
|
|
|
break;
|
|
|
|
}
|
2022-02-17 17:14:56 -03:00
|
|
|
|
2022-06-09 05:02:59 -04:00
|
|
|
header("Content-Type: application/json");
|
2022-11-20 15:00:45 -03:00
|
|
|
echo json_encode($results);
|
2022-09-11 10:54:40 -03:00
|
|
|
?>
|