added one more bt site;added the option for choosing a site to search torrents

This commit is contained in:
huangjx
2021-09-17 14:32:22 +08:00
parent 7427f395f5
commit de2afbb0ef
10 changed files with 200 additions and 47 deletions

View File

@@ -3,25 +3,35 @@
namespace OCA\NCDownloader\Search;
require __DIR__ . "/../../vendor/autoload.php";
use OCA\NCDownloader\Search\Sites\TPB;
use OCA\NCDownloader\Tools\Helper;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\HttpClient\HttpClient;
use OCP\IServerContainer;
class torrentSearch
{
public static function go($keyword)
public $container;
private $site = null;
public function __construct()
{
$client = HttpClient::create();
$crawler = new Crawler();
$tpb = new TPB($crawler, $client);
$data = $tpb->search($keyword);
self::addAction($data);
$this->container = \OC::$server->query(IServerContainer::class);
$this->site = __NAMESPACE__ . '\Sites\TPB';
}
public function go($keyword)
{
$siteInst = $this->container->query($this->site);
$data = $siteInst->search($keyword);
$this->addAction($data);
return $data;
}
private static function addAction(&$data)
public function setSite($site)
{
if (strpos($site, '\\') !== false) {
$this->site = $site;
} else {
$this->site = __NAMESPACE__ . '\Sites\\' . $site;
}
}
private function addAction(&$data)
{
foreach ($data as $key => &$value) {
if (!$value) {