add try/catch blocks inside all torrent engines

This commit is contained in:
lamacchinadesiderante 2023-04-11 21:40:17 +02:00
parent 0937b73813
commit 36f3b1192d
6 changed files with 109 additions and 88 deletions

View File

@ -3,32 +3,37 @@
function get_1337x_results($response)
{
global $config;
$xpath = get_xpath($response);
$results = array();
try {
global $config;
$xpath = get_xpath($response);
$results = array();
foreach($xpath->query("//table/tbody/tr") as $result)
{
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;
$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.tw"
)
);
array_push($results,
array (
"name" => htmlspecialchars($name),
"seeders" => (int) $seeders,
"leechers" => (int) $leechers,
"magnet" => htmlspecialchars($magnet),
"size" => htmlspecialchars($size),
"source" => "1337x.tw"
)
);
}
return $results;
} catch (Error $e) {
return array();
}
return $results;
}
?>

View File

@ -1,25 +1,26 @@
<?php
$nyaa_url = "https://nyaa.si/?q=$query";
$nyaa_url = "https://nyaa.si/?q=$query";
function get_nyaa_results($response)
{
function get_nyaa_results($response)
{
try {
global $config;
$xpath = get_xpath($response);
$results = array();
foreach($xpath->query("//tbody/tr") as $result)
{
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;
$size = $centered[1]->textContent;
$seeders = $centered[3]->textContent;
$leechers = $centered[4]->textContent;
array_push($results,
array (
array_push(
$results,
array(
"name" => htmlspecialchars($name),
"seeders" => (int) $seeders,
"leechers" => (int) $leechers,
@ -31,5 +32,8 @@
}
return $results;
} catch (Error $e) {
return array();
}
?>
}
?>

View File

@ -1,26 +1,27 @@
<?php
$rutor_url = "http://rutor.info/search/$query";
$rutor_url = "http://rutor.info/search/$query";
function get_rutor_results($response)
{
function get_rutor_results($response)
{
try {
global $config;
$xpath = get_xpath($response);
$results = array();
foreach($xpath->query("//table/tr[@class='gai' or @class='tum']") as $result)
{
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 = $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 (
array_push(
$results,
array(
"name" => htmlspecialchars($name),
"seeders" => (int) remove_special($seeders),
"leechers" => (int) remove_special($leechers),
@ -32,5 +33,9 @@
}
return $results;
} catch (Error $e) {
return array();
}
?>
}
?>

View File

@ -1,25 +1,26 @@
<?php
$sukebei_url = "https://sukebei.nyaa.si/?q=$query";
$sukebei_url = "https://sukebei.nyaa.si/?q=$query";
function get_sukebei_results($response)
{
function get_sukebei_results($response)
{
try {
global $config;
$xpath = get_xpath($response);
$results = array();
foreach($xpath->query("//tbody/tr") as $result)
{
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;
$size = $centered[1]->textContent;
$seeders = $centered[3]->textContent;
$leechers = $centered[4]->textContent;
array_push($results,
array (
array_push(
$results,
array(
"name" => htmlspecialchars($name),
"seeders" => (int) $seeders,
"leechers" => (int) $leechers,
@ -31,5 +32,8 @@
}
return $results;
} catch (Error $e) {
return array();
}
?>
}
?>

View File

@ -1,22 +1,21 @@
<?php
$thepiratebay_url = "https://apibay.org/q.php?q=$query";
$thepiratebay_url = "https://apibay.org/q.php?q=$query";
function get_thepiratebay_results($response)
{
function get_thepiratebay_results($response)
{
try {
global $config;
$results = array();
$json_response = json_decode($response, true);
if (empty($json_response))
{
if (empty($json_response)) {
return $results;
}
foreach ($json_response as $response)
{
foreach ($json_response as $response) {
$size = human_filesize($response["size"]);
$hash = $response["info_hash"];
$hash = $response["info_hash"];
$name = $response["name"];
$seeders = (int) $response["seeders"];
$leechers = (int) $response["leechers"];
@ -26,8 +25,9 @@
if ($name == "No results returned")
break;
array_push($results,
array (
array_push(
$results,
array(
"size" => htmlspecialchars($size),
"name" => htmlspecialchars($name),
"seeders" => (int) htmlspecialchars($seeders),
@ -39,6 +39,8 @@
}
return $results;
} catch (Error $e) {
return array();
}
?>
}
?>

View File

@ -1,31 +1,30 @@
<?php
$yts_url = "https://yts.mx/api/v2/list_movies.json?query_term=$query";
$yts_url = "https://yts.mx/api/v2/list_movies.json?query_term=$query";
function get_yts_results($response)
{
function get_yts_results($response)
{
try {
global $config;
$results = array();
$json_response = json_decode($response, true);
if ($json_response["status"] == "ok" && $json_response["data"]["movie_count"] != 0)
{
foreach ($json_response["data"]["movies"] as $movie)
{
$name = $movie["title"];
$name_encoded = urlencode($name);
if ($json_response["status"] == "ok" && $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)
{
foreach ($movie["torrents"] as $torrent) {
$hash = $torrent["hash"];
$seeders = $torrent["seeds"];
$leechers = $torrent["peers"];
$size = $torrent["size"];
$hash = $torrent["hash"];
$seeders = $torrent["seeds"];
$leechers = $torrent["peers"];
$size = $torrent["size"];
$magnet = "magnet:?xt=urn:btih:$hash&dn=$name_encoded$config->bittorent_trackers";
$magnet = "magnet:?xt=urn:btih:$hash&dn=$name_encoded$config->bittorent_trackers";
array_push($results,
array (
array_push(
$results,
array(
"size" => htmlspecialchars($size),
"name" => htmlspecialchars($name),
"seeders" => htmlspecialchars($seeders),
@ -34,12 +33,14 @@
"source" => "yts.mx"
)
);
}
}
}
}
return $results;
} catch (Error $e) {
return array();
}
?>
}
?>