From 603bdb84789bef3c1fd035915d9bf382ec9b9a4a Mon Sep 17 00:00:00 2001 From: amuliang <982632988@qq.com> Date: Sat, 5 Aug 2023 12:49:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=BA=90=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=85=B7=E7=8B=97=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/main.js | 16 +++++----- app/model/SourceModel.js | 19 ++++++++++++ app/model/StoreModel.js | 2 +- app/source/KugouSource.js | 56 +++++++++++++++++++++++++++++++++++ app/source/MyFreemp3Source.js | 17 +---------- html/index.html | 2 +- 6 files changed, 87 insertions(+), 25 deletions(-) create mode 100644 app/source/KugouSource.js diff --git a/app/main.js b/app/main.js index 0860a6a..bb9b51e 100644 --- a/app/main.js +++ b/app/main.js @@ -7,6 +7,7 @@ const { SuccessResult, ErrorResult } = require('./model/ResultModel'); const { QQSource } = require('./source/QQSource'); const mfm = require('./source/MyFreemp3Source'); +const { KugouSource } = require('./source/KugouSource'); // 防止进程中断 // process.on('uncaughtException', function (err) { @@ -18,17 +19,18 @@ const searcher = new SearchModel(); //searcher.registerSourceModel(new QQSource()); searcher.registerSourceModel(new mfm.MyFreemp3QQSource()); searcher.registerSourceModel(new mfm.MyFreemp3NeteaseSource()); -searcher.registerSourceModel(new mfm.MyFreemp3KugouSource()); +//searcher.registerSourceModel(new mfm.MyFreemp3KugouSource()); searcher.registerSourceModel(new mfm.MyFreemp3KuwoSource()); -searcher.registerSourceModel(new mfm.MyFreemp3MiguSource()); +//searcher.registerSourceModel(new mfm.MyFreemp3MiguSource()); searcher.registerSourceModel(new mfm.MyFreemp3QianqianSource()); -searcher.registerSourceModel(new mfm.MyFreemp3QingtingSource()); -searcher.registerSourceModel(new mfm.MyFreemp3XimalayaSource()); -searcher.registerSourceModel(new mfm.MyFreemp3LizhiSource()); -searcher.registerSourceModel(new mfm.MyFreemp3KgSource()); -searcher.registerSourceModel(new mfm.MyFreemp31tingSource()); +//searcher.registerSourceModel(new mfm.MyFreemp3QingtingSource()); +//searcher.registerSourceModel(new mfm.MyFreemp3XimalayaSource()); +//searcher.registerSourceModel(new mfm.MyFreemp3LizhiSource()); +//searcher.registerSourceModel(new mfm.MyFreemp3KgSource()); +//searcher.registerSourceModel(new mfm.MyFreemp31tingSource()); // searcher.registerSourceModel(new mfm.MyFreemp35singycSource()); // searcher.registerSourceModel(new mfm.MyFreemp35singfcSource()); +searcher.registerSourceModel(new KugouSource()); // *********************************************************************** diff --git a/app/model/SourceModel.js b/app/model/SourceModel.js index ddc0a8e..00119f8 100644 --- a/app/model/SourceModel.js +++ b/app/model/SourceModel.js @@ -1,5 +1,7 @@ const _request = require('request'); +const exts = ['mp3', 'acc', 'aiff', 'ape', 'au', 'flac', 'm4a', 'mmf', 'opus', 'voc', 'wav', 'ogg', 'ra', 'dvf', 'taa', 'dsf', 'diff', 'dts', 'wma']; + class SourceModel { constructor() { this.name = ""; @@ -9,6 +11,23 @@ class SourceModel { return this.name; } + checkExtension(ext) { + if(typeof(ext) == 'string' && ext.trim() != '') { + ext = ext.toLowerCase(); + if(exts.indexOf(ext) >= 0) { + return ext; + } + + for(let i = 0; i < exts.length; i++) { + if(ext.indexOf('.'+exts[i]) >= 0) { + return exts[i]; + } + } + } + + return ''; + } + request(options) { return new Promise((resolve, reject) => { _request(options, function(error, response, body) { diff --git a/app/model/StoreModel.js b/app/model/StoreModel.js index 45ea59b..5914350 100644 --- a/app/model/StoreModel.js +++ b/app/model/StoreModel.js @@ -20,7 +20,7 @@ function storeResource(path, url) { return new Promise((resolve, reject) => { mkdirsSync(_path.dirname(path)); const writeableStream = fs.createWriteStream(path); - request.get({ url: url, timeout: 10000 }).pipe(writeableStream).on('close', () => { + request.get({ url: url, timeout: 20000 }).pipe(writeableStream).on('close', () => { resolve(true); }); }); diff --git a/app/source/KugouSource.js b/app/source/KugouSource.js new file mode 100644 index 0000000..97fd9fc --- /dev/null +++ b/app/source/KugouSource.js @@ -0,0 +1,56 @@ +const { SourceModel } = require('../model/SourceModel'); + +class KugouSource extends SourceModel { + constructor() { + super(); + this.name = "酷狗"; + } + + getExtension(url) { + return url.split('.').pop().toLowerCase(); + } + + async search(keywords) { + keywords = encodeURIComponent(keywords); + + let search_result = await this.request({ + url: `https://complexsearch.kugou.com/v2/search/song?callback=callback123&srcappid=2919&clientver=1000&clienttime=1691202199922&mid=32acdcbc2dd5869a4d7b70955007e5ff&uuid=32acdcbc2dd5869a4d7b70955007e5ff&dfid=11S8YH0fnvjm1hFwgx32LHUg&keyword=${keywords}&page=1&pagesize=30&bitrate=0&isfuzzy=0&inputtype=0&platform=WebFilter&userid=0&iscorrection=1&privilege_filter=0&filter=10&token=&appid=1014&signature=51f06a76df41782bbb4072a8337575cd`, + method: 'GET' + }); + let json_string = search_result.replace(/^[^\(]*\(/, '').replace(/\)[^\)]*$/, ''); + let json_data = JSON.parse(json_string); + let list = json_data.data.lists; + + let items = []; + let length = list.length > 10 ? 10 : list.length; + for(let i = 0; i < length; i++) { + let item_link = `https://www.kugou.com/mixsong/${list[i].EMixSongID}.html`; + let item_result = await this.request({ + url: `https://wwwapi.kugou.com/yy/index.php?r=play/getdata&callback=jQuery19108686411456290846_1691202312384&dfid=11S8YH0fnvjm1hFwgx32LHUg&appid=1014&mid=32acdcbc2dd5869a4d7b70955007e5ff&platid=4&encode_album_audio_id=${list[i].EMixSongID}`, + method: 'GET' + }); + let json_string = item_result.replace(/^[^\(]*\(/, '').replace(/\)[^\)]*$/, ''); + let json_data = JSON.parse(json_string); + let item = json_data.data; + items.push({ + title: item.song_name, + author: item.author_name, + url: item.play_url, + link: item_link, + lrc: item.lyrics, + pic: item.img, + source_name: this.getName(), + extension: item.play_url ? this.checkExtension(this.getExtension(item.play_url)) : '' + }); + } + + return items; + } +} + +// let kugou = new KugouSource(); +// kugou.search('吻别'); + +module.exports = { + KugouSource +} \ No newline at end of file diff --git a/app/source/MyFreemp3Source.js b/app/source/MyFreemp3Source.js index 23ca344..c47092f 100644 --- a/app/source/MyFreemp3Source.js +++ b/app/source/MyFreemp3Source.js @@ -1,20 +1,5 @@ const { SourceModel } = require('../model/SourceModel'); -const exts = ['mp3', 'acc', 'aiff', 'ape', 'au', 'flac', 'm4a', 'mmf', 'opus', 'voc', 'wav', 'ogg', 'ra', 'dvf', 'taa', 'dsf', 'diff', 'dts', 'wma']; -function checkExtension(ext) { - if(exts.indexOf(ext) >= 0) { - return ext; - } - - for(let i = 0; i < exts.length; i++) { - if(ext.indexOf('.'+exts[i]) >= 0) { - return exts[i]; - } - } - - return ''; -} - class MyFreemp3Source extends SourceModel { constructor() { super(); @@ -57,7 +42,7 @@ class MyFreemp3Source extends SourceModel { lrc: item.lrc, pic: item.pic, source_name: this.getName(), - extension: item.url ? checkExtension(this.getExtension(item.url)) : '' + extension: item.url ? this.checkExtension(this.getExtension(item.url)) : '' } }); }else { diff --git a/html/index.html b/html/index.html index 7111e47..96250a6 100644 --- a/html/index.html +++ b/html/index.html @@ -123,7 +123,7 @@ data() { const ajax = axios.create({ baseURL: document.location.href.indexOf('localhost') >= 0 ? 'http://localhost:5750' : 'http://musicdlr.amuliang.top:5750', - timeout: 10000, + timeout: 20000, headers: { 'Content-Type': 'application/x-www-form-urlencoded', //'Access-Control-Allow-Origin': true