mirror of
https://github.com/hnhx/librex.git
synced 2025-01-10 11:47:24 -03:00
added yts, nyaa torrent results, added torrent tracker config option
This commit is contained in:
parent
6a5bc4953a
commit
06f4f76959
9 changed files with 168 additions and 38 deletions
4
api.php
4
api.php
|
@ -32,8 +32,8 @@
|
||||||
$results = array("error" => "disabled");
|
$results = array("error" => "disabled");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
require "engines/bittorrent/thepiratebay.php";
|
require "engines/bittorrent/merge.php";
|
||||||
$results = get_thepiratebay_results($query_encoded);
|
$results = get_merged_torrent_results($query_encoded);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
// Disable BitTorrent search
|
// Disable BitTorrent search
|
||||||
$config_disable_bittorent_search = false;
|
$config_disable_bittorent_search = false;
|
||||||
|
|
||||||
|
$config_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";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
youtube.com results will be replaced with the given invidious instance
|
youtube.com results will be replaced with the given invidious instance
|
||||||
Get online invidious instances from here: https://docs.invidious.io/Invidious-Instances.md
|
Get online invidious instances from here: https://docs.invidious.io/Invidious-Instances.md
|
||||||
|
|
46
engines/bittorrent/merge.php
Normal file
46
engines/bittorrent/merge.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
function get_merged_torrent_results($query)
|
||||||
|
{
|
||||||
|
require "engines/bittorrent/thepiratebay.php";
|
||||||
|
require "engines/bittorrent/nyaa.php";
|
||||||
|
require "engines/bittorrent/yts.php";
|
||||||
|
|
||||||
|
$results = array_merge(get_thepiratebay_results($query),
|
||||||
|
get_nyaa_results($query),
|
||||||
|
get_yts_results($query));
|
||||||
|
|
||||||
|
$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 style=\"color:#50fa7b\">$seeders</span> - ";
|
||||||
|
echo "LE: <span style=\"color:#ff79c6\">$leechers</span> - ";
|
||||||
|
echo "$size</span>";
|
||||||
|
echo "</div>";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "</div>";
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
40
engines/bittorrent/nyaa.php
Normal file
40
engines/bittorrent/nyaa.php
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
function get_nyaa_results($query)
|
||||||
|
{
|
||||||
|
require_once "config.php";
|
||||||
|
require_once "misc/tools.php";
|
||||||
|
|
||||||
|
$url = "https://nyaa.si/?q=$query";
|
||||||
|
$response = request($url);
|
||||||
|
$xpath = get_xpath($response);
|
||||||
|
|
||||||
|
$results = array();
|
||||||
|
|
||||||
|
foreach($xpath->query("//tbody/tr") as $result)
|
||||||
|
{
|
||||||
|
global $config_bittorent_trackers;
|
||||||
|
|
||||||
|
$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" => $name,
|
||||||
|
"seeders" => (int) $seeders,
|
||||||
|
"leechers" => (int) $leechers,
|
||||||
|
"magnet" => $magnet,
|
||||||
|
"size" => $size,
|
||||||
|
"source" => "nyaa.si"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
?>
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
function get_thepiratebay_results($query)
|
function get_thepiratebay_results($query)
|
||||||
{
|
{
|
||||||
require "config.php";
|
require_once "config.php";
|
||||||
require "misc/tools.php";
|
require_once "misc/tools.php";
|
||||||
|
|
||||||
$query = urlencode($query);
|
$query = urlencode($query);
|
||||||
|
|
||||||
|
@ -16,20 +16,24 @@
|
||||||
foreach ($json_response as $response)
|
foreach ($json_response as $response)
|
||||||
{
|
{
|
||||||
|
|
||||||
$hash = $response["info_hash"];
|
global $config_bittorent_trackers;
|
||||||
$name = $response["name"];
|
|
||||||
$seeders = $response["seeders"];
|
|
||||||
$leechers = $response["leechers"];
|
|
||||||
|
|
||||||
$magnet = "magnet:?xt=urn:btih:$hash&dn=$name";
|
$size = human_filesize($response["size"]);
|
||||||
|
$hash = $response["info_hash"];
|
||||||
|
$name = $response["name"];
|
||||||
|
$seeders = (int) $response["seeders"];
|
||||||
|
$leechers = (int) $response["leechers"];
|
||||||
|
|
||||||
|
$magnet = "magnet:?xt=urn:btih:$hash&dn=$name$config_bittorent_trackers";
|
||||||
|
|
||||||
array_push($results,
|
array_push($results,
|
||||||
array (
|
array (
|
||||||
"hash" => $hash,
|
"size" => $size,
|
||||||
"name" => $name,
|
"name" => $name,
|
||||||
"seeders" => $seeders,
|
"seeders" => $seeders,
|
||||||
"leechers" => $leechers,
|
"leechers" => $leechers,
|
||||||
"magnet" => $magnet
|
"magnet" => $magnet,
|
||||||
|
"source" => "thepiratebay.org"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -37,28 +41,4 @@
|
||||||
return $results;
|
return $results;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function print_thepiratebay_results($results)
|
|
||||||
{
|
|
||||||
echo "<div class=\"text-result-container\">";
|
|
||||||
|
|
||||||
foreach($results as $result)
|
|
||||||
{
|
|
||||||
$hash = $result["hash"];
|
|
||||||
$name = $result["name"];
|
|
||||||
$seeders = $result["seeders"];
|
|
||||||
$leechers = $result["leechers"];
|
|
||||||
$magnet = $result["magnet"];
|
|
||||||
|
|
||||||
echo "<div class=\"text-result-wrapper\">";
|
|
||||||
echo "<a href=\"$magnet\">";
|
|
||||||
echo "$hash";
|
|
||||||
echo "<h2>$name</h2>";
|
|
||||||
echo "</a>";
|
|
||||||
echo "<span>SE: $seeders - LE: $leechers</span>";
|
|
||||||
echo "</div>";
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "</div>";
|
|
||||||
}
|
|
||||||
?>
|
?>
|
52
engines/bittorrent/yts.php
Normal file
52
engines/bittorrent/yts.php
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
function get_yts_results($query)
|
||||||
|
{
|
||||||
|
require_once "config.php";
|
||||||
|
require_once "misc/tools.php";
|
||||||
|
|
||||||
|
$query = urlencode($query);
|
||||||
|
|
||||||
|
$results = array();
|
||||||
|
|
||||||
|
$url = "https://yts.mx/api/v2/list_movies.json?query_term=$query";
|
||||||
|
$response = request($url);
|
||||||
|
$json_response = json_decode($response, true);
|
||||||
|
|
||||||
|
if ($json_response["data"]["movie_count"] != 0)
|
||||||
|
{
|
||||||
|
foreach ($json_response["data"]["movies"] as $movie)
|
||||||
|
{
|
||||||
|
$name = $movie["title"];
|
||||||
|
$name_encoded = urlencode($name);
|
||||||
|
|
||||||
|
foreach ($movie["torrents"] as $torrent)
|
||||||
|
{
|
||||||
|
global $config_bittorent_trackers;
|
||||||
|
|
||||||
|
$hash = $torrent["hash"];
|
||||||
|
$seeders = $torrent["seeds"];
|
||||||
|
$leechers = $torrent["peers"];
|
||||||
|
$size = $torrent["size"];
|
||||||
|
|
||||||
|
$magnet = "magnet:?xt=urn:btih:$hash&dn=$name_encoded$config_bittorent_trackers";
|
||||||
|
|
||||||
|
array_push($results,
|
||||||
|
array (
|
||||||
|
"size" => $size,
|
||||||
|
"name" => $name,
|
||||||
|
"seeders" => $seeders,
|
||||||
|
"leechers" => $leechers,
|
||||||
|
"magnet" => $magnet,
|
||||||
|
"source" => "yts.mx"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
|
@ -26,6 +26,14 @@
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function human_filesize($bytes, $dec = 2)
|
||||||
|
{
|
||||||
|
$size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
|
||||||
|
$factor = floor((strlen($bytes) - 1) / 3);
|
||||||
|
|
||||||
|
return sprintf("%.{$dec}f ", $bytes / pow(1024, $factor)) . @$size[$factor];
|
||||||
|
}
|
||||||
|
|
||||||
function print_next_page_button($text, $page, $query, $type)
|
function print_next_page_button($text, $page, $query, $type)
|
||||||
{
|
{
|
||||||
echo "<form id=\"page\" action=\"search.php\" target=\"_top\" method=\"post\" enctype=\"multipart/form-data\" autocomplete=\"off\">";
|
echo "<form id=\"page\" action=\"search.php\" target=\"_top\" method=\"post\" enctype=\"multipart/form-data\" autocomplete=\"off\">";
|
||||||
|
|
|
@ -92,9 +92,10 @@
|
||||||
echo "<p class=\"text-result-container\">The host disabled this feature! :C</p>";
|
echo "<p class=\"text-result-container\">The host disabled this feature! :C</p>";
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
require "engines/bittorrent/thepiratebay.php";
|
require "engines/bittorrent/merge.php";
|
||||||
$results = get_thepiratebay_results($query_encoded);
|
$results = get_merged_torrent_results($query_encoded);
|
||||||
print_thepiratebay_results($results);
|
print_merged_torrent_results($results);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -120,6 +120,7 @@ a:hover, .text-result-wrapper h2:hover {
|
||||||
|
|
||||||
.text-result-wrapper {
|
.text-result-wrapper {
|
||||||
max-width: 500px;
|
max-width: 500px;
|
||||||
|
word-wrap: break-word;
|
||||||
margin-top: 35px;
|
margin-top: 35px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue