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,6 +3,7 @@
function get_1337x_results($response)
{
try {
global $config;
$xpath = get_xpath($response);
$results = array();
@ -30,5 +31,9 @@
}
return $results;
} catch (Error $e) {
return array();
}
}
?>

View File

@ -3,12 +3,12 @@
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;
@ -18,7 +18,8 @@
$seeders = $centered[3]->textContent;
$leechers = $centered[4]->textContent;
array_push($results,
array_push(
$results,
array(
"name" => htmlspecialchars($name),
"seeders" => (int) $seeders,
@ -31,5 +32,8 @@
}
return $results;
} catch (Error $e) {
return array();
}
}
?>

View File

@ -3,13 +3,13 @@
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;
@ -19,7 +19,8 @@
$seeders = $xpath->evaluate(".//span", $result)[0]->textContent;
$leechers = $xpath->evaluate(".//span", $result)[1]->textContent;
array_push($results,
array_push(
$results,
array(
"name" => htmlspecialchars($name),
"seeders" => (int) remove_special($seeders),
@ -32,5 +33,9 @@
}
return $results;
} catch (Error $e) {
return array();
}
}
?>

View File

@ -3,12 +3,12 @@
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;
@ -18,7 +18,8 @@
$seeders = $centered[3]->textContent;
$leechers = $centered[4]->textContent;
array_push($results,
array_push(
$results,
array(
"name" => htmlspecialchars($name),
"seeders" => (int) $seeders,
@ -31,5 +32,8 @@
}
return $results;
} catch (Error $e) {
return array();
}
}
?>

View File

@ -4,17 +4,16 @@
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"];
$name = $response["name"];
@ -26,7 +25,8 @@
if ($name == "No results returned")
break;
array_push($results,
array_push(
$results,
array(
"size" => htmlspecialchars($size),
"name" => htmlspecialchars($name),
@ -39,6 +39,8 @@
}
return $results;
} catch (Error $e) {
return array();
}
}
?>

View File

@ -3,19 +3,17 @@
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)
{
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"];
@ -24,7 +22,8 @@
$magnet = "magnet:?xt=urn:btih:$hash&dn=$name_encoded$config->bittorent_trackers";
array_push($results,
array_push(
$results,
array(
"size" => htmlspecialchars($size),
"name" => htmlspecialchars($name),
@ -40,6 +39,8 @@
}
return $results;
} catch (Error $e) {
return array();
}
}
?>