mirror of
https://github.com/hnhx/librex.git
synced 2025-04-29 14:09:27 -04:00
improved performance for torrent results via curl_multi
This commit is contained in:
parent
e3fbd186ce
commit
b07e6fa0a5
5 changed files with 59 additions and 30 deletions
|
@ -2,19 +2,62 @@
|
||||||
|
|
||||||
function get_merged_torrent_results($query)
|
function get_merged_torrent_results($query)
|
||||||
{
|
{
|
||||||
|
global $config;
|
||||||
|
|
||||||
require "engines/bittorrent/thepiratebay.php";
|
require "engines/bittorrent/thepiratebay.php";
|
||||||
require "engines/bittorrent/rutor.php";
|
require "engines/bittorrent/rutor.php";
|
||||||
require "engines/bittorrent/nyaa.php";
|
require "engines/bittorrent/nyaa.php";
|
||||||
require "engines/bittorrent/yts.php";
|
require "engines/bittorrent/yts.php";
|
||||||
|
|
||||||
$results = array_merge(get_thepiratebay_results($query),
|
$query = urlencode($query);
|
||||||
get_rutor_results($query),
|
|
||||||
get_nyaa_results($query),
|
|
||||||
get_yts_results($query));
|
|
||||||
|
|
||||||
|
$torrent_urls = array(
|
||||||
|
$thepiratebay_url,
|
||||||
|
$rutor_url,
|
||||||
|
$nyaa_url,
|
||||||
|
$yts_url
|
||||||
|
);
|
||||||
|
|
||||||
|
$mh = curl_multi_init();
|
||||||
|
$chs = $results = array();
|
||||||
|
|
||||||
|
foreach ($torrent_urls as $url)
|
||||||
|
{
|
||||||
|
$ch = curl_init($url);
|
||||||
|
curl_setopt_array($ch, $config->curl_settings);
|
||||||
|
array_push($chs, $ch);
|
||||||
|
curl_multi_add_handle($mh, $ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
$running = null;
|
||||||
|
do {
|
||||||
|
curl_multi_exec($mh, $running);
|
||||||
|
} while ($running);
|
||||||
|
|
||||||
|
for ($i=0; count($chs)>$i; $i++)
|
||||||
|
{
|
||||||
|
$response = curl_multi_getcontent($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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$seeders = array_column($results, "seeders");
|
$seeders = array_column($results, "seeders");
|
||||||
array_multisort($seeders, SORT_DESC, $results);
|
array_multisort($seeders, SORT_DESC, $results);
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
function get_nyaa_results($query)
|
$nyaa_url = "https://nyaa.si/?q=$query";
|
||||||
|
|
||||||
|
function get_nyaa_results($response)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$url = "https://nyaa.si/?q=$query";
|
|
||||||
$response = request($url);
|
|
||||||
$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)
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
function get_rutor_results($query)
|
$rutor_url = "http://rutor.info/search/$query";
|
||||||
|
|
||||||
|
function get_rutor_results($response)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$url = "http://rutor.info/search/$query";
|
|
||||||
$response = request($url);
|
|
||||||
$xpath = get_xpath($response);
|
$xpath = get_xpath($response);
|
||||||
|
|
||||||
$results = array();
|
$results = array();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
function get_thepiratebay_results($query)
|
$thepiratebay_url = "https://apibay.org/q.php?q=$query";
|
||||||
|
|
||||||
|
function get_thepiratebay_results($response)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$query = urlencode($query);
|
|
||||||
|
|
||||||
$results = array();
|
$results = array();
|
||||||
|
|
||||||
$url = "https://apibay.org/q.php?q=$query";
|
|
||||||
$response = request($url);
|
|
||||||
$json_response = json_decode($response, true);
|
$json_response = json_decode($response, true);
|
||||||
|
|
||||||
foreach ($json_response as $response)
|
foreach ($json_response as $response)
|
||||||
|
|
|
@ -1,18 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
$yts_url = "https://yts.mx/api/v2/list_movies.json?query_term=$query";
|
||||||
|
|
||||||
function get_yts_results($query)
|
function get_yts_results($response)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$query = urlencode($query);
|
|
||||||
|
|
||||||
$results = array();
|
$results = array();
|
||||||
|
|
||||||
$url = "https://yts.mx/api/v2/list_movies.json?query_term=$query";
|
|
||||||
$response = request($url);
|
|
||||||
$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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue