Merge pull request 'add try/catch blocks inside all torrent engines' (#2) from feature/add-try-catch-blocks-to-torrent-engines into master

Reviewed-on: #2
This commit is contained in:
lamacchinadesiderante 2023-04-11 19:50:49 +00:00
commit 71bcbdc808
6 changed files with 109 additions and 88 deletions

View File

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

View File

@ -3,12 +3,12 @@
function get_nyaa_results($response) function get_nyaa_results($response)
{ {
try {
global $config; global $config;
$xpath = get_xpath($response); $xpath = get_xpath($response);
$results = array(); $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; $name = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result)[0]->textContent;
$centered = $xpath->evaluate(".//td[@class='text-center']", $result); $centered = $xpath->evaluate(".//td[@class='text-center']", $result);
$magnet = $xpath->evaluate(".//a[2]/@href", $centered[0])[0]->textContent; $magnet = $xpath->evaluate(".//a[2]/@href", $centered[0])[0]->textContent;
@ -18,7 +18,8 @@
$seeders = $centered[3]->textContent; $seeders = $centered[3]->textContent;
$leechers = $centered[4]->textContent; $leechers = $centered[4]->textContent;
array_push($results, array_push(
$results,
array( array(
"name" => htmlspecialchars($name), "name" => htmlspecialchars($name),
"seeders" => (int) $seeders, "seeders" => (int) $seeders,
@ -31,5 +32,8 @@
} }
return $results; return $results;
} catch (Error $e) {
return array();
}
} }
?> ?>

View File

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

View File

@ -3,12 +3,12 @@
function get_sukebei_results($response) function get_sukebei_results($response)
{ {
try {
global $config; global $config;
$xpath = get_xpath($response); $xpath = get_xpath($response);
$results = array(); $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; $name = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result)[0]->textContent;
$centered = $xpath->evaluate(".//td[@class='text-center']", $result); $centered = $xpath->evaluate(".//td[@class='text-center']", $result);
$magnet = $xpath->evaluate(".//a[2]/@href", $centered[0])[0]->textContent; $magnet = $xpath->evaluate(".//a[2]/@href", $centered[0])[0]->textContent;
@ -18,7 +18,8 @@
$seeders = $centered[3]->textContent; $seeders = $centered[3]->textContent;
$leechers = $centered[4]->textContent; $leechers = $centered[4]->textContent;
array_push($results, array_push(
$results,
array( array(
"name" => htmlspecialchars($name), "name" => htmlspecialchars($name),
"seeders" => (int) $seeders, "seeders" => (int) $seeders,
@ -31,5 +32,8 @@
} }
return $results; return $results;
} catch (Error $e) {
return array();
}
} }
?> ?>

View File

@ -4,17 +4,16 @@
function get_thepiratebay_results($response) function get_thepiratebay_results($response)
{ {
try {
global $config; global $config;
$results = array(); $results = array();
$json_response = json_decode($response, true); $json_response = json_decode($response, true);
if (empty($json_response)) if (empty($json_response)) {
{
return $results; return $results;
} }
foreach ($json_response as $response) foreach ($json_response as $response) {
{
$size = human_filesize($response["size"]); $size = human_filesize($response["size"]);
$hash = $response["info_hash"]; $hash = $response["info_hash"];
$name = $response["name"]; $name = $response["name"];
@ -26,7 +25,8 @@
if ($name == "No results returned") if ($name == "No results returned")
break; break;
array_push($results, array_push(
$results,
array( array(
"size" => htmlspecialchars($size), "size" => htmlspecialchars($size),
"name" => htmlspecialchars($name), "name" => htmlspecialchars($name),
@ -39,6 +39,8 @@
} }
return $results; return $results;
} catch (Error $e) {
return array();
}
} }
?> ?>

View File

@ -3,19 +3,17 @@
function get_yts_results($response) function get_yts_results($response)
{ {
try {
global $config; global $config;
$results = array(); $results = array();
$json_response = json_decode($response, true); $json_response = json_decode($response, true);
if ($json_response["status"] == "ok" && $json_response["data"]["movie_count"] != 0) if ($json_response["status"] == "ok" && $json_response["data"]["movie_count"] != 0) {
{ foreach ($json_response["data"]["movies"] as $movie) {
foreach ($json_response["data"]["movies"] as $movie)
{
$name = $movie["title"]; $name = $movie["title"];
$name_encoded = urlencode($name); $name_encoded = urlencode($name);
foreach ($movie["torrents"] as $torrent) foreach ($movie["torrents"] as $torrent) {
{
$hash = $torrent["hash"]; $hash = $torrent["hash"];
$seeders = $torrent["seeds"]; $seeders = $torrent["seeds"];
@ -24,7 +22,8 @@
$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_push(
$results,
array( array(
"size" => htmlspecialchars($size), "size" => htmlspecialchars($size),
"name" => htmlspecialchars($name), "name" => htmlspecialchars($name),
@ -40,6 +39,8 @@
} }
return $results; return $results;
} catch (Error $e) {
return array();
}
} }
?> ?>