added experimental support for a music site

This commit is contained in:
huangjx
2022-02-26 22:00:50 +08:00
parent e73440ff03
commit 963334dee5
4 changed files with 106 additions and 10 deletions

View File

@@ -6,6 +6,7 @@ use OCA\NCDownloader\Controller\Aria2Controller;
use OCA\NCDownloader\Controller\MainController; use OCA\NCDownloader\Controller\MainController;
use OCA\NCDownloader\Controller\YoutubeController; use OCA\NCDownloader\Controller\YoutubeController;
use OCA\NCDownloader\Search\Sites\bitSearch; use OCA\NCDownloader\Search\Sites\bitSearch;
use OCA\NCDownloader\Search\Sites\sliderkz;
use OCA\NCDownloader\Search\Sites\TPB; use OCA\NCDownloader\Search\Sites\TPB;
use OCA\NCDownloader\Tools\Aria2; use OCA\NCDownloader\Tools\Aria2;
use OCA\NCDownloader\Tools\Helper; use OCA\NCDownloader\Tools\Helper;
@@ -85,7 +86,12 @@ class Application extends App
return new Crawler(); return new Crawler();
}); });
$container->registerService('httpClient', function () { $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) { $container->registerService(TPB::class, function (IContainer $container) {
$crawler = $container->query('crawler'); $crawler = $container->query('crawler');
@@ -97,6 +103,10 @@ class Application extends App
$client = $container->query('httpClient'); $client = $container->query('httpClient');
return new bitSearch($crawler, $client); return new bitSearch($crawler, $client);
}); });
$container->registerService(sliderkz::class, function (IContainer $container) {
$client = $container->query('httpClient');
return new sliderkz($client);
});
} }
private function getRealDownloadDir() private function getRealDownloadDir()

View File

@@ -0,0 +1,65 @@
<?php
namespace OCA\NCDownloader\Search\Sites;
use OCA\NCDownloader\Tools\Helper;
//slider.kz
class sliderkz extends searchBase
{
public $baseUrl = "https://slider.kz/vk_auth.php";
protected $query = null;
protected $tableTitles = [];
public function __construct($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);
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 [];
}
}

View File

@@ -17,7 +17,7 @@
class="search-torrents option-buttons" class="search-torrents option-buttons"
@click.prevent="whichType('search', $event)" @click.prevent="whichType('search', $event)"
> >
Search Torrents {{ searchLabel }}
</div> </div>
</div> </div>
<div class="action-group"> <div class="action-group">
@@ -36,10 +36,14 @@
> >
</div> </div>
<actionButton className="download-button" @clicked="download"></actionButton> <actionButton className="download-button" @clicked="download"></actionButton>
<uploadFile v-if="downloadType === 'aria2'" @uploadfile="uploadFile" :path="uris.upload_url"></uploadFile> <uploadFile
v-if="downloadType === 'aria2'"
@uploadfile="uploadFile"
:path="uris.upload_url"
></uploadFile>
</div> </div>
</div> </div>
<searchInput v-else @search="search"></searchInput> <searchInput v-else @search="search" @optionSelected="optionCallback"></searchInput>
</div> </div>
</form> </form>
</template> </template>
@@ -48,6 +52,7 @@ import textInput from "./textInput";
import searchInput from "./searchInput.vue"; import searchInput from "./searchInput.vue";
import actionButton from "./actionButton"; import actionButton from "./actionButton";
import uploadFile from "./uploadFile"; import uploadFile from "./uploadFile";
import { translate as t } from "@nextcloud/l10n";
export default { export default {
data() { data() {
@@ -57,7 +62,8 @@ export default {
inputType: "download", inputType: "download",
checkboxes: false, checkboxes: false,
downloadType: "aria2", downloadType: "aria2",
placeholder: "Paste your http/magnet link here", placeholder: t("ncdownloader", "Paste your http/magnet link here"),
searchLabel: t("ncdownloader", "Search Torrents"),
}; };
}, },
components: { components: {
@@ -78,9 +84,8 @@ export default {
this.downloadType = type; this.downloadType = type;
if (type === "aria2") { if (type === "aria2") {
this.path = this.uris.aria2_url; this.path = this.uris.aria2_url;
this.placeholder = "Paste your http/magnet link here";
} else if (type === "youtube-dl") { } else if (type === "youtube-dl") {
this.placeholder = "Paste your video link here"; this.placeholder = t("ncdownloader", "Paste your video link here");
this.path = this.uris.ytd_url; this.path = this.uris.ytd_url;
} else { } else {
this.path = this.uris.search_url; this.path = this.uris.search_url;
@@ -97,6 +102,13 @@ export default {
uploadFile(event, vm) { uploadFile(event, vm) {
this.$emit("uploadfile", event, vm); this.$emit("uploadfile", event, vm);
}, },
optionCallback(option) {
if (option.label.toLowerCase() == "music") {
this.searchLabel = t("ncdownloader", "Search Music");
}else{
this.searchLabel = t("ncdownloader", "Search Torrents");
}
},
}, },
mounted() {}, mounted() {},
name: "mainForm", name: "mainForm",

View File

@@ -2,8 +2,8 @@
<div class="search-input" id="nc-vue-search-input"> <div class="search-input" id="nc-vue-search-input">
<textInput :placeholder="placeholder" dataType="search"></textInput> <textInput :placeholder="placeholder" dataType="search"></textInput>
<div class="search-controls-container"> <div class="search-controls-container">
<div id="select-value-search"> <div id="select-value-search-container">
<select :value="selected"> <select :value="selected" @change="selectHandler" id="select-value-search">
<option <option
v-for="(option, key) in selectOptions" v-for="(option, key) in selectOptions"
v-bind:key="key" v-bind:key="key"
@@ -22,15 +22,17 @@
<script> <script>
import textInput from "./textInput"; import textInput from "./textInput";
import actionButton from "./actionButton"; import actionButton from "./actionButton";
import { translate as t } from "@nextcloud/l10n";
export default { export default {
data() { data() {
return { return {
placeholder: "Enter keyword to search", placeholder: t("ncdownloader", "Enter keyword to search"),
selected: "TPB", selected: "TPB",
selectOptions: [ selectOptions: [
{ name: "TPB", label: "THEPIRATEBAY" }, { name: "TPB", label: "THEPIRATEBAY" },
{ name: "bitSearch", label: "BITSEARCH" }, { name: "bitSearch", label: "BITSEARCH" },
{ name: "sliderkz", label: "MUSIC" },
], ],
}; };
}, },
@@ -42,6 +44,13 @@ export default {
search(event, btnVm) { search(event, btnVm) {
this.$emit("search", event, btnVm); this.$emit("search", event, btnVm);
}, },
selectHandler(event) {
const data = {};
const element = event.target;
data.key = element.value;
data.label = element.options[element.selectedIndex].text;
this.$emit("optionSelected", data);
},
}, },
name: "searchInput", name: "searchInput",
props: [], props: [],