diff --git a/appinfo/application.php b/appinfo/application.php index 0e0f2b6..567197c 100644 --- a/appinfo/application.php +++ b/appinfo/application.php @@ -6,6 +6,7 @@ use OCA\NCDownloader\Controller\Aria2Controller; use OCA\NCDownloader\Controller\MainController; use OCA\NCDownloader\Controller\YoutubeController; use OCA\NCDownloader\Search\Sites\bitSearch; +use OCA\NCDownloader\Search\Sites\sliderkz; use OCA\NCDownloader\Search\Sites\TPB; use OCA\NCDownloader\Tools\Aria2; use OCA\NCDownloader\Tools\Helper; @@ -85,7 +86,12 @@ class Application extends App return new Crawler(); }); $container->registerService('httpClient', function () { - return HttpClient::create(); + $agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'; + return HttpClient::create([ + 'headers' => [ + 'User-Agent' => $agent, + ], + ]); }); $container->registerService(TPB::class, function (IContainer $container) { $crawler = $container->query('crawler'); @@ -97,6 +103,10 @@ class Application extends App $client = $container->query('httpClient'); return new bitSearch($crawler, $client); }); + $container->registerService(sliderkz::class, function (IContainer $container) { + $client = $container->query('httpClient'); + return new sliderkz($client); + }); } private function getRealDownloadDir() diff --git a/lib/Search/Sites/sliderkz.php b/lib/Search/Sites/sliderkz.php new file mode 100644 index 0000000..4b9a76a --- /dev/null +++ b/lib/Search/Sites/sliderkz.php @@ -0,0 +1,65 @@ +client = $client; + } + public function search(string $keyword): array + { + $this->query = ['q' => trim($keyword)]; + $this->searchUrl = $this->baseUrl; + $this->getItems()->setTableTitles(["Title", "Duration", "Actions"])->addActionLinks(null); + return ["title" => $this->getTableTitles(), 'row' => $this->getRows()]; + } + + public function getItems() + { + $data = $this->getResponse(); + $this->rows = $this->transformResp($data); + return $this; + } + protected function getDownloadUrl(array $item): string + { + extract($item); + return sprintf("https://slider.kz/download/%s/%s/%s/%s.mp3?extra=null", $id, $duration, $url, urlencode($tit_art)); + } + + private function transformResp($data): array + { + $items = []; + if (count($data) < 1) { + return []; + } + foreach ($data as $item) { + $items[] = array("title" => $item["tit_art"], "data-link" => $this->getDownloadUrl($item), "duration" => Helper::formatInterval($item["duration"])); + } + unset($data); + return $items; + } + + public function getResponse(): array + { + + try { + $response = $this->client->request('GET', $this->searchUrl, ['query' => $this->query]); + $resp = $response->toArray(); + } catch (ExceptionInterface $e) { + return ["error" => $e->getMessage()]; + } + if (isset($resp['audios'])) { + return array_values($resp["audios"])[0]; + } + + return []; + } +} diff --git a/src/components/mainForm.vue b/src/components/mainForm.vue index 402f78d..386835b 100644 --- a/src/components/mainForm.vue +++ b/src/components/mainForm.vue @@ -17,7 +17,7 @@ class="search-torrents option-buttons" @click.prevent="whichType('search', $event)" > - Search Torrents + {{ searchLabel }}