add try/catch blocks inside all torrent engines #2

Merged
lamacchinadesiderante merged 1 commits from feature/add-try-catch-blocks-to-torrent-engines into master 2023-04-11 19:50:50 +00:00
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

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

View File

@ -1,15 +1,15 @@
<?php <?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; 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,8 +19,9 @@
$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(
array ( $results,
array(
"name" => htmlspecialchars($name), "name" => htmlspecialchars($name),
"seeders" => (int) remove_special($seeders), "seeders" => (int) remove_special($seeders),
"leechers" => (int) remove_special($leechers), "leechers" => (int) remove_special($leechers),
@ -32,5 +33,9 @@
} }
return $results; return $results;
} catch (Error $e) {
return array();
} }
}
?> ?>

View File

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

View File

@ -1,20 +1,19 @@
<?php <?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; 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,8 +25,9 @@
if ($name == "No results returned") if ($name == "No results returned")
break; break;
array_push($results, array_push(
array ( $results,
array(
"size" => htmlspecialchars($size), "size" => htmlspecialchars($size),
"name" => htmlspecialchars($name), "name" => htmlspecialchars($name),
"seeders" => (int) htmlspecialchars($seeders), "seeders" => (int) htmlspecialchars($seeders),
@ -39,6 +39,8 @@
} }
return $results; return $results;
} catch (Error $e) {
return array();
} }
}
?> ?>

View File

@ -1,21 +1,19 @@
<?php <?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; 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,8 +22,9 @@
$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(
array ( $results,
array(
"size" => htmlspecialchars($size), "size" => htmlspecialchars($size),
"name" => htmlspecialchars($name), "name" => htmlspecialchars($name),
"seeders" => htmlspecialchars($seeders), "seeders" => htmlspecialchars($seeders),
@ -40,6 +39,8 @@
} }
return $results; return $results;
} catch (Error $e) {
return array();
} }
}
?> ?>