diff --git a/engines/bittorrent/1337x.php b/engines/bittorrent/1337x.php
index 21a80eb..e7ae3e5 100644
--- a/engines/bittorrent/1337x.php
+++ b/engines/bittorrent/1337x.php
@@ -1,34 +1,39 @@
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;
-
- array_push($results,
- array (
- "name" => htmlspecialchars($name),
- "seeders" => (int) $seeders,
- "leechers" => (int) $leechers,
- "magnet" => htmlspecialchars($magnet),
- "size" => htmlspecialchars($size),
- "source" => "1337x.to"
- )
- );
+ class _1337xRequest extends EngineRequest {
+ public function get_request_url() {
+ $query = urlencode($this->query);
+ return "https://1337x.to/search/$query/1/";
}
- return $results;
+ public function get_results() {
+ $response = curl_multi_getcontent($this->ch);
+
+ $xpath = get_xpath($response);
+ $results = array();
+
+ 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;
+
+ array_push($results,
+ array (
+ "name" => htmlspecialchars($name),
+ "seeders" => (int) $seeders,
+ "leechers" => (int) $leechers,
+ "magnet" => htmlspecialchars($magnet),
+ "size" => htmlspecialchars($size),
+ "source" => "1337x.to"
+ )
+ );
+ }
+
+ return $results;
+ }
}
?>
diff --git a/engines/bittorrent/merge.php b/engines/bittorrent/merge.php
index be4727f..ec99127 100644
--- a/engines/bittorrent/merge.php
+++ b/engines/bittorrent/merge.php
@@ -4,68 +4,32 @@
$this->query = $query;
$this->page = $page;
- // TODO make these engine requests
require "engines/bittorrent/thepiratebay.php";
require "engines/bittorrent/rutor.php";
- require "engines/bittorrent/nyaa.php";
require "engines/bittorrent/yts.php";
require "engines/bittorrent/torrentgalaxy.php";
require "engines/bittorrent/1337x.php";
require "engines/bittorrent/sukebei.php";
- $query = urlencode($query);
-
- $torrent_urls = array(
- $thepiratebay_url,
- $rutor_url,
- $nyaa_url,
- $yts_url,
- $torrentgalaxy_url,
- $_1337x_url,
- $sukebei_url
+ $this->requests = array(
+ new PirateBayRequest($query, $page, $mh, $config),
+ new _1337xRequest($query, $page, $mh, $config),
+ new NyaaRequest($query, $page, $mh, $config),
+ new RutorRequest($query, $page, $mh, $config),
+ new SukebeiRequest($query, $page, $mh, $config),
+ new TorrentGalaxyRequest($query, $page, $mh, $config),
+ new YTSRequest($query, $page, $mh, $config),
);
-
- $this->chs = array();
-
- foreach ($torrent_urls as $url)
- {
- $ch = curl_init($url);
- curl_setopt_array($ch, $config->curl_settings);
- array_push($this->chs, $ch);
- curl_multi_add_handle($mh, $ch);
- }
}
public function get_results() {
$query = urlencode($this->query);
$results = array();
- for ($i=0; count($this->chs)>$i; $i++)
- {
- $response = curl_multi_getcontent($this->chs[$i]);
-
- switch ($i)
- {
- case 0:
- $results = array_merge($results, get_thepiratebay_results($response));
- break;
- case 1:
- $results = array_merge($results, get_rutor_results($response));
- break;
- case 2:
- $results = array_merge($results, get_nyaa_results($response));
- break;
- case 3:
- $results = array_merge($results, get_yts_results($response));
- break;
- case 4:
- //$results = array_merge($results, get_torrentgalaxy_results($response));
- break;
- case 5:
- //$results = array_merge($results, get_1337x_results($response));
- break;
- case 6:
- $results = array_merge($results, get_sukebei_results($response));
- break;
+ foreach ($this->requests as $request) {
+ error_log($request->get_request_url());
+ error_log( curl_getinfo($request->ch)['http_code'] );
+ if ($request->successful()) {
+ $results = array_merge($results, $request->get_results());
}
}
@@ -78,30 +42,29 @@
public static function print_results($results) {
echo "
";
- if (!empty($results))
- {
- foreach($results as $result)
- {
- $source = $result["source"];
- $name = $result["name"];
- $magnet = $result["magnet"];
- $seeders = $result["seeders"];
- $leechers = $result["leechers"];
- $size = $result["size"];
-
- echo "
";
- echo "
";
- echo "$source";
- echo "$name
";
- echo "";
- echo "
SE: $seeders - ";
- echo "LE: $leechers - ";
- echo "$size";
- echo "
";
- }
- }
- else
+ if (empty($results)) {
echo "
There are no results. Please try different keywords!
";
+ return;
+ }
+
+ foreach($results as $result) {
+ $source = $result["source"];
+ $name = $result["name"];
+ $magnet = $result["magnet"];
+ $seeders = $result["seeders"];
+ $leechers = $result["leechers"];
+ $size = $result["size"];
+
+ echo "
";
+ echo "
";
+ echo "$source";
+ echo "$name
";
+ echo "";
+ echo "
SE: $seeders - ";
+ echo "LE: $leechers - ";
+ echo "$size";
+ echo "
";
+ }
echo "
";
}
diff --git a/engines/bittorrent/nyaa.php b/engines/bittorrent/nyaa.php
index e2b846d..9eeb58d 100644
--- a/engines/bittorrent/nyaa.php
+++ b/engines/bittorrent/nyaa.php
@@ -1,35 +1,50 @@
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;
-
- array_push($results,
- array (
- "name" => htmlspecialchars($name),
- "seeders" => (int) $seeders,
- "leechers" => (int) $leechers,
- "magnet" => htmlspecialchars($magnet),
- "size" => htmlspecialchars($size),
- "source" => "nyaa.si"
- )
- );
+ public function get_request_url() {
+ return "https://$this->SOURCE/?q=" . urlencode($this->query);
}
- return $results;
+ public function get_results() {
+ $response = curl_multi_getcontent($this->ch);
+ $xpath = get_xpath($response);
+ $results = array();
+
+ foreach($xpath->query("//tbody/tr") as $result)
+ {
+ $name_node = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result);
+ if ($name_node->length > 0) {
+ $name = $name_node[0]->textContent;
+ } else {
+ $name = "";
+ }
+ $centered = $xpath->evaluate(".//td[@class='text-center']", $result);
+ $magnet_node = $xpath->evaluate(".//a[2]/@href", $centered[0]);
+ if ($magnet_node->length > 0) {
+ $magnet = $magnet_node[0]->textContent;
+ $magnet_without_tracker = explode("&tr=", $magnet)[0];
+ $magnet = $magnet_without_tracker . $this->config->bittorent_trackers;
+ } else {
+ $magnet = "";
+ }
+ $size = $centered[1]->textContent;
+ $seeders = $centered[3]->textContent;
+ $leechers = $centered[4]->textContent;
+
+ array_push($results,
+ array (
+ "name" => htmlspecialchars($name),
+ "seeders" => (int) $seeders,
+ "leechers" => (int) $leechers,
+ "magnet" => htmlspecialchars($magnet),
+ "size" => htmlspecialchars($size),
+ "source" => $this->SOURCE
+ )
+ );
+ }
+
+ return $results;
+ }
}
?>
diff --git a/engines/bittorrent/rutor.php b/engines/bittorrent/rutor.php
index 8369f3e..3bda93f 100644
--- a/engines/bittorrent/rutor.php
+++ b/engines/bittorrent/rutor.php
@@ -1,36 +1,39 @@
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_without_tracker = explode("&tr=", $magnet)[0];
- $magnet = $magnet_without_tracker . $config->bittorent_trackers;
- $td = $xpath->evaluate(".//td", $result);
- $size = $td[count($td) == 5 ? 3 : 2]->textContent;
- $seeders = $xpath->evaluate(".//span", $result)[0]->textContent;
- $leechers = $xpath->evaluate(".//span", $result)[1]->textContent;
-
- array_push($results,
- array (
- "name" => htmlspecialchars($name),
- "seeders" => (int) filter_var($seeders, FILTER_SANITIZE_NUMBER_INT),
- "leechers" => (int) filter_var($leechers, FILTER_SANITIZE_NUMBER_INT),
- "magnet" => htmlspecialchars($magnet),
- "size" => htmlspecialchars($size),
- "source" => "rutor.info"
- )
- );
+ class RutorRequest extends EngineRequest {
+ public function get_request_url() {
+ return "http://rutor.info/search/" . urlencode($this->query);
}
- return $results;
+ public function get_results() {
+ $response = curl_multi_getcontent($this->ch);
+ $xpath = get_xpath($response);
+ $results = array();
+
+
+ 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_without_tracker = explode("&tr=", $magnet)[0];
+ $magnet = $magnet_without_tracker . $this->config->bittorent_trackers;
+ $td = $xpath->evaluate(".//td", $result);
+ $size = $td[count($td) == 5 ? 3 : 2]->textContent;
+ $seeders = $xpath->evaluate(".//span", $result)[0]->textContent;
+ $leechers = $xpath->evaluate(".//span", $result)[1]->textContent;
+
+ array_push($results,
+ array (
+ "name" => htmlspecialchars($name),
+ "seeders" => (int) filter_var($seeders, FILTER_SANITIZE_NUMBER_INT),
+ "leechers" => (int) filter_var($leechers, FILTER_SANITIZE_NUMBER_INT),
+ "magnet" => htmlspecialchars($magnet),
+ "size" => htmlspecialchars($size),
+ "source" => "rutor.info"
+ )
+ );
+ }
+
+ return $results;
+ }
}
?>
diff --git a/engines/bittorrent/sukebei.php b/engines/bittorrent/sukebei.php
index 61485cc..106ff1a 100644
--- a/engines/bittorrent/sukebei.php
+++ b/engines/bittorrent/sukebei.php
@@ -1,44 +1,6 @@
query("//tbody/tr") as $result)
- {
- $name_node = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result);
- if ($name_node->length > 0) {
- $name = $name_node[0]->textContent;
- } else {
- $name = "";
- }
- $centered = $xpath->evaluate(".//td[@class='text-center']", $result);
- $magnet_node = $xpath->evaluate(".//a[2]/@href", $centered[0]);
- if ($magnet_node->length > 0) {
- $magnet = $magnet_node[0]->textContent;
- $magnet_without_tracker = explode("&tr=", $magnet)[0];
- $magnet = $magnet_without_tracker . $config->bittorent_trackers;
- } else {
- $magnet = "";
- }
- $size = $centered[1]->textContent;
- $seeders = $centered[3]->textContent;
- $leechers = $centered[4]->textContent;
-
- array_push($results,
- array (
- "name" => htmlspecialchars($name),
- "seeders" => (int) $seeders,
- "leechers" => (int) $leechers,
- "magnet" => htmlspecialchars($magnet),
- "size" => htmlspecialchars($size),
- "source" => "sukebei.nyaa.si"
- )
- );
- }
- return $results;
+ include "engines/bittorrent/nyaa.php";
+ class SukebeiRequest extends NyaaRequest {
+ public $SOURCE = "sukebei.nyaa.si";
}
?>
diff --git a/engines/bittorrent/thepiratebay.php b/engines/bittorrent/thepiratebay.php
index 49b2476..02375ec 100644
--- a/engines/bittorrent/thepiratebay.php
+++ b/engines/bittorrent/thepiratebay.php
@@ -1,44 +1,46 @@
query);
+ }
- $thepiratebay_url = "https://apibay.org/q.php?q=$query";
+ public function get_results() {
+ $response = curl_multi_getcontent($this->ch);
+ $results = array();
+ $json_response = json_decode($response, true);
- function get_thepiratebay_results($response)
- {
- global $config;
- $results = array();
- $json_response = json_decode($response, true);
+ if (empty($json_response))
+ {
+ return $results;
+ }
+
+ foreach ($json_response as $response)
+ {
+ $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;
+
+ if ($name == "No results returned")
+ break;
+
+ array_push($results,
+ array (
+ "size" => htmlspecialchars($size),
+ "name" => htmlspecialchars($name),
+ "seeders" => (int) htmlspecialchars($seeders),
+ "leechers" => (int) htmlspecialchars($leechers),
+ "magnet" => htmlspecialchars($magnet),
+ "source" => "thepiratebay.org"
+ )
+ );
+ }
- if (empty($json_response))
- {
return $results;
+
}
-
- foreach ($json_response as $response)
- {
- $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;
-
- if ($name == "No results returned")
- break;
-
- array_push($results,
- array (
- "size" => htmlspecialchars($size),
- "name" => htmlspecialchars($name),
- "seeders" => (int) htmlspecialchars($seeders),
- "leechers" => (int) htmlspecialchars($leechers),
- "magnet" => htmlspecialchars($magnet),
- "source" => "thepiratebay.org"
- )
- );
- }
-
- return $results;
-
}
?>
diff --git a/engines/bittorrent/torrentgalaxy.php b/engines/bittorrent/torrentgalaxy.php
index 5d31e82..75c209b 100644
--- a/engines/bittorrent/torrentgalaxy.php
+++ b/engines/bittorrent/torrentgalaxy.php
@@ -1,34 +1,38 @@
query("//div[@class='tgxtablerow txlight']") as $result)
- {
- $name = $xpath->evaluate(".//div[contains(@class, 'clickable-row')]", $result)[0]->textContent;
- $magnet = $xpath->evaluate(".//div[@class='tgxtablecell collapsehide rounded txlight']/a/@href", $result)[1]->textContent;
- $magnet_without_tracker = explode("&tr=", $magnet)[0];
- $magnet = $magnet_without_tracker . $config->bittorent_trackers;
- $size = $xpath->evaluate(".//div[@class='tgxtablecell collapsehide rounded txlight']/span", $result)[0]->textContent;
- $seeders = $xpath->evaluate(".//div[@class='tgxtablecell collapsehide rounded txlight']/span/font", $result)[1]->textContent;
- $leechers = $xpath->evaluate(".//div[@class='tgxtablecell collapsehide rounded txlight']/span/font", $result)[2]->textContent;
-
- array_push($results,
- array (
- "name" => htmlspecialchars($name),
- "seeders" => (int) $seeders,
- "leechers" => (int) $leechers,
- "magnet" => htmlspecialchars($magnet),
- "size" => htmlspecialchars($size),
- "source" => "torrentgalaxy.to"
- )
- );
+ class TorrentGalaxyRequest extends EngineRequest {
+ public function get_request_url() {
+ $query = urlencode($this->query);
+ return "https://torrentgalaxy.to/torrents.php?search=$query#results";
}
- return $results;
- }
+ public function get_results() {
+ $response = curl_multi_getcontent($this->ch);
+ $xpath = get_xpath($response);
+ $results = array();
+
+ foreach($xpath->query("//div[@class='tgxtablerow txlight']") as $result)
+ {
+ $name = $xpath->evaluate(".//div[contains(@class, 'clickable-row')]", $result)[0]->textContent;
+ $magnet = $xpath->evaluate(".//div[@class='tgxtablecell collapsehide rounded txlight']/a/@href", $result)[1]->textContent;
+ $magnet_without_tracker = explode("&tr=", $magnet)[0];
+ $magnet = $magnet_without_tracker . $this->config->bittorent_trackers;
+ $size = $xpath->evaluate(".//div[@class='tgxtablecell collapsehide rounded txlight']/span", $result)[0]->textContent;
+ $seeders = $xpath->evaluate(".//div[@class='tgxtablecell collapsehide rounded txlight']/span/font", $result)[1]->textContent;
+ $leechers = $xpath->evaluate(".//div[@class='tgxtablecell collapsehide rounded txlight']/span/font", $result)[2]->textContent;
+
+ array_push($results,
+ array (
+ "name" => htmlspecialchars($name),
+ "seeders" => (int) $seeders,
+ "leechers" => (int) $leechers,
+ "magnet" => htmlspecialchars($magnet),
+ "size" => htmlspecialchars($size),
+ "source" => "torrentgalaxy.to"
+ )
+ );
+ }
+
+ return $results;
+ }
+ }
?>
diff --git a/engines/bittorrent/yts.php b/engines/bittorrent/yts.php
index f3a588d..ea2fd26 100644
--- a/engines/bittorrent/yts.php
+++ b/engines/bittorrent/yts.php
@@ -1,45 +1,47 @@
bittorent_trackers";
-
- array_push($results,
- array (
- "size" => htmlspecialchars($size),
- "name" => htmlspecialchars($name),
- "seeders" => htmlspecialchars($seeders),
- "leechers" => htmlspecialchars($leechers),
- "magnet" => htmlspecialchars($magnet),
- "source" => "yts.mx"
- )
- );
-
- }
- }
+ class YTSRequest extends EngineRequest {
+ public function get_request_url() {
+ return "https://yts.mx/api/v2/list_movies.json?query_term=" . urlencode($this->query);
}
- return $results;
-
+ public function get_results() {
+ $response = curl_multi_getcontent($this->ch);
+ 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);
+
+ foreach ($movie["torrents"] as $torrent)
+ {
+
+ $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" => htmlspecialchars($size),
+ "name" => htmlspecialchars($name),
+ "seeders" => htmlspecialchars($seeders),
+ "leechers" => htmlspecialchars($leechers),
+ "magnet" => htmlspecialchars($magnet),
+ "source" => "yts.mx"
+ )
+ );
+ }
+ }
+ }
+
+ return $results;
+ }
}
?>
diff --git a/misc/search_engine.php b/misc/search_engine.php
index 28a8b26..c028913 100644
--- a/misc/search_engine.php
+++ b/misc/search_engine.php
@@ -17,6 +17,10 @@
return "";
}
+ public function successful() {
+ return curl_getinfo($this->ch)['http_code'] == '200';
+ }
+
abstract function get_results();
static public function print_results($results){}
}