refactor(sdk): tipSearch 全删、歌词解码器归位、IPC 桥移除、api-source 层拆除
- 四平台 tipSearch 全部删除(永不做搜索联想),types 同步去掉 tipSearch 字段 - 歌词解码器归位:kg/krcDecode、tx/qrcDecode、kw/lyricDecode(原 common/ 下三处) - rendererIpc/ipcNames IPC 桥删除,SDK 纯服务端化 - supportQuality 由各平台 apis 内联导出(sdk/index 汇总),kg/kw/tx/wy 改直连 apis/*,api-source 旧层移除
This commit is contained in:
1 parent
3c51e4d06a
commit
66d06ef48a
25 files changed
+42
-342
No files matched your search
+2
-10
@@ -1,5 +1,5 @@
|
||||
import leaderboard from './leaderboard.ts'
|
||||
import { apis } from '../api-source.ts'
|
||||
import kgApi from '../apis/kg.ts'
|
||||
import songList from './songList.ts'
|
||||
import musicSearch from './musicSearch.ts'
|
||||
import pic from './pic.ts'
|
||||
@@ -8,10 +8,8 @@ import hotSearch from './hotSearch.ts'
|
||||
import comment from './comment.ts'
|
||||
import singer from './singer.ts'
|
||||
import album from './album.ts'
|
||||
// import tipSearch from './tipSearch.ts'
|
||||
|
||||
const kg = {
|
||||
// tipSearch,
|
||||
leaderboard,
|
||||
songList,
|
||||
musicSearch,
|
||||
@@ -20,23 +18,17 @@ const kg = {
|
||||
singer,
|
||||
album,
|
||||
getMusicUrl(songInfo, type) {
|
||||
return apis('kg').getMusicUrl!(songInfo, type)
|
||||
return kgApi.getMusicUrl(songInfo, type)
|
||||
},
|
||||
getLyric(songInfo) {
|
||||
return lyric.getLyric(songInfo)
|
||||
},
|
||||
// getLyric(songInfo) {
|
||||
// return apis('kg').getLyric(songInfo)
|
||||
// },
|
||||
getPic(songInfo) {
|
||||
return pic.getPic(songInfo)
|
||||
},
|
||||
getMusicDetailPageUrl(songInfo) {
|
||||
return `https://www.kugou.com/song/#hash=${songInfo.hash}&album_id=${songInfo.albumId}`
|
||||
},
|
||||
// getPic(songInfo) {
|
||||
// return apis('kg').getPic(songInfo)
|
||||
// },
|
||||
}
|
||||
|
||||
export default kg
|
||||
@@ -0,0 +1,78 @@
|
||||
// 酷狗 krc 歌词解码
|
||||
|
||||
import zlib from 'node:zlib'
|
||||
import { decodeName } from '../common/utils.ts'
|
||||
|
||||
// 基于社区通用的 krc 解析思路
|
||||
const enc_key = Buffer.from([0x40, 0x47, 0x61, 0x77, 0x5e, 0x32, 0x74, 0x47, 0x51, 0x36, 0x31, 0x2d, 0xce, 0xd2, 0x6e, 0x69])
|
||||
|
||||
const decodeLyric = str => new Promise((resolve, reject) => {
|
||||
if (!str.length) return
|
||||
const buf_str = Buffer.from(str, 'base64').subarray(4)
|
||||
for (let i = 0, len = buf_str.length; i < len; i++) {
|
||||
buf_str[i] = buf_str[i] ^ enc_key[i % 16]
|
||||
}
|
||||
zlib.inflate(buf_str, (err, result) => {
|
||||
if (err) return reject(err)
|
||||
resolve(result.toString())
|
||||
})
|
||||
})
|
||||
|
||||
const headExp = /^.*\[id:\$\w+\]\n/
|
||||
|
||||
const parseLyric = str => {
|
||||
str = str.replace(/\r/g, '')
|
||||
if (headExp.test(str)) str = str.replace(headExp, '')
|
||||
let trans = str.match(/\[language:([\w=\\/+]+)\]/)
|
||||
let lyric
|
||||
let rlyric
|
||||
let tlyric
|
||||
if (trans) {
|
||||
str = str.replace(/\[language:[\w=\\/+]+\]\n/, '')
|
||||
let json = JSON.parse(Buffer.from(trans[1], 'base64').toString())
|
||||
for (const item of json.content) {
|
||||
switch (item.type) {
|
||||
case 0:
|
||||
rlyric = item.lyricContent
|
||||
break
|
||||
case 1:
|
||||
tlyric = item.lyricContent
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
let i = 0
|
||||
let yrc = str.replace(/\[((\d+),\d+)\].*/g, str => {
|
||||
let result = str.match(/\[((\d+),\d+)\].*/)
|
||||
let time: any = parseInt(result[2])
|
||||
let ms = time % 1000
|
||||
time /= 1000
|
||||
let m = Math.trunc(time / 60).toString().padStart(2, '0')
|
||||
time %= 60
|
||||
let s = Math.trunc(time).toString().padStart(2, '0')
|
||||
time = `${m}:${s}.${ms}`
|
||||
if (rlyric) rlyric[i] = `[${time}]${rlyric[i]?.join('') ?? ''}`
|
||||
if (tlyric) tlyric[i] = `[${time}]${tlyric[i]?.join('') ?? ''}`
|
||||
i++
|
||||
return str.replace(result[1], time)
|
||||
})
|
||||
rlyric = rlyric ? rlyric.join('\n') : ''
|
||||
tlyric = tlyric ? tlyric.join('\n') : ''
|
||||
yrc = yrc.replace(/<(\d+,\d+),\d+>/g, '<$1>')
|
||||
yrc = decodeName(yrc)
|
||||
lyric = yrc.replace(/<\d+,\d+>/g, '')
|
||||
rlyric = decodeName(rlyric)
|
||||
tlyric = decodeName(tlyric)
|
||||
return {
|
||||
lyric,
|
||||
tlyric,
|
||||
rlyric,
|
||||
yrc,
|
||||
}
|
||||
}
|
||||
|
||||
export const decodeKrc = async data => {
|
||||
return decodeLyric(data).then(parseLyric)
|
||||
}
|
||||
|
||||
export default { decodeKrc }
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { decodeKrc } from '../common/lyricUtils/kg.ts'
|
||||
import { decodeKrc } from './krcDecode.ts'
|
||||
|
||||
export default {
|
||||
getIntv(interval) {
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import { createHttpFetch } from './util.ts'
|
||||
|
||||
export default {
|
||||
requestObj: null as any,
|
||||
cancelTipSearch() {
|
||||
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
||||
},
|
||||
tipSearchBySong(str) {
|
||||
this.cancelTipSearch()
|
||||
this.requestObj = createHttpFetch(`https://searchtip.kugou.com/getSearchTip?MusicTipCount=10&keyword=${encodeURIComponent(str)}`, {
|
||||
headers: {
|
||||
referer: 'https://www.kugou.com/',
|
||||
},
|
||||
})
|
||||
return this.requestObj.then(body => {
|
||||
return body[0].RecordDatas
|
||||
})
|
||||
},
|
||||
handleResult(rawData) {
|
||||
return rawData.map(info => info.HintInfo)
|
||||
},
|
||||
async search(str) {
|
||||
return this.tipSearchBySong(str).then(result => this.handleResult(result))
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user