refactor(sdk): musicSdk 全量迁移至 TypeScript
This commit is contained in:
1 parent
f289df4cd7
commit
1dfb7a59ca
83 files changed
+924
-732
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { getMusicInfosByList } from './musicInfo.js'
|
||||
import { createHttpFetch } from './util.js'
|
||||
import { getMusicInfosByList } from './musicInfo.ts'
|
||||
import { createHttpFetch } from './util.ts'
|
||||
|
||||
export default {
|
||||
/**
|
||||
@@ -1,11 +1,12 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import { decodeName, dateFormat2 } from '../index.js'
|
||||
import { signatureParams } from './util.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { decodeName, dateFormat2 } from '../index.ts'
|
||||
import { signatureParams } from './util.ts'
|
||||
// import { getMusicInfoRaw } from './musicInfo.js'
|
||||
import type { HttpRequestObject } from '../types.ts'
|
||||
|
||||
export default {
|
||||
_requestObj: null,
|
||||
_requestObj2: null,
|
||||
_requestObj: null as HttpRequestObject | null,
|
||||
_requestObj2: null as HttpRequestObject | null,
|
||||
async getComment({ hash }, page = 1, limit = 20) {
|
||||
if (this._requestObj) this._requestObj.cancelHttp()
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import { decodeName } from '../index.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { decodeName } from '../index.ts'
|
||||
import type { HttpRequestObject } from '../types.ts'
|
||||
|
||||
export default {
|
||||
_requestObj: null,
|
||||
_requestObj: null as HttpRequestObject | null,
|
||||
async getList(retryNum = 0) {
|
||||
if (this._requestObj) this._requestObj.cancelHttp()
|
||||
if (retryNum > 2) return Promise.reject(new Error('try max num'))
|
||||
@@ -12,10 +13,10 @@ export default {
|
||||
headers: {
|
||||
dfid: '1ssiv93oVqMp27cirf2CvoF1',
|
||||
mid: '156798703528610303473757548878786007104',
|
||||
clienttime: 1584257267,
|
||||
clienttime: '1584257267',
|
||||
'x-router': 'msearch.kugou.com',
|
||||
'user-agent': 'Android9-AndroidPhone-10020-130-0-searchrecommendprotocol-wifi',
|
||||
'kg-rc': 1,
|
||||
'kg-rc': '1',
|
||||
},
|
||||
})
|
||||
const { body, statusCode } = await _requestObj.promise
|
||||
@@ -24,7 +25,7 @@ export default {
|
||||
return { source: 'kg', list: this.filterList(body.data.list) }
|
||||
},
|
||||
filterList(rawList) {
|
||||
const list = []
|
||||
const list: string[] = []
|
||||
rawList.forEach(item => {
|
||||
item.keywords.map(k => list.push(decodeName(k.keyword)))
|
||||
})
|
||||
@@ -1,11 +1,11 @@
|
||||
import leaderboard from './leaderboard.js'
|
||||
import { apis } from '../api-source.js'
|
||||
import songList from './songList.js'
|
||||
import musicSearch from './musicSearch.js'
|
||||
import pic from './pic.js'
|
||||
import lyric from './lyric.js'
|
||||
import hotSearch from './hotSearch.js'
|
||||
import comment from './comment.js'
|
||||
import leaderboard from './leaderboard.ts'
|
||||
import { apis } from '../api-source.ts'
|
||||
import songList from './songList.ts'
|
||||
import musicSearch from './musicSearch.ts'
|
||||
import pic from './pic.ts'
|
||||
import lyric from './lyric.ts'
|
||||
import hotSearch from './hotSearch.ts'
|
||||
import comment from './comment.ts'
|
||||
// import tipSearch from './tipSearch.js'
|
||||
|
||||
const kg = {
|
||||
@@ -16,7 +16,7 @@ const kg = {
|
||||
hotSearch,
|
||||
comment,
|
||||
getMusicUrl(songInfo, type) {
|
||||
return apis('kg').getMusicUrl(songInfo, type)
|
||||
return apis('kg').getMusicUrl!(songInfo, type)
|
||||
},
|
||||
getLyric(songInfo) {
|
||||
return lyric.getLyric(songInfo)
|
||||
@@ -1,6 +1,7 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import { decodeName, formatPlayTime, sizeFormate } from '../index.js'
|
||||
import { formatSingerName } from '../utils.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { decodeName, formatPlayTime, sizeFormate } from '../index.ts'
|
||||
import { formatSingerName } from '../utils.ts'
|
||||
import type { HttpRequestObject, SongType, QualityInfo } from '../types.ts'
|
||||
|
||||
let boardList = [{ id: 'kg__8888', name: 'TOP500', bangid: '8888' }, { id: 'kg__6666', name: '飙升榜', bangid: '6666' }, { id: 'kg__59703', name: '蜂鸟流行音乐榜', bangid: '59703' }, { id: 'kg__52144', name: '抖音热歌榜', bangid: '52144' }, { id: 'kg__52767', name: '快手热歌榜', bangid: '52767' }, { id: 'kg__24971', name: 'DJ热歌榜', bangid: '24971' }, { id: 'kg__23784', name: '网络红歌榜', bangid: '23784' }, { id: 'kg__44412', name: '说唱先锋榜', bangid: '44412' }, { id: 'kg__31308', name: '内地榜', bangid: '31308' }, { id: 'kg__33160', name: '电音榜', bangid: '33160' }, { id: 'kg__31313', name: '香港地区榜', bangid: '31313' }, { id: 'kg__51341', name: '民谣榜', bangid: '51341' }, { id: 'kg__54848', name: '台湾地区榜', bangid: '54848' }, { id: 'kg__31310', name: '欧美榜', bangid: '31310' }, { id: 'kg__33162', name: 'ACG新歌榜', bangid: '33162' }, { id: 'kg__31311', name: '韩国榜', bangid: '31311' }, { id: 'kg__31312', name: '日本榜', bangid: '31312' }, { id: 'kg__49225', name: '80后热歌榜', bangid: '49225' }, { id: 'kg__49223', name: '90后热歌榜', bangid: '49223' }, { id: 'kg__49224', name: '00后热歌榜', bangid: '49224' }, { id: 'kg__33165', name: '粤语金曲榜', bangid: '33165' }, { id: 'kg__33166', name: '欧美金曲榜', bangid: '33166' }, { id: 'kg__33163', name: '影视金曲榜', bangid: '33163' }, { id: 'kg__51340', name: '伤感榜', bangid: '51340' }, { id: 'kg__35811', name: '会员专享榜', bangid: '35811' }, { id: 'kg__37361', name: '雷达榜', bangid: '37361' }, { id: 'kg__21101', name: '分享榜', bangid: '21101' }, { id: 'kg__46910', name: '综艺新歌榜', bangid: '46910' }, { id: 'kg__30972', name: '酷狗音乐人原创榜', bangid: '30972' }, { id: 'kg__60170', name: '闽南语榜', bangid: '60170' }, { id: 'kg__65234', name: '儿歌榜', bangid: '65234' }, { id: 'kg__4681', name: '美国BillBoard榜', bangid: '4681' }, { id: 'kg__25028', name: 'Beatport电子舞曲榜', bangid: '25028' }, { id: 'kg__4680', name: '英国单曲榜', bangid: '4680' }, { id: 'kg__38623', name: '韩国Melon音乐榜', bangid: '38623' }, { id: 'kg__42807', name: 'joox本地热歌榜', bangid: '42807' }, { id: 'kg__36107', name: '小语种热歌榜', bangid: '36107' }, { id: 'kg__4673', name: '日本公信榜', bangid: '4673' }, { id: 'kg__46868', name: '日本SPACE SHOWER榜', bangid: '46868' }, { id: 'kg__42808', name: 'KKBOX风云榜', bangid: '42808' }, { id: 'kg__60171', name: '越南语榜', bangid: '60171' }, { id: 'kg__60172', name: '泰语榜', bangid: '60172' }, { id: 'kg__59895', name: 'R&B榜', bangid: '59895' }, { id: 'kg__59896', name: '摇滚榜', bangid: '59896' }, { id: 'kg__59897', name: '爵士榜', bangid: '59897' }, { id: 'kg__59898', name: '乡村音乐榜', bangid: '59898' }, { id: 'kg__59900', name: '纯音乐榜', bangid: '59900' }, { id: 'kg__59899', name: '古典榜', bangid: '59899' }, { id: 'kg__22603', name: '5sing音乐榜', bangid: '22603' }, { id: 'kg__21335', name: '繁星音乐榜', bangid: '21335' }, { id: 'kg__33161', name: '古风新歌榜', bangid: '33161' }]
|
||||
|
||||
@@ -72,18 +73,18 @@ export default {
|
||||
limit: /pagesize: '(\d+)',/,
|
||||
listData: /global\.features = (\[.+\]);/,
|
||||
},
|
||||
_requestBoardsObj: null,
|
||||
_requestBoardsObj: null as HttpRequestObject | null,
|
||||
getBoardsData() {
|
||||
if (this._requestBoardsObj) this._requestBoardsObj.cancelHttp()
|
||||
this._requestBoardsObj = httpFetch('http://mobilecdnbj.kugou.com/api/v5/rank/list?version=9108&plat=0&showtype=2&parentid=0&apiver=6&area_code=1&withsong=1')
|
||||
return this._requestBoardsObj.promise
|
||||
return this._requestBoardsObj!.promise
|
||||
},
|
||||
getData(url) {
|
||||
const requestDataObj = httpFetch(url)
|
||||
return requestDataObj.promise
|
||||
},
|
||||
getSinger(singers) {
|
||||
let arr = []
|
||||
let arr: string[] = []
|
||||
singers.forEach(singer => {
|
||||
arr.push(singer.author_name)
|
||||
})
|
||||
@@ -92,8 +93,8 @@ export default {
|
||||
filterData(rawList) {
|
||||
// console.log(rawList)
|
||||
return rawList.map(item => {
|
||||
const types = []
|
||||
const _types = {}
|
||||
const types: Array<SongType & { hash?: string }> = []
|
||||
const _types: Record<string, QualityInfo & { hash?: string }> = {}
|
||||
if (item.filesize !== 0) {
|
||||
let size = sizeFormate(item.filesize)
|
||||
types.push({ type: '128k', size, hash: item.hash })
|
||||
@@ -147,7 +148,7 @@ export default {
|
||||
|
||||
filterBoardsData(rawList) {
|
||||
// console.log(rawList)
|
||||
let list = []
|
||||
let list: Array<{ id: string; name: string; bangid: string }> = []
|
||||
for (const board of rawList) {
|
||||
if (board.isvol != 1) continue
|
||||
list.push({
|
||||
@@ -1,4 +1,4 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { decodeKrc } from '../../src/common/lyricUtils/kg.js'
|
||||
|
||||
export default {
|
||||
@@ -11,7 +11,7 @@ export default {
|
||||
intv += (intvArr.pop()) * unit
|
||||
unit *= 60
|
||||
}
|
||||
return parseInt(intv)
|
||||
return parseInt(intv as unknown as string)
|
||||
},
|
||||
// getLyric(songInfo, tryNum = 0) {
|
||||
// let requestObj = httpFetch(`http://m.kugou.com/app/i/krc.php?cmd=100&keyword=${encodeURIComponent(songInfo.name)}&hash=${songInfo.hash}&timelength=${songInfo._interval || this.getIntv(songInfo.interval)}&d=0.38664927426725626`, {
|
||||
@@ -38,12 +38,12 @@ export default {
|
||||
searchLyric(name, hash, time, tryNum = 0) {
|
||||
let requestObj = httpFetch(`http://lyrics.kugou.com/search?ver=1&man=yes&client=pc&keyword=${encodeURIComponent(name)}&hash=${hash}&timelength=${time}&lrctxt=1`, {
|
||||
headers: {
|
||||
'KG-RC': 1,
|
||||
'KG-RC': '1',
|
||||
'KG-THash': 'expand_search_manager.cpp:852736169:451',
|
||||
'User-Agent': 'KuGou2012-9020-ExpandSearchManager',
|
||||
},
|
||||
})
|
||||
requestObj.promise = requestObj.promise.then(({ body, statusCode }) => {
|
||||
requestObj.promise = (requestObj.promise as any).then(({ body, statusCode }) => {
|
||||
if (statusCode !== 200) {
|
||||
if (tryNum > 5) return Promise.reject(new Error('歌词获取失败'))
|
||||
let tryRequestObj = this.searchLyric(name, hash, time, ++tryNum)
|
||||
@@ -61,15 +61,15 @@ export default {
|
||||
getLyricDownload(id, accessKey, fmt, tryNum = 0) {
|
||||
let requestObj = httpFetch(`http://lyrics.kugou.com/download?ver=1&client=pc&id=${id}&accesskey=${accessKey}&fmt=${fmt}&charset=utf8`, {
|
||||
headers: {
|
||||
'KG-RC': 1,
|
||||
'KG-RC': '1',
|
||||
'KG-THash': 'expand_search_manager.cpp:852736169:451',
|
||||
'User-Agent': 'KuGou2012-9020-ExpandSearchManager',
|
||||
},
|
||||
})
|
||||
requestObj.promise = requestObj.promise.then(({ body, statusCode }) => {
|
||||
requestObj.promise = (requestObj.promise as any).then(({ body, statusCode }) => {
|
||||
if (statusCode !== 200) {
|
||||
if (tryNum > 5) return Promise.reject(new Error('歌词获取失败'))
|
||||
let tryRequestObj = this.getLyric(id, accessKey, fmt, ++tryNum)
|
||||
let tryRequestObj = (this.getLyric as any)(id, accessKey, fmt, ++tryNum)
|
||||
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
||||
return tryRequestObj.promise
|
||||
}
|
||||
@@ -97,12 +97,12 @@ export default {
|
||||
requestObj.promise = requestObj.promise.then(result => {
|
||||
if (!result) return Promise.reject(new Error('Get lyric failed'))
|
||||
|
||||
let requestObj2 = this.getLyricDownload(result.id, result.accessKey, result.fmt)
|
||||
let requestObj2 = this.getLyricDownload((result as any).id, (result as any).accessKey, (result as any).fmt)
|
||||
|
||||
requestObj.cancelHttp = requestObj2.cancelHttp.bind(requestObj2)
|
||||
|
||||
return requestObj2.promise
|
||||
})
|
||||
}) as any
|
||||
return requestObj
|
||||
},
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { decodeName, formatPlayTime, sizeFormate } from '../index.js'
|
||||
import { createHttpFetch } from './util.js'
|
||||
import { decodeName, formatPlayTime, sizeFormate } from '../index.ts'
|
||||
import { createHttpFetch } from './util.ts'
|
||||
import type { SongInfo, SongType, QualityInfo } from '../types.ts'
|
||||
|
||||
const createGetMusicInfosTask = (hashs) => {
|
||||
const createGetMusicInfosTask = (hashs: Array<{ hash: string }>): Array<Promise<any>> => {
|
||||
let data = {
|
||||
area_code: '1',
|
||||
show_privilege: 1,
|
||||
@@ -16,7 +17,7 @@ const createGetMusicInfosTask = (hashs) => {
|
||||
fields: 'album_info,author_name,audio_info,ori_audio_name,base,songname,classification',
|
||||
}
|
||||
let list = hashs
|
||||
let tasks = []
|
||||
let tasks: Array<{ data: Array<{ hash: string }> }> = []
|
||||
while (list.length) {
|
||||
tasks.push(Object.assign({ data: list.slice(0, 100) }, data))
|
||||
if (list.length < 100) break
|
||||
@@ -37,16 +38,16 @@ const createGetMusicInfosTask = (hashs) => {
|
||||
}).then(data => data.map(s => s[0])))
|
||||
}
|
||||
|
||||
export const filterMusicInfoList = (rawList) => {
|
||||
export const filterMusicInfoList = (rawList: any[]): SongInfo[] => {
|
||||
// console.log(rawList)
|
||||
let ids = new Set()
|
||||
let list = []
|
||||
let list: SongInfo[] = []
|
||||
rawList.forEach(item => {
|
||||
if (!item) return
|
||||
if (ids.has(item.audio_info.audio_id)) return
|
||||
ids.add(item.audio_info.audio_id)
|
||||
const types = []
|
||||
const _types = {}
|
||||
const types: Array<SongType & { hash?: string }> = []
|
||||
const _types: Record<string, QualityInfo & { hash?: string }> = {}
|
||||
if (item.audio_info.filesize !== '0') {
|
||||
let size = sizeFormate(parseInt(item.audio_info.filesize))
|
||||
types.push({ type: '128k', size, hash: item.audio_info.hash })
|
||||
@@ -99,18 +100,18 @@ export const filterMusicInfoList = (rawList) => {
|
||||
return list
|
||||
}
|
||||
|
||||
export const getMusicInfos = async(hashs) => {
|
||||
export const getMusicInfos = async(hashs: Array<{ hash: string }>): Promise<SongInfo[]> => {
|
||||
return filterMusicInfoList(await Promise.all(createGetMusicInfosTask(hashs)).then(data => data.flat()))
|
||||
}
|
||||
|
||||
export const getMusicInfoRaw = async(hash) => {
|
||||
export const getMusicInfoRaw = async(hash: string): Promise<any> => {
|
||||
return Promise.all(createGetMusicInfosTask([{ hash }])).then(data => data.flat()[0])
|
||||
}
|
||||
|
||||
export const getMusicInfo = async(hash) => {
|
||||
export const getMusicInfo = async(hash: string): Promise<SongInfo | undefined> => {
|
||||
return getMusicInfos([{ hash }]).then(data => data[0])
|
||||
}
|
||||
|
||||
export const getMusicInfosByList = (list) => {
|
||||
export const getMusicInfosByList = (list: any[]): Promise<SongInfo[]> => {
|
||||
return getMusicInfos(list.map(item => ({ hash: item.hash })))
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import { decodeName, formatPlayTime, sizeFormate } from '../index.js'
|
||||
import { formatSingerName } from '../utils.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { decodeName, formatPlayTime, sizeFormate } from '../index.ts'
|
||||
import { formatSingerName } from '../utils.ts'
|
||||
import type { SongType, QualityInfo } from '../types.ts'
|
||||
|
||||
|
||||
export default {
|
||||
@@ -13,8 +14,8 @@ export default {
|
||||
return searchRequest.promise.then(({ body }) => body)
|
||||
},
|
||||
filterData(rawData) {
|
||||
const types = []
|
||||
const _types = {}
|
||||
const types: Array<SongType & { hash?: string }> = []
|
||||
const _types: Record<string, QualityInfo & { hash?: string }> = {}
|
||||
if (rawData.FileSize !== 0) {
|
||||
let size = sizeFormate(rawData.FileSize)
|
||||
types.push({ type: '128k', size, hash: rawData.FileHash })
|
||||
@@ -67,7 +68,7 @@ export default {
|
||||
},
|
||||
handleResult(rawData) {
|
||||
let ids = new Set()
|
||||
const list = []
|
||||
const list: any[] = []
|
||||
rawData.forEach(item => {
|
||||
const key = item.Audioid + item.FileHash
|
||||
if (ids.has(key)) return
|
||||
@@ -1,4 +1,4 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
|
||||
export default {
|
||||
getPic(songInfo) {
|
||||
@@ -7,7 +7,7 @@ export default {
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'KG-RC': 1,
|
||||
'KG-RC': '1',
|
||||
'KG-THash': 'expand_search_manager.cpp:852736169:451',
|
||||
'User-Agent': 'KuGou2012-9020-ExpandSearchManager',
|
||||
},
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getMusicInfosByList } from './musicInfo.js'
|
||||
import { createHttpFetch } from './util.js'
|
||||
import { getMusicInfosByList } from './musicInfo.ts'
|
||||
import { createHttpFetch } from './util.ts'
|
||||
|
||||
export default {
|
||||
/**
|
||||
@@ -1,7 +1,8 @@
|
||||
import { httpFetch } from '../request.js'
|
||||
import { decodeName, formatPlayTime, sizeFormate, dateFormat, formatPlayCount } from '../index.js'
|
||||
import { toMD5 } from '../utils.js'
|
||||
import { signatureParams } from './util.js'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import { decodeName, formatPlayTime, sizeFormate, dateFormat, formatPlayCount } from '../index.ts'
|
||||
import { toMD5 } from '../utils.ts'
|
||||
import { signatureParams } from './util.ts'
|
||||
import type { HttpRequestObject, SongInfo, SongType, QualityInfo } from '../types.ts'
|
||||
|
||||
// 原版使用 @renderer/utils/musicSdk/kg/vendors/infSign.min(浏览器签名库),
|
||||
// 其 H5 签名算法为:{srcappid, clientver, clienttime, mid, uuid, dfid} + 业务参数,
|
||||
@@ -27,10 +28,10 @@ const handleSignature = (id, page, limit) => {
|
||||
}
|
||||
|
||||
export default {
|
||||
_requestObj_tags: null,
|
||||
_requestObj_listInfo: null,
|
||||
_requestObj_list: null,
|
||||
_requestObj_listRecommend: null,
|
||||
_requestObj_tags: null as HttpRequestObject | null,
|
||||
_requestObj_listInfo: null as HttpRequestObject | null,
|
||||
_requestObj_list: null as HttpRequestObject | null,
|
||||
_requestObj_listRecommend: null as HttpRequestObject | null,
|
||||
listDetailLimit: 10000,
|
||||
currentTagInfo: {
|
||||
id: undefined,
|
||||
@@ -119,7 +120,7 @@ export default {
|
||||
if (index < 0) return null
|
||||
return decodeName(afterStr.substring(0, index))
|
||||
},
|
||||
async getListDetailBySpecialId(id, page, tryNum = 0) {
|
||||
async getListDetailBySpecialId(id, page?, tryNum = 0) {
|
||||
if (tryNum > 2) throw new Error('try max num')
|
||||
|
||||
const { body } = await httpFetch(this.getSongListDetailUrl(id)).promise
|
||||
@@ -172,7 +173,7 @@ export default {
|
||||
// },
|
||||
// }
|
||||
},
|
||||
getInfoUrl(tagId) {
|
||||
getInfoUrl(tagId?) {
|
||||
return tagId
|
||||
? `http://www2.kugou.kugou.com/yueku/v9/special/getSpecial?is_smarty=1&cdn=cdn&t=5&c=${tagId}`
|
||||
: 'http://www2.kugou.kugou.com/yueku/v9/special/getSpecial?is_smarty=1&'
|
||||
@@ -186,7 +187,7 @@ export default {
|
||||
},
|
||||
|
||||
filterInfoHotTag(rawData) {
|
||||
const result = []
|
||||
const result: any[] = []
|
||||
if (rawData.status !== 1) return result
|
||||
for (const key of Object.keys(rawData.data)) {
|
||||
let tag = rawData.data[key]
|
||||
@@ -199,7 +200,7 @@ export default {
|
||||
return result
|
||||
},
|
||||
filterTagInfo(rawData) {
|
||||
const result = []
|
||||
const result: any[] = []
|
||||
for (const name of Object.keys(rawData)) {
|
||||
result.push({
|
||||
name,
|
||||
@@ -221,7 +222,7 @@ export default {
|
||||
this._requestObj_list = httpFetch(
|
||||
this.getSongListUrl(sortId, tagId, page),
|
||||
)
|
||||
return this._requestObj_list.promise.then(({ body }) => {
|
||||
return this._requestObj_list!.promise.then(({ body }) => {
|
||||
if (!body || body.status !== 1) return this.getSongList(sortId, tagId, page, ++tryNum)
|
||||
return this.filterList(body.special_db)
|
||||
})
|
||||
@@ -249,7 +250,7 @@ export default {
|
||||
},
|
||||
},
|
||||
)
|
||||
return this._requestObj_listRecommend.promise.then(({ body }) => {
|
||||
return this._requestObj_listRecommend!.promise.then(({ body }) => {
|
||||
if (body.status !== 1) return this.getSongListRecommend(++tryNum)
|
||||
return this.filterList(body.data.special_list)
|
||||
})
|
||||
@@ -308,7 +309,7 @@ export default {
|
||||
fields: 'album_info,author_name,audio_info,ori_audio_name,base,songname',
|
||||
}
|
||||
let list = hashs
|
||||
let tasks = []
|
||||
let tasks: any[] = []
|
||||
while (list.length) {
|
||||
tasks.push(Object.assign({ data: list.slice(0, 100) }, data))
|
||||
if (list.length < 100) break
|
||||
@@ -452,7 +453,7 @@ export default {
|
||||
async getUserListDetailByLink({ info }, link) {
|
||||
let listInfo = info['0']
|
||||
let total = listInfo.count
|
||||
let tasks = []
|
||||
let tasks: any[] = []
|
||||
let page = 0
|
||||
while (total) {
|
||||
const limit = total > 90 ? 90 : total
|
||||
@@ -484,7 +485,7 @@ export default {
|
||||
}
|
||||
},
|
||||
createGetListDetail2Task(id, total) {
|
||||
let tasks = []
|
||||
let tasks: any[] = []
|
||||
let page = 0
|
||||
while (total) {
|
||||
const limit = total > 300 ? 300 : total
|
||||
@@ -653,32 +654,33 @@ export default {
|
||||
},
|
||||
})
|
||||
const { headers: { location }, statusCode, body } = await requestObj_listDetailLink.promise
|
||||
const loc = location as string | undefined
|
||||
// console.log(body, location)
|
||||
if (statusCode > 400) return this.getUserListDetail(link, page, ++retryNum)
|
||||
if (location) {
|
||||
if (loc) {
|
||||
// console.log(location)
|
||||
if (location.includes('global_collection_id')) return this.getUserListDetail2(location.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1'))
|
||||
if (location.includes('gcid_')) {
|
||||
if (loc.includes('global_collection_id')) return this.getUserListDetail2(loc.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1'))
|
||||
if (loc.includes('gcid_')) {
|
||||
let gcid = link.match(/gcid_\w+/)?.[0]
|
||||
if (gcid) {
|
||||
const global_collection_id = await this.decodeGcid(gcid)
|
||||
if (global_collection_id) return this.getUserListDetail2(global_collection_id)
|
||||
}
|
||||
}
|
||||
if (location.includes('chain=')) return this.getUserListDetail3(location.replace(/^.*?chain=(\w+)(?:&.*$|#.*$|$)/, '$1'), page)
|
||||
if (location.includes('.html')) {
|
||||
if (location.includes('zlist.html')) {
|
||||
let link = location.replace(/^(.*)zlist\.html/, 'https://m3ws.kugou.com/zlist/list')
|
||||
if (loc.includes('chain=')) return this.getUserListDetail3(loc.replace(/^.*?chain=(\w+)(?:&.*$|#.*$|$)/, '$1'), page)
|
||||
if (loc.includes('.html')) {
|
||||
if (loc.includes('zlist.html')) {
|
||||
let link = loc.replace(/^(.*)zlist\.html/, 'https://m3ws.kugou.com/zlist/list')
|
||||
if (link.includes('pagesize')) {
|
||||
link = link.replace('pagesize=30', 'pagesize=' + this.listDetailLimit).replace('page=1', 'page=' + page)
|
||||
} else {
|
||||
link += `&pagesize=${this.listDetailLimit}&page=${page}`
|
||||
}
|
||||
return this.getUserListDetail(link, page, ++retryNum)
|
||||
} else return this.getUserListDetail3(location.replace(/.+\/(\w+).html(?:\?.*|&.*$|#.*$|$)/, '$1'), page)
|
||||
} else return this.getUserListDetail3(loc.replace(/.+\/(\w+).html(?:\?.*|&.*$|#.*$|$)/, '$1'), page)
|
||||
}
|
||||
// console.log('location', location)
|
||||
return this.getUserListDetail(location, page, ++retryNum)
|
||||
return this.getUserListDetail(loc, page, ++retryNum)
|
||||
}
|
||||
if (typeof body == 'string') {
|
||||
let global_collection_id = body.match(/"global_collection_id":"(\w+)"/)?.[1]
|
||||
@@ -713,8 +715,8 @@ export default {
|
||||
filterData(rawList) {
|
||||
// console.log(rawList)
|
||||
return rawList.map(item => {
|
||||
const types = []
|
||||
const _types = {}
|
||||
const types: Array<{ type: string; size: string; hash?: string }> = []
|
||||
const _types: Record<string, QualityInfo & { hash?: string }> = {}
|
||||
if (item.filesize !== 0) {
|
||||
let size = sizeFormate(item.filesize)
|
||||
types.push({ type: '128k', size, hash: item.hash })
|
||||
@@ -831,13 +833,13 @@ export default {
|
||||
filterData2(rawList) {
|
||||
// console.log(rawList)
|
||||
let ids = new Set()
|
||||
let list = []
|
||||
let list: SongInfo[] = []
|
||||
rawList.forEach(item => {
|
||||
if (!item) return
|
||||
if (ids.has(item.audio_info.audio_id)) return
|
||||
ids.add(item.audio_info.audio_id)
|
||||
const types = []
|
||||
const _types = {}
|
||||
const types: Array<SongType & { hash?: string }> = []
|
||||
const _types: Record<string, QualityInfo & { hash?: string }> = {}
|
||||
if (item.audio_info.filesize !== '0') {
|
||||
let size = sizeFormate(parseInt(item.audio_info.filesize))
|
||||
types.push({ type: '128k', size, hash: item.audio_info.hash })
|
||||
@@ -895,7 +897,7 @@ export default {
|
||||
if (this._requestObj_listInfo) this._requestObj_listInfo.cancelHttp()
|
||||
if (tryNum > 2) return Promise.reject(new Error('try max num'))
|
||||
this._requestObj_listInfo = httpFetch(this.getInfoUrl(tagId))
|
||||
return this._requestObj_listInfo.promise.then(({ body }) => {
|
||||
return this._requestObj_listInfo!.promise.then(({ body }) => {
|
||||
if (body.status !== 1) return this.getListInfo(tagId, ++tryNum)
|
||||
return {
|
||||
limit: body.data.params.pagesize,
|
||||
@@ -933,7 +935,7 @@ export default {
|
||||
if (this._requestObj_tags) this._requestObj_tags.cancelHttp()
|
||||
if (tryNum > 2) return Promise.reject(new Error('try max num'))
|
||||
this._requestObj_tags = httpFetch(this.getInfoUrl())
|
||||
return this._requestObj_tags.promise.then(({ body }) => {
|
||||
return this._requestObj_tags!.promise.then(({ body }) => {
|
||||
if (body.status !== 1) return this.getTags(++tryNum)
|
||||
return {
|
||||
hotTag: this.filterInfoHotTag(body.data.hotTag),
|
||||
@@ -1,7 +1,7 @@
|
||||
import { createHttpFetch } from './util.js'
|
||||
import { createHttpFetch } from './util.ts'
|
||||
|
||||
export default {
|
||||
requestObj: null,
|
||||
requestObj: null as any,
|
||||
cancelTipSearch() {
|
||||
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
||||
},
|
||||
@@ -1,5 +1,6 @@
|
||||
import { toMD5 } from '../utils.js'
|
||||
import { httpFetch } from '../request.js'
|
||||
import { toMD5 } from '../utils.ts'
|
||||
import { httpFetch } from '../request.ts'
|
||||
import type { HttpOptions } from '../types.ts'
|
||||
|
||||
// s.content[0].lyricContent.forEach(([str]) => {
|
||||
// console.log(str)
|
||||
@@ -10,7 +11,7 @@ import { httpFetch } from '../request.js'
|
||||
* @param {*} params
|
||||
* @param {*} apiver
|
||||
*/
|
||||
export const signatureParams = (params, platform = 'android', body = '') => {
|
||||
export const signatureParams = (params: string, platform = 'android', body = ''): string => {
|
||||
let keyparam = 'OIlwieks28dk2k092lksi2UIkp'
|
||||
if (platform === 'web') keyparam = 'NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt'
|
||||
let param_list = params.split('&')
|
||||
@@ -25,7 +26,7 @@ export const signatureParams = (params, platform = 'android', body = '') => {
|
||||
* @param {*} options
|
||||
* @param {*} retryNum
|
||||
*/
|
||||
export const createHttpFetch = async(url, options, retryNum = 0) => {
|
||||
export const createHttpFetch = async(url: string, options?: HttpOptions, retryNum = 0): Promise<any> => {
|
||||
if (retryNum > 2) throw new Error('try max num')
|
||||
let result
|
||||
try {
|
||||
Reference in new issue
Block a user