diff --git a/lib/Search/Sites/TPB.php b/lib/Search/Sites/TPB.php index 5bf3bb2..a1756c8 100644 --- a/lib/Search/Sites/TPB.php +++ b/lib/Search/Sites/TPB.php @@ -19,6 +19,9 @@ class TPB extends searchBase implements searchInterface $this->searchUrl = $this->baseUrl . trim($keyword); $this->crawler->add($this->getContent()); $this->getItems()->addActionLinks(null); + if ($this->hasErrors()) { + return ['error' => $this->getErrors()]; + } return ['title' => $this->getTableTitles(), 'row' => $this->getRows()]; } public function setContent($content) @@ -30,8 +33,15 @@ class TPB extends searchBase implements searchInterface if ($this->content) { return $this->content; } - $response = $this->client->request('GET', $this->searchUrl); - return $response->getContent(); + $content; + try { + $response = $this->client->request('GET', $this->searchUrl); + $content = $response->getContent(); + } catch (\Exception $e) { + $this->errors[] = $e->getMessage(); + return []; + } + return $content; } public function parse() { diff --git a/lib/Search/Sites/bitSearch.php b/lib/Search/Sites/bitSearch.php index 1cc9199..03e1817 100644 --- a/lib/Search/Sites/bitSearch.php +++ b/lib/Search/Sites/bitSearch.php @@ -20,9 +20,13 @@ class bitSearch extends searchBase implements searchInterface { $this->query = ['q' => trim($keyword), 'sort' => 'seeders']; $this->searchUrl = $this->baseUrl; - $this->crawler->add($this->getContent()); + $content = $this->getContent(); + if ($this->hasErrors()) { + return ['error' => $this->getErrors()]; + } + $this->crawler->add($content); $this->getItems()->addActionLinks(null); - return ['title' =>$this->getTableTitles(), 'row' => $this->getRows()]; + return ['title' => $this->getTableTitles(), 'row' => $this->getRows()]; } public function setContent($content) { @@ -33,8 +37,15 @@ class bitSearch extends searchBase implements searchInterface if ($this->content) { return $this->content; } - $response = $this->client->request('GET', $this->searchUrl, ['query' => $this->query]); - return $response->getContent(); + $content; + try { + $response = $this->client->request('GET', $this->searchUrl, ['query' => $this->query]); + $content = $response->getContent(); + } catch (\Exception $e) { + $this->errors[] = $e->getMessage(); + return []; + } + return $content; } public function parse() diff --git a/lib/Search/Sites/searchBase.php b/lib/Search/Sites/searchBase.php index 862a0ee..0a3b65a 100644 --- a/lib/Search/Sites/searchBase.php +++ b/lib/Search/Sites/searchBase.php @@ -7,6 +7,7 @@ abstract class searchBase protected $query = null; protected $tableTitles = []; protected $rows = []; + protected $errors = []; protected $actionLinks = [["name" => 'download', 'path' => '/index.php/apps/ncdownloader/new'], ['name' => 'clipboard']]; public function getTableTitles(): array @@ -38,4 +39,14 @@ abstract class searchBase return $this->rows; } + public function hasErrors(): bool + { + return (bool) (count($this->errors) > 0); + } + + public function getErrors(): string + { + return implode(",", $this->errors); + } + } diff --git a/lib/Search/Sites/sliderkz.php b/lib/Search/Sites/sliderkz.php index 4b9a76a..7f25bcc 100644 --- a/lib/Search/Sites/sliderkz.php +++ b/lib/Search/Sites/sliderkz.php @@ -1,15 +1,15 @@ client = $client; @@ -19,6 +19,9 @@ class sliderkz extends searchBase $this->query = ['q' => trim($keyword)]; $this->searchUrl = $this->baseUrl; $this->getItems()->setTableTitles(["Title", "Duration", "Actions"])->addActionLinks(null); + if ($this->hasErrors()) { + return ['error' => $this->getErrors()]; + } return ["title" => $this->getTableTitles(), 'row' => $this->getRows()]; } @@ -37,7 +40,7 @@ class sliderkz extends searchBase private function transformResp($data): array { $items = []; - if (count($data) < 1) { + if (count($data) < 1 || $this->hasErrors()) { return []; } foreach ($data as $item) { @@ -54,7 +57,8 @@ class sliderkz extends searchBase $response = $this->client->request('GET', $this->searchUrl, ['query' => $this->query]); $resp = $response->toArray(); } catch (ExceptionInterface $e) { - return ["error" => $e->getMessage()]; + $this->errors[] = $e->getMessage(); + return []; } if (isset($resp['audios'])) { return array_values($resp["audios"])[0]; diff --git a/src/App.vue b/src/App.vue index 1116b03..76c99c6 100644 --- a/src/App.vue +++ b/src/App.vue @@ -96,6 +96,10 @@ export default { tableInst.rowClass = "table-row-search"; tableInst.create(); } + if (data.error) { + helper.resetSearch(vm); + helper.error(data.error); + } }) .send(); }, diff --git a/src/utils/helper.js b/src/utils/helper.js index 9463425..aba3181 100644 --- a/src/utils/helper.js +++ b/src/utils/helper.js @@ -248,7 +248,11 @@ const helper = { } }, t: function (str) { - return t("ncdownloader", str); + return t("ncdownloader", str); + }, + resetSearch: function (vm) { + vm.$data.loading = 0; + contentTable.getInstance([], []).clear(); } }