some changes for search

This commit is contained in:
huangjx
2022-04-26 18:13:18 +08:00
parent c42be35566
commit 3ac43ec88a
8 changed files with 70 additions and 26 deletions

View File

@@ -2,6 +2,8 @@
namespace OCA\NCDownloader\Search\Sites;
use OCA\NCDownloader\Tools\tableData;
//The Piratebay
class TPB extends searchBase implements searchInterface
{
@@ -14,15 +16,15 @@ class TPB extends searchBase implements searchInterface
$this->client = $client;
$this->crawler = $crawler;
}
public function search(string $keyword): array
public function search(string $keyword): tableData
{
$this->searchUrl = $this->baseUrl . trim($keyword);
$this->crawler->add($this->getContent());
$this->getItems()->addActionLinks(null);
$this->getItems()->addActionLinks();
if ($this->hasErrors()) {
return ['error' => $this->getErrors()];
return tableData::create()->setEror($this->getErrors());
}
return ['title' => $this->getTableTitles(), 'row' => $this->getRows()];
return tableData::create($this->getTableTitles(), $this->getRows());
}
public function setContent($content)
{

View File

@@ -2,6 +2,8 @@
namespace OCA\NCDownloader\Search\Sites;
use OCA\NCDownloader\Tools\tableData;
//bitsearch.to
class bitSearch extends searchBase implements searchInterface
{
@@ -16,17 +18,17 @@ class bitSearch extends searchBase implements searchInterface
$this->client = $client;
$this->crawler = $crawler;
}
public function search(string $keyword): array
public function search(string $keyword): tableData
{
$this->query = ['q' => trim($keyword), 'sort' => 'seeders'];
$this->searchUrl = $this->baseUrl;
$content = $this->getContent();
if ($this->hasErrors()) {
return ['error' => $this->getErrors()];
return tableData::create()->setEror($this->getErrors());
}
$this->crawler->add($content);
$this->getItems()->addActionLinks(null);
return ['title' => $this->getTableTitles(), 'row' => $this->getRows()];
$this->getItems()->addActionLinks();
return tableData::create($this->getTableTitles(), $this->getRows());
}
public function setContent($content)
{

View File

@@ -9,7 +9,6 @@ abstract class searchBase
protected $rows = [];
protected $errors = [];
protected $actionLinks = [["name" => 'download', 'path' => '/index.php/apps/ncdownloader/new'], ['name' => 'clipboard']];
private static $instance = null;
public function getTableTitles(): array
{
@@ -19,14 +18,11 @@ abstract class searchBase
return $this->tableTitles;
}
public static function create($crawler,$client)
public static function create($crawler, $client)
{
if (!self::$instance) {
self::$instance = new static($crawler,$client);
}
return new static($crawler, $client);
return self::$instance;
}
public function setTableTitles(array $titles)
@@ -35,7 +31,7 @@ abstract class searchBase
return $this;
}
protected function addActionLinks(?array $links)
protected function addActionLinks(array $links = null)
{
$links = $links ?? $this->actionLinks;
foreach ($this->rows as $key => &$value) {

View File

@@ -1,10 +1,11 @@
<?php
namespace OCA\NCDownloader\Search\Sites;
use OCA\NCDownloader\Tools\tableData;
interface searchInterface
{
public function search(string $keyword):array;
public function search(string $keyword):tableData;
public function getRows():array;
public function getTableTitles():array;
}

View File

@@ -3,6 +3,7 @@
namespace OCA\NCDownloader\Search\Sites;
use OCA\NCDownloader\Tools\Helper;
use OCA\NCDownloader\Tools\tableData;
//slider.kz
class sliderkz extends searchBase implements searchInterface
@@ -16,15 +17,15 @@ class sliderkz extends searchBase implements searchInterface
$this->client = $client;
}
public function search(string $keyword): array
public function search(string $keyword): tableData
{
$this->query = ['q' => trim($keyword)];
$this->searchUrl = $this->baseUrl;
$this->getItems()->setTableTitles(["Title", "Duration", "Actions"])->addActionLinks(null);
$this->getItems()->setTableTitles(["Title", "Duration", "Actions"])->addActionLinks();
if ($this->hasErrors()) {
return ['error' => $this->getErrors()];
return tableData::create()->setEror($this->getErrors());
}
return ["title" => $this->getTableTitles(), 'row' => $this->getRows()];
return tableData::create($this->getTableTitles(), $this->getRows());
}
public function getItems()