This repository has been archived by the owner on Oct 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a4ebc7
commit 56e7e78
Showing
41 changed files
with
2,075 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
error_reporting(E_ERROR | E_PARSE); | ||
$config = require "config.php"; | ||
require "misc/tools.php"; | ||
|
||
if (!isset($_REQUEST['q']) || !isset($_REQUEST['p']) || !isset($_REQUEST['type'])) { | ||
?> | ||
<html> | ||
<head> | ||
<title>GMX - API</title> | ||
</head> | ||
<body> | ||
<center> | ||
<h2>GMX API</h2> | ||
</center> | ||
<hr> | ||
<p>Example API <b>[GET]</b> request: <a href="./api?q=gentoo&p=2&type=0">/api?q=gentoo&p=2&type=0</a></p> | ||
<p style="margin-top: 30px; margin-left: 20px;"><b>"q"</b> is the keyword</p> | ||
<p style="margin-left: 20px;"><b>"p"</b> is the result page <b>(the first page is 0)</b></p> | ||
<p style="margin-left: 20px;"><b>"type"</b> is the search type <b>(0=text, 1=image, 2=video, 3=torrent)</b></p> | ||
<p style="margin-top: 30px;">The results are going to be in <b>JSON format</b>.</p> | ||
<p>The API supports both <b>POST</b> and <b>GET</b> requests.</p> | ||
</body> | ||
</html> | ||
<?php | ||
die(); | ||
} | ||
|
||
$query = $_REQUEST["q"]; | ||
$query_encoded = urlencode($query); | ||
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0; | ||
$type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0; | ||
|
||
$results = array(); | ||
|
||
switch ($type) | ||
{ | ||
case 0: | ||
if(empty($_REQUEST['q'])) $results = print_api_error('query is empty', 'GMX_Q_NO'); | ||
else { | ||
require "engines/google/text.php"; | ||
$results = get_text_results($query, $page); | ||
if(empty($results)) $results = print_api_error('no results found', 'GMX_RES_NO'); | ||
} | ||
break; | ||
case 1: | ||
if(empty($_REQUEST['q'])) $results = print_api_error('query is empty', 'GMX_Q_NO'); | ||
else { | ||
require "engines/google/image.php"; | ||
$results = get_image_results($query_encoded, $page); | ||
if(empty($results)) $results = print_api_error('no results found', 'GMX_RES_NO'); | ||
} | ||
break; | ||
case 2: | ||
if(empty($_REQUEST['q'])) $results = print_api_error('query is empty', 'GMX_Q_NO'); | ||
else { | ||
require "engines/google/video.php"; | ||
$results = get_video_results($query_encoded, $page); | ||
if(empty($results)) $results = print_api_error('no results found', 'GMX_RES_NO'); | ||
} | ||
break; | ||
case 3: | ||
if(empty($_REQUEST['q'])) $results = print_api_error('query is empty', 'GMX_Q_NO'); | ||
else { | ||
if ($config->disable_bittorent_search) | ||
$results = print_api_error('bittorrent search is disabled by host', 'GMX_BIT_DIS'); | ||
else { | ||
require "engines/bittorrent/merge.php"; | ||
$results = get_merged_torrent_results($query_encoded); | ||
if(empty($results)) $results = print_api_error('no results found', 'GMX_RES_NO'); | ||
} | ||
} | ||
break; | ||
default: | ||
if(empty($_REQUEST['q'])) $results = print_api_error('query is empty', 'GMX_Q_NO'); | ||
else { | ||
require "engines/google/text.php"; | ||
$results = get_text_results($query_encoded, $page); | ||
if(empty($results)) $results = print_api_error('no results found', 'GMX_RES_NO'); | ||
} | ||
break; | ||
} | ||
|
||
header("Content-Type: application/json"); | ||
echo json_encode($results, JSON_PRETTY_PRINT); | ||
if(isset($results['error'])) http_response_code('422'); | ||
exit; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
return (object) array( | ||
|
||
// e.g.: fr -> https://google.fr/ | ||
"google_domain" => "com", | ||
|
||
// Google results will be in this language | ||
"google_language" => "en", | ||
|
||
"disable_bittorent_search" => false, | ||
"bittorent_trackers" => "&tr=http%3A%2F%2Fnyaa.tracker.wf%3A7777%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce", | ||
|
||
/* | ||
Preset privacy friendly frontends for users, these can be overwritten by users in settings | ||
e.g.: "invidious" => "https://yewtu.be", | ||
*/ | ||
"invidious" => "", | ||
"bibliogram" => "", | ||
"nitter" => "", | ||
"libreddit" => "", | ||
"proxitok" => "", | ||
"wikiless" => "", | ||
|
||
/* | ||
To send requests trough a proxy uncomment CURLOPT_PROXY and CURLOPT_PROXYTYPE: | ||
CURLOPT_PROXYTYPE options: | ||
CURLPROXY_HTTP | ||
CURLPROXY_SOCKS4 | ||
CURLPROXY_SOCKS4A | ||
CURLPROXY_SOCKS5 | ||
CURLPROXY_SOCKS5_HOSTNAME | ||
!!! ONLY CHANGE THE OTHER OPTIONS IF YOU KNOW WHAT YOU ARE DOING !!! | ||
*/ | ||
"curl_settings" => array( | ||
// CURLOPT_PROXY => "ip:port", | ||
// CURLOPT_PROXYTYPE => CURLPROXY_HTTP, | ||
CURLOPT_RETURNTRANSFER => true, | ||
CURLOPT_ENCODING => "", | ||
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36", | ||
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4, | ||
CURLOPT_CUSTOMREQUEST => "GET", | ||
CURLOPT_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP, | ||
CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP, | ||
CURLOPT_MAXREDIRS => 5, | ||
CURLOPT_TIMEOUT => 8, | ||
CURLOPT_VERBOSE => false | ||
), | ||
|
||
// !!! DO NOT CHANGE THIS !!! | ||
"gmx_version" => "1.0.0" | ||
); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
$_1337x_url = "https://1337x.to/search/$query/1/"; | ||
|
||
function get_1337x_results($response) | ||
{ | ||
global $config; | ||
$xpath = get_xpath($response); | ||
$results = array(); | ||
|
||
if(!is_null($xpath)) { | ||
foreach($xpath->query("//table/tbody/tr") as $result) | ||
{ | ||
|
||
$name = $xpath->evaluate(".//td[@class='coll-1 name']/a", $result)[1]->textContent; | ||
$magnet = "/engines/bittorrent/get_magnet_1337x.php?url=https://1337x.to" . $xpath->evaluate(".//td[@class='coll-1 name']/a/@href", $result)[1]->textContent; | ||
$size_unformatted = explode(" ", $xpath->evaluate(".//td[contains(@class, 'coll-4 size')]", $result)[0]->textContent); | ||
$size = $size_unformatted[0] . " " . preg_replace("/[0-9]+/", "", $size_unformatted[1]); | ||
$seeders = $xpath->evaluate(".//td[@class='coll-2 seeds']", $result)[0]->textContent; | ||
$leechers = $xpath->evaluate(".//td[@class='coll-3 leeches']", $result)[0]->textContent; | ||
|
||
array_push($results, | ||
array ( | ||
"name" => htmlspecialchars($name), | ||
"seeders" => (int) $seeders, | ||
"leechers" => (int) $leechers, | ||
"magnet" => htmlspecialchars($magnet), | ||
"size" => htmlspecialchars($size), | ||
"source" => "1337x.to" | ||
) | ||
); | ||
} | ||
} | ||
|
||
return $results; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
require "../../misc/tools.php"; | ||
$config = require "../../config.php"; | ||
|
||
$url = $_REQUEST["url"]; | ||
|
||
$response = request($url); | ||
$xpath = get_xpath($response); | ||
|
||
$magnet = $xpath->query("//main/div/div/div/div/div/ul/li/a/@href")[0]->textContent; | ||
$magnet_without_tracker = explode("&tr=", $magnet)[0]; | ||
$magnet = $magnet_without_tracker . $config->bittorent_trackers; | ||
|
||
header("Location: $magnet") | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
function get_merged_torrent_results($query) | ||
{ | ||
global $config; | ||
|
||
require "engines/bittorrent/thepiratebay.php"; | ||
require "engines/bittorrent/rutor.php"; | ||
require "engines/bittorrent/nyaa.php"; | ||
require "engines/bittorrent/yts.php"; | ||
require "engines/bittorrent/torrentgalaxy.php"; | ||
require "engines/bittorrent/1337x.php"; | ||
|
||
$query = urlencode($query); | ||
|
||
$torrent_urls = array( | ||
$thepiratebay_url, | ||
$rutor_url, | ||
$nyaa_url, | ||
$yts_url, | ||
$torrentgalaxy_url, | ||
$_1337x_url | ||
); | ||
|
||
$mh = curl_multi_init(); | ||
$chs = $results = array(); | ||
|
||
foreach ($torrent_urls as $url) | ||
{ | ||
$ch = curl_init($url); | ||
curl_setopt_array($ch, $config->curl_settings); | ||
array_push($chs, $ch); | ||
curl_multi_add_handle($mh, $ch); | ||
} | ||
|
||
$running = null; | ||
do { | ||
curl_multi_exec($mh, $running); | ||
} while ($running); | ||
|
||
for ($i=0; count($chs)>$i; $i++) | ||
{ | ||
$response = curl_multi_getcontent($chs[$i]); | ||
|
||
switch ($i) | ||
{ | ||
case 0: | ||
$results = array_merge($results, get_thepiratebay_results($response)); | ||
break; | ||
case 1: | ||
$results = array_merge($results, get_rutor_results($response)); | ||
break; | ||
case 2: | ||
$results = array_merge($results, get_nyaa_results($response)); | ||
break; | ||
case 3: | ||
$results = array_merge($results, get_yts_results($response)); | ||
break; | ||
case 4: | ||
$results = array_merge($results, get_torrentgalaxy_results($response)); | ||
break; | ||
case 5: | ||
$results = array_merge($results, get_1337x_results($response)); | ||
break; | ||
} | ||
} | ||
|
||
$seeders = array_column($results, "seeders"); | ||
array_multisort($seeders, SORT_DESC, $results); | ||
|
||
return $results; | ||
} | ||
|
||
function print_merged_torrent_results($results) | ||
{ | ||
echo "<div class=\"text-result-container\">"; | ||
|
||
foreach($results as $result) | ||
{ | ||
$source = $result["source"]; | ||
$name = $result["name"]; | ||
$magnet = $result["magnet"]; | ||
$seeders = $result["seeders"]; | ||
$leechers = $result["leechers"]; | ||
$size = $result["size"]; | ||
|
||
echo "<div class=\"text-result-wrapper\">"; | ||
echo "<a href=\"$magnet\">"; | ||
echo "$source"; | ||
echo "<h2>$name</h2>"; | ||
echo "</a>"; | ||
echo "<span>SE: <span class=\"seeders\">$seeders</span> - "; | ||
echo "LE: <span class=\"leechers\">$leechers</span> - "; | ||
echo "$size</span>"; | ||
echo "</div>"; | ||
} | ||
|
||
echo "</div>"; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
$nyaa_url = "https://nyaa.si/?q=$query"; | ||
|
||
function get_nyaa_results($response) | ||
{ | ||
global $config; | ||
$xpath = get_xpath($response); | ||
$results = array(); | ||
|
||
if(!is_null($xpath)) { | ||
foreach($xpath->query("//tbody/tr") as $result) | ||
{ | ||
$name = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result)[0]->textContent; | ||
$centered = $xpath->evaluate(".//td[@class='text-center']", $result); | ||
$magnet = $xpath->evaluate(".//a[2]/@href", $centered[0])[0]->textContent; | ||
$magnet_without_tracker = explode("&tr=", $magnet)[0]; | ||
$magnet = $magnet_without_tracker . $config->bittorent_trackers; | ||
$size = $centered[1]->textContent; | ||
$seeders = $centered[3]->textContent; | ||
$leechers = $centered[4]->textContent; | ||
|
||
array_push($results, | ||
array ( | ||
"name" => htmlspecialchars($name), | ||
"seeders" => (int) $seeders, | ||
"leechers" => (int) $leechers, | ||
"magnet" => htmlspecialchars($magnet), | ||
"size" => htmlspecialchars($size), | ||
"source" => "nyaa.si" | ||
) | ||
); | ||
} | ||
} | ||
|
||
return $results; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
$rutor_url = "http://rutor.info/search/$query"; | ||
|
||
function get_rutor_results($response) | ||
{ | ||
global $config; | ||
$xpath = get_xpath($response); | ||
$results = array(); | ||
|
||
if(!is_null($xpath)) { | ||
foreach($xpath->query("//table/tr[@class='gai' or @class='tum']") as $result) | ||
{ | ||
|
||
$name = $xpath->evaluate(".//td/a", $result)[2]->textContent; | ||
$magnet = $xpath->evaluate(".//td/a/@href", $result)[1]->textContent; | ||
$magnet_without_tracker = explode("&tr=", $magnet)[0]; | ||
$magnet = $magnet_without_tracker . $config->bittorent_trackers; | ||
$size = $xpath->evaluate(".//td", $result)[3]->textContent; | ||
$seeders = $xpath->evaluate(".//span", $result)[0]->textContent; | ||
$leechers = $xpath->evaluate(".//span", $result)[1]->textContent; | ||
|
||
array_push($results, | ||
array ( | ||
"name" => htmlspecialchars($name), | ||
"seeders" => (int) remove_special($seeders), | ||
"leechers" => (int) remove_special($leechers), | ||
"magnet" => htmlspecialchars($magnet), | ||
"size" => htmlspecialchars($size), | ||
"source" => "rutor.info" | ||
) | ||
); | ||
} | ||
} | ||
|
||
return $results; | ||
} | ||
?> |
Oops, something went wrong.