79 lines
2.1 KiB
PHP
79 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace OCA\NCDownloader\Search\Sites;
|
|
|
|
use OCA\NCDownloader\Tools\Helper;
|
|
|
|
//slider.kz
|
|
class sliderkz extends searchBase implements searchInterface
|
|
{
|
|
public $baseUrl = "https://slider.kz/vk_auth.php";
|
|
protected $query = null;
|
|
protected $tableTitles = [];
|
|
|
|
public function __construct($crawler, $client)
|
|
{
|
|
$this->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);
|
|
if ($this->hasErrors()) {
|
|
return ['error' => $this->getErrors()];
|
|
}
|
|
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 || $this->hasErrors()) {
|
|
return [];
|
|
}
|
|
foreach ($data as $item) {
|
|
if (empty($item)) {
|
|
continue;
|
|
}
|
|
$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();
|
|
if (isset($resp['audios'])) {
|
|
return array_values($resp["audios"])[0];
|
|
}
|
|
} catch (ExceptionInterface $e) {
|
|
$this->errors[] = $e->getMessage();
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
public static function getLabel(): string
|
|
{
|
|
return 'music';
|
|
}
|
|
}
|