This commit is contained in:
lyswhut 2023-04-29 15:04:54 +08:00
parent ec1b3e5ec9
commit 4c18f8ab71
17 changed files with 1126 additions and 1048 deletions

View File

@ -48,12 +48,12 @@ export default {
const tipSearch = debounce(async() => { const tipSearch = debounce(async() => {
if (searchText.value === '' && prevTempSearchSource) { if (searchText.value === '' && prevTempSearchSource) {
tipList.value = [] tipList.value = []
music[prevTempSearchSource].tempSearch.cancelTempSearch() music[prevTempSearchSource].tipSearch.cancelTipSearch()
return return
} }
const { temp_source } = await getSearchSetting() const { temp_source } = await getSearchSetting()
prevTempSearchSource = temp_source prevTempSearchSource = temp_source
music[prevTempSearchSource].tempSearch.search(searchText.value).then(list => { music[prevTempSearchSource].tipSearch.search(searchText.value).then(list => {
tipList.value = list tipList.value = list
}).catch(() => {}) }).catch(() => {})
}, 50) }, 50)

View File

@ -9,10 +9,10 @@ export * from '@common/utils/tools'
* *
* @param {*} num * @param {*} num
*/ */
export const formatPlayCount = (num: number): { count: number, lang: string } => { export const formatPlayCount = (num: number): string => {
if (num > 100000000) return {count: parseInt((num / 10000000).toString()) / 10, lang: 'play_count_billion'} if (num > 100000000) return `${Math.trunc(num / 10000000) / 10}亿`
if (num > 10000) return {count: parseInt((num / 1000).toString()) / 10, lang: 'play_count_million'} if (num > 10000) return `${Math.trunc(num / 1000) / 10}`
return { count: num, lang: 'play_count_none' } return String(num)
} }

View File

@ -38,13 +38,13 @@ export default {
* @param {*} page * @param {*} page
*/ */
async getAlbumDetail(id, page = 1, limit = 200) { async getAlbumDetail(id, page = 1, limit = 200) {
const info = await this.getAlbumInfo(id)
const albumList = await createHttpFetch(`http://mobiles.kugou.com/api/v3/album/song?version=9108&albumid=${id}&plat=0&pagesize=${limit}&area_code=0&page=${page}&with_res_tag=0`) const albumList = await createHttpFetch(`http://mobiles.kugou.com/api/v3/album/song?version=9108&albumid=${id}&plat=0&pagesize=${limit}&area_code=0&page=${page}&with_res_tag=0`)
if (!albumList.info) return Promise.reject(new Error('Get album list failed.')) if (!albumList.info) return Promise.reject(new Error('Get album list failed.'))
let result = await getMusicInfosByList(albumList.info) let result = await getMusicInfosByList(albumList.info)
const info = await this.getAlbumInfo(id)
return { return {
list: result || [], list: result || [],
page, page,

View File

@ -6,10 +6,10 @@ import pic from './pic'
import lyric from './lyric' import lyric from './lyric'
import hotSearch from './hotSearch' import hotSearch from './hotSearch'
import comment from './comment' import comment from './comment'
import tipSearch from './tipSearch' // import tipSearch from './tipSearch'
const kg = { const kg = {
tipSearch, // tipSearch,
leaderboard, leaderboard,
songList, songList,
musicSearch, musicSearch,

View File

@ -1,5 +1,6 @@
import { httpFetch } from '../../request' import { httpFetch } from '../../request'
import { decodeName, formatPlayTime, sizeFormate } from '../../index' import { decodeName, formatPlayTime, sizeFormate } from '../../index'
import { formatSingerName } from '@renderer/utils/musicSdk/utils'
export default { export default {
limit: 30, limit: 30,
@ -10,79 +11,75 @@ export default {
const searchRequest = httpFetch(`https://songsearch.kugou.com/song_search_v2?keyword=${encodeURIComponent(str)}&page=${page}&pagesize=${limit}&userid=0&clientver=&platform=WebFilter&filter=2&iscorrection=1&privilege_filter=0`) const searchRequest = httpFetch(`https://songsearch.kugou.com/song_search_v2?keyword=${encodeURIComponent(str)}&page=${page}&pagesize=${limit}&userid=0&clientver=&platform=WebFilter&filter=2&iscorrection=1&privilege_filter=0`)
return searchRequest.promise.then(({ body }) => body) return searchRequest.promise.then(({ body }) => body)
}, },
filterList(raw) { filterData(rawData) {
let ids = new Set()
const list = []
raw.forEach(item => {
if (ids.has(item.Audioid) || !item.Audioid) return
ids.add(item.Audioid)
const types = [] const types = []
const _types = {} const _types = {}
if (item.FileSize !== 0) { if (rawData.FileSize !== 0) {
let size = sizeFormate(item.FileSize) let size = sizeFormate(rawData.FileSize)
types.push({ type: '128k', size, hash: item.FileHash }) types.push({ type: '128k', size, hash: rawData.FileHash })
_types['128k'] = { _types['128k'] = {
size, size,
hash: item.FileHash, hash: rawData.FileHash,
} }
} }
if (item.HQFileSize !== 0) { if (rawData.HQFileSize !== 0) {
let size = sizeFormate(item.HQFileSize) let size = sizeFormate(rawData.HQFileSize)
types.push({ type: '320k', size, hash: item.HQFileHash }) types.push({ type: '320k', size, hash: rawData.HQFileHash })
_types['320k'] = { _types['320k'] = {
size, size,
hash: item.HQFileHash, hash: rawData.HQFileHash,
} }
} }
if (item.SQFileSize !== 0) { if (rawData.SQFileSize !== 0) {
let size = sizeFormate(item.SQFileSize) let size = sizeFormate(rawData.SQFileSize)
types.push({ type: 'flac', size, hash: item.SQFileHash }) types.push({ type: 'flac', size, hash: rawData.SQFileHash })
_types.flac = { _types.flac = {
size, size,
hash: item.SQFileHash, hash: rawData.SQFileHash,
} }
} }
if (item.ResFileSize !== 0) { if (rawData.ResFileSize !== 0) {
let size = sizeFormate(item.ResFileSize) let size = sizeFormate(rawData.ResFileSize)
types.push({ type: 'flac24bit', size, hash: item.ResFileHash }) types.push({ type: 'flac24bit', size, hash: rawData.ResFileHash })
_types.flac24bit = { _types.flac24bit = {
size, size,
hash: item.ResFileHash, hash: rawData.ResFileHash,
} }
} }
list.push({ return {
singer: decodeName(item.SingerName), singer: decodeName(formatSingerName(rawData.Singers, 'name')),
name: decodeName(item.SongName), name: decodeName(rawData.SongName),
albumName: decodeName(item.AlbumName), albumName: decodeName(rawData.AlbumName),
albumId: item.AlbumID, albumId: rawData.AlbumID,
songmid: item.Audioid, songmid: rawData.Audioid,
source: 'kg', source: 'kg',
interval: formatPlayTime(item.Duration), interval: formatPlayTime(rawData.Duration),
_interval: item.Duration, _interval: rawData.Duration,
img: null, img: null,
lrc: null, lrc: null,
otherSource: null, otherSource: null,
hash: item.FileHash, hash: rawData.FileHash,
types, types,
_types, _types,
typeUrl: {}, typeUrl: {},
}) }
})
return list
}, },
handleResult(raw) { handleResult(rawData) {
const handleList = [] let ids = new Set()
const list = []
raw.forEach(item => { rawData.forEach(item => {
handleList.push(item) const key = item.Audioid + item.FileHash
if (item.Grp.length === 0) return if (ids.has(key)) return
for (const e in item.Grp) { ids.add(key)
handleList.push(e) list.push(this.filterData(item))
for (const childItem of item.Grp) {
const key = item.Audioid + item.FileHash
if (ids.has(key)) continue
ids.add(key)
list.push(this.filterData(childItem))
} }
}) })
return this.filterList(handleList) return list
}, },
search(str, page = 1, limit, retryNum = 0) { search(str, page = 1, limit, retryNum = 0) {
if (++retryNum > 3) return Promise.reject(new Error('try max num')) if (++retryNum > 3) return Promise.reject(new Error('try max num'))

View File

@ -1,9 +1,17 @@
import { httpFetch } from '../../request' import { httpFetch } from '../../request'
import { formatSingerName } from '../utils'
import { decodeName, formatPlayTime, sizeFormate, dateFormat, formatPlayCount } from '../../index' import { decodeName, formatPlayTime, sizeFormate, dateFormat, formatPlayCount } from '../../index'
import { signatureParams, createHttpFetch } from './util' import infSign from './vendors/infSign.min'
import { getMusicInfosByList } from './musicInfo' import { signatureParams } from './util'
import album from './album'
const handleSignature = (id, page, limit) => new Promise((resolve, reject) => {
infSign({ appid: 1058, type: 0, module: 'playlist', page, pagesize: limit, specialid: id }, null, {
useH5: !0,
isCDN: !0,
callback(i) {
resolve(i.signature)
},
})
})
export default { export default {
_requestObj_tags: null, _requestObj_tags: null,
@ -38,59 +46,75 @@ export default {
}, },
], ],
cache: new Map(), cache: new Map(),
CollectionIdListInfoCache: new Map(),
regExps: { regExps: {
listData: /global\.data = (\[.+\]);/, listData: /global\.data = (\[.+\]);/,
listInfo: /global = {[\s\S]+?name: "(.+)"[\s\S]+?pic: "(.+)"[\s\S]+?};/, listInfo: /global = {[\s\S]+?name: "(.+)"[\s\S]+?pic: "(.+)"[\s\S]+?};/,
// https://www.kugou.com/yy/special/single/1067062.html // https://www.kugou.com/yy/special/single/1067062.html
listDetailLink: /^.+\/(\d+)\.html(?:\?.*|&.*$|#.*$|$)/, listDetailLink: /^.+\/(\d+)\.html(?:\?.*|&.*$|#.*$|$)/,
}, },
// async getGlobalSpecialId(specialId) {
/** // return httpFetch(`http://mobilecdnbj.kugou.com/api/v5/special/info?specialid=${specialId}`, {
* 获取歌曲列表内的音乐 // headers: {
* @param {*} id // 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; HLK-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Mobile Safari/537.36 EdgA/104.0.1293.70',
* @param {*} page // },
*/ // }).promise.then(({ body }) => {
async getListDetail(id, page) { // // console.log(body)
id = id.toString() // if (!body.data.global_specialid) Promise.reject(new Error('Failed to get global collection id.'))
// return body.data.global_specialid
if (id.includes('special/single/')) id = id.replace(this.regExps.listDetailLink, '$1') // })
// fix https://www.kugou.com/songlist/xxx/?uid=xxx&chl=qq_client&cover=http%3A%2F%2Fimge.kugou.com%xxx.jpg&iszlist=1 // },
if (/https?:/.test(id)) { // async getListInfoBySpecialId(special_id, retry = 0) {
if (id.includes('#')) id = id.replace(/#.*$/, '') // if (++retry > 2) throw new Error('failed')
if (id.includes('global_collection_id')) return this.getUserListDetailByCollectionId(id.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1'), page) // return httpFetch(`https://m.kugou.com/plist/list/${special_id}/?json=true`, {
if (id.includes('chain=')) return this.getUserListDetail3(id.replace(/^.*?chain=(\w+)(?:&.*$|#.*$|$)/, '$1'), page) // headers: {
if (id.includes('.html')) { // 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; HLK-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Mobile Safari/537.36 EdgA/104.0.1293.70',
if (id.includes('zlist.html')) { // },
id = id.replace(/^(.*)zlist\.html/, 'https://m3ws.kugou.com/zlist/list') // follow_max: 2,
if (id.includes('pagesize')) { // }).promise.then(({ body }) => {
id = id.replace('pagesize=30', 'pagesize=' + this.listDetailLimit).replace('page=1', 'page=' + page) // // console.log(body)
} else { // if (!body.info.list) return this.getListInfoBySpecialId(special_id, retry)
id += `&pagesize=${this.listDetailLimit}&page=${page}` // let listinfo = body.info.list
} // return {
} else if (!id.includes('song.html')) return this.getUserListDetail3(id.replace(/.+\/(\w+).html(?:\?.*|&.*$|#.*$|$)/, '$1'), page) // listInfo: {
} // name: listinfo.specialname,
return this.getUserListDetail(id.replace(/^.*?http/, 'http'), page) // image: listinfo.imgurl.replace('{size}', '150'),
} // intro: listinfo.intro,
if (/^\d+$/.test(id)) return this.getUserListDetailByCode(id, page) // author: listinfo.nickname,
if (id.startsWith('gid_')) return this.getUserListDetailByCollectionId(id.replace('gid_', ''), page) // playcount: listinfo.playcount,
if (id.startsWith('id_')) return this.getUserListDetailBySpecialId(id.replace('id_', ''), page) // total: listinfo.songcount,
// },
return new Error('Failed.') // globalSpecialId: listinfo.global_specialid,
// }
// })
// },
// async getSongListDetailByGlobalSpecialId(id, page, limit = 100, retry = 0) {
// if (++retry > 2) throw new Error('failed')
// console.log(id)
// const params = `specialid=0&need_sort=1&module=CloudMusic&clientver=11409&pagesize=${limit}&global_collection_id=${id}&userid=0&page=${page}&type=1&area_code=1&appid=1005`
// return httpFetch(`http://pubsongscdn.tx.kugou.com/v2/get_other_list_file?${params}&signature=${signatureParams(params)}`).promise.then(({ body }) => {
// // console.log(body)
// if (body.data?.info == null) return this.getSongListDetailByGlobalSpecialId(id, page, limit, retry)
// return body.data.info
// })
// },
parseHtmlDesc(html) {
const prefix = '<div class="pc_specail_text pc_singer_tab_content" id="specailIntroduceWrap">'
let index = html.indexOf(prefix)
if (index < 0) return null
const afterStr = html.substring(index + prefix.length)
index = afterStr.indexOf('</div>')
if (index < 0) return null
return decodeName(afterStr.substring(0, index))
}, },
async getListDetailBySpecialId(id, page, tryNum = 0) {
/**
* 获取SpecialId歌单
* @param {*} id
*/
async getUserListDetailBySpecialId(id, page, tryNum = 0) {
if (tryNum > 2) throw new Error('try max num') if (tryNum > 2) throw new Error('try max num')
const { body } = await httpFetch(this.getSongListDetailUrl(id)).promise const { body } = await httpFetch(this.getSongListDetailUrl(id)).promise
let listData = body.match(this.regExps.listData) let listData = body.match(this.regExps.listData)
let listInfo = body.match(this.regExps.listInfo) let listInfo = body.match(this.regExps.listInfo)
if (!listData) return this.getListDetailBySpecialId(id, page, ++tryNum) if (!listData) return this.getListDetailBySpecialId(id, page, ++tryNum)
let list = await getMusicInfosByList(JSON.parse(listData[1])) let list = await this.getMusicInfos(JSON.parse(listData[1]))
// listData = this.filterData(JSON.parse(listData[1]))
let name let name
let pic let pic
if (listInfo) { if (listInfo) {
@ -114,48 +138,36 @@ export default {
// play_count: formatPlayCount(body.result.listen_num), // play_count: formatPlayCount(body.result.listen_num),
}, },
} }
},
parseHtmlDesc(html) {
const prefix = '<div class="pc_specail_text pc_singer_tab_content" id="specailIntroduceWrap">'
let index = html.indexOf(prefix)
if (index < 0) return null
const afterStr = html.substring(index + prefix.length)
index = afterStr.indexOf('</div>')
if (index < 0) return null
return decodeName(afterStr.substring(0, index))
},
/** // const globalSpecialId = await this.getGlobalSpecialId(id)
* 使用SpecialId获取CollectionId // const limit = 100
* @param {*} specialId // const listData = await this.getSongListDetailByGlobalSpecialId(globalSpecialId, page, limit)
*/ // if (!Array.isArray(listData))
async getCollectionIdBySpecialId(specialId) { // return this.getUserListDetail2(globalSpecialId)
return httpFetch(`http://mobilecdnbj.kugou.com/api/v5/special/info?specialid=${specialId}`, { // return {
headers: { // list: this.filterDatav9(listData),
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; HLK-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Mobile Safari/537.36 EdgA/104.0.1293.70', // page,
}, // limit,
}).promise.then(({ body }) => { // total: listInfo.total,
// console.log('getCollectionIdBySpecialId', body) // source: 'kg',
if (!body.data.global_specialid) return Promise.reject(new Error('Failed to get global collection id.')) // info: {
return body.data.global_specialid // name: listInfo.name,
}) // img: listInfo.image,
}, // desc: listInfo.intro,
// author: listInfo.author,
/** // play_count: formatPlayCount(listInfo.playcount),
* 获取歌单URL // },
* @param {*} sortId // }
* @param {*} tagId
* @param {*} page
*/
getSongListUrl(sortId, tagId, page) {
if (tagId == null) tagId = ''
return `http://www2.kugou.kugou.com/yueku/v9/special/getSpecial?is_ajax=1&cdn=cdn&t=${sortId}&c=${tagId}&p=${page}`
}, },
getInfoUrl(tagId) { getInfoUrl(tagId) {
return 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&cdn=cdn&t=5&c=${tagId}`
: 'http://www2.kugou.kugou.com/yueku/v9/special/getSpecial?is_smarty=1&' : 'http://www2.kugou.kugou.com/yueku/v9/special/getSpecial?is_smarty=1&'
}, },
getSongListUrl(sortId, tagId, page) {
if (tagId == null) tagId = ''
return `http://www2.kugou.kugou.com/yueku/v9/special/getSpecial?is_ajax=1&cdn=cdn&t=${sortId}&c=${tagId}&p=${page}`
},
getSongListDetailUrl(id) { getSongListDetailUrl(id) {
return `http://www2.kugou.kugou.com/yueku/v9/special/single/${id}-5-9999.html` return `http://www2.kugou.kugou.com/yueku/v9/special/single/${id}-5-9999.html`
}, },
@ -173,7 +185,6 @@ export default {
} }
return result return result
}, },
filterTagInfo(rawData) { filterTagInfo(rawData) {
const result = [] const result = []
for (const name of Object.keys(rawData)) { for (const name of Object.keys(rawData)) {
@ -190,20 +201,6 @@ export default {
} }
return result return result
}, },
filterSongList(rawData) {
return rawData.map(item => ({
play_count: item.total_play_count || formatPlayCount(item.play_count),
id: 'id_' + item.specialid,
author: item.nickname,
name: item.specialname,
time: dateFormat(item.publish_time || item.publishtime, 'Y-M-D'),
img: item.img || item.imgurl,
total: item.songcount,
grade: item.grade,
desc: item.intro,
source: 'kg',
}))
},
getSongList(sortId, tagId, page, tryNum = 0) { getSongList(sortId, tagId, page, tryNum = 0) {
if (this._requestObj_list) this._requestObj_list.cancelHttp() if (this._requestObj_list) this._requestObj_list.cancelHttp()
@ -213,7 +210,7 @@ export default {
) )
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) if (!body || body.status !== 1) return this.getSongList(sortId, tagId, page, ++tryNum)
return this.filterSongList(body.special_db) return this.filterList(body.special_db)
}) })
}, },
getSongListRecommend(tryNum = 0) { getSongListRecommend(tryNum = 0) {
@ -241,185 +238,88 @@ export default {
) )
return this._requestObj_listRecommend.promise.then(({ body }) => { return this._requestObj_listRecommend.promise.then(({ body }) => {
if (body.status !== 1) return this.getSongListRecommend(++tryNum) if (body.status !== 1) return this.getSongListRecommend(++tryNum)
return this.filterSongList(body.data.special_list) return this.filterList(body.data.special_list)
}) })
}, },
filterList(rawData) {
/** return rawData.map(item => ({
* 通过CollectionId获取歌单详情 play_count: item.total_play_count || formatPlayCount(item.play_count),
* @param {*} id id: 'id_' + item.specialid,
*/ author: item.nickname,
async getUserListInfoByCollectionId(id) { name: item.specialname,
if (!id || id.length > 1000) return Promise.reject(new Error('get list error')) time: dateFormat(item.publish_time || item.publishtime, 'Y-M-D'),
if (this.CollectionIdListInfoCache.has(id)) return this.CollectionIdListInfoCache.get(id) img: item.img || item.imgurl,
total: item.songcount,
const params = `appid=1058&specialid=0&global_specialid=${id}&format=jsonp&srcappid=2919&clientver=20000&clienttime=1586163242519&mid=1586163242519&uuid=1586163242519&dfid=-` grade: item.grade,
return createHttpFetch(`https://mobiles.kugou.com/api/v5/special/info_v2?${params}&signature=${signatureParams(params, 5)}`, { desc: item.intro,
headers: {
mid: '1586163242519',
Referer: 'https://m3ws.kugou.com/share/index.php',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
dfid: '-',
clienttime: '1586163242519',
},
}).then(body => {
let info = {
type: body.type,
userName: body.nickname,
userAvatar: body.user_avatar,
imageUrl: body.imgurl,
desc: body.intro,
name: body.specialname,
globalSpecialid: body.global_specialid,
total: body.songcount,
playCount: body.playcount,
}
this.CollectionIdListInfoCache.set(id, info)
return info
})
},
/**
* 通过SpecialId获取歌单
* @param {*} id
*/
// async getUserListDetailBySpecialId(id, page = 1, limit = 300) {
// if (!id || id.length > 1000) return Promise.reject(new Error('get list error.'))
// const listInfo = await this.getListInfoBySpecialId(id)
// const params = `specialid=${id}&need_sort=1&module=CloudMusic&clientver=11589&pagesize=${limit}&userid=0&page=${page}&type=0&area_code=1&appid=1005`
// return createHttpFetch(`http://pubsongs.kugou.com/v2/get_other_list_file?${params}&signature=${signatureParams(params, 2)}`, {
// headers: {
// 'User-Agent': 'Android10-AndroidPhone-11589-201-0-playlist-wifi',
// },
// }).then(body => {
// if (!body.info) return Promise.reject(new Error('Get list failed.'))
// const songList = this.filterListByCollectionId(body.info)
// return {
// list: songList || [],
// page,
// limit,
// total: body.count,
// source: 'kg',
// info: {
// name: listInfo.name,
// img: listInfo.image,
// desc: listInfo.desc,
// // author: listInfo.userName,
// // play_count: formatPlayCount(listInfo.playCount),
// },
// }
// })
// },
/**
* 通过CollectionId获取歌单
* @param {*} id
*/
async getUserListDetailByCollectionId(id, page = 1, limit = 300) {
if (!id || id.length > 1000) return Promise.reject(new Error('ID error.'))
const listInfo = await this.getUserListInfoByCollectionId(id)
const params = `need_sort=1&module=CloudMusic&clientver=11589&pagesize=${limit}&global_collection_id=${id}&userid=0&page=${page}&type=0&area_code=1&appid=1005`
return createHttpFetch(`http://pubsongs.kugou.com/v2/get_other_list_file?${params}&signature=${signatureParams(params, 2)}`, {
headers: {
'User-Agent': 'Android10-AndroidPhone-11589-201-0-playlist-wifi',
},
}).then(body => {
if (!body.info) return Promise.reject(new Error('Get list failed.'))
const songList = this.filterListByCollectionId(body.info)
return {
list: songList || [],
page,
limit,
total: listInfo.total,
source: 'kg', source: 'kg',
info: { }))
name: listInfo.name,
img: listInfo.imageUrl && listInfo.imageUrl.replace('{size}', 240),
desc: listInfo.desc,
author: listInfo.userName,
play_count: formatPlayCount(listInfo.playCount),
}, },
}
})
},
/**
* 过滤GlobalSpecialId歌单数据
* @param {*} rawData
*/
filterListByCollectionId(rawData) {
let ids = new Set()
let list = []
rawData.forEach(item => {
if (!item) return
if (ids.has(item.hash)) return
ids.add(item.hash)
const types = []
const _types = {}
item.relate_goods.forEach(data => { async createHttp(url, options, retryNum = 0) {
let size = sizeFormate(data.size) if (retryNum > 2) throw new Error('try max num')
switch (data.level) { let result
case 2: try {
types.push({ type: '128k', size, hash: data.hash }) result = await httpFetch(url, options).promise
_types['128k'] = { } catch (err) {
size, console.log(err)
hash: data.hash, return this.createHttp(url, options, ++retryNum)
} }
break // console.log(result.statusCode, result.body)
case 4: if (result.statusCode !== 200 ||
types.push({ type: '320k', size, hash: data.hash }) (
_types['320k'] = { (result.body.error_code !== undefined
size, ? result.body.error_code
hash: data.hash, : result.body.errcode !== undefined
} ? result.body.errcode
break : result.body.err_code
case 5: ) !== 0)
types.push({ type: 'flac', size, hash: data.hash }) ) return this.createHttp(url, options, ++retryNum)
_types.flac = { if (result.body.data) return result.body.data
size, if (Array.isArray(result.body.info)) return result.body
hash: data.hash, return result.body.info
}
break
case 6:
types.push({ type: 'flac24bit', size, hash: data.hash })
_types.flac24bit = {
size,
hash: data.hash,
}
break
}
})
list.push({
singer: formatSingerName(item.singerinfo, 'name') || decodeName(item.name).split(' - ')[0].replace(/&/g, '、'),
name: decodeName(item.name).split(' - ')[1],
albumName: decodeName(item.albuminfo.name),
albumId: item.albuminfo.id,
songmid: item.audio_id,
source: 'kg',
interval: formatPlayTime(parseInt(item.timelen) / 1000),
img: null,
lrc: null,
hash: item.hash,
otherSource: null,
types,
_types,
typeUrl: {},
})
})
return list
}, },
/**
* 通过酷狗码获取歌单 createTask(hashs) {
* @param {*} id let data = {
* @param {*} page appid: 1001,
*/ clienttime: 639437935,
async getUserListDetailByCode(id, page = 1) { clientver: 9020,
// type 1单曲2歌单3电台4酷狗码5别人的播放队列 fields:
const codeData = await createHttpFetch('http://t.kugou.com/command/', { 'album_info,author_name,audio_info,ori_audio_name',
is_publish: '1',
key: '0475af1457cd3363c7b45b871e94428a',
mid: '21511157a05844bd085308bc76ef3342',
show_privilege: 1,
}
let list = hashs
let tasks = []
while (list.length) {
tasks.push(Object.assign({ data: list.slice(0, 100) }, data))
if (list.length < 100) break
list = list.slice(100)
}
let url = 'http://kmr.service.kugou.com/v2/album_audio/audio'
return tasks.map(task => this.createHttp(url, {
method: 'POST',
body: task,
headers: {
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',
},
}).then(data => data.map(s => s[0])))
},
async getMusicInfos(list) {
return this.filterData2(
await Promise.all(
this.createTask(
this.deDuplication(list)
.map(item => ({ hash: item.hash })),
))
.then(([...datas]) => datas.flat()))
},
async getUserListDetailByCode(id) {
const songInfo = await this.createHttp('http://t.kugou.com/command/', {
method: 'POST', method: 'POST',
headers: { headers: {
'KG-RC': 1, 'KG-RC': 1,
@ -428,58 +328,59 @@ export default {
}, },
body: { appid: 1001, clientver: 9020, mid: '21511157a05844bd085308bc76ef3343', clienttime: 640612895, key: '36164c4015e704673c588ee202b9ecb8', data: id }, body: { appid: 1001, clientver: 9020, mid: '21511157a05844bd085308bc76ef3343', clienttime: 640612895, key: '36164c4015e704673c588ee202b9ecb8', data: id },
}) })
if (!codeData) return Promise.reject(new Error('Get list failed.')) // console.log(songInfo)
const codeInfo = codeData.info // type 1单曲2歌单3电台4酷狗码5别人的播放队列
let songList
switch (codeInfo.type) { let info = songInfo.info
switch (info.type) {
case 2: case 2:
if (!codeInfo.global_collection_id) return this.getUserListDetailBySpecialId(codeInfo.id, page) if (!info.global_collection_id) return this.getListDetailBySpecialId(info.id)
break break
case 3:
return album.getAlbumDetail(codeInfo.id, page)
}
if (codeInfo.global_collection_id) return this.getUserListDetailByCollectionId(codeInfo.global_collection_id, page)
if (codeInfo.userid != null) { default:
const songList = await createHttpFetch('http://www2.kugou.kugou.com/apps/kucodeAndShare/app/', { break
}
if (info.global_collection_id) return this.getUserListDetail2(info.global_collection_id)
if (info.userid != null) {
songList = await this.createHttp('http://www2.kugou.kugou.com/apps/kucodeAndShare/app/', {
method: 'POST', method: 'POST',
headers: { headers: {
'KG-RC': 1, 'KG-RC': 1,
'KG-THash': 'network_super_call.cpp:3676261689:379', 'KG-THash': 'network_super_call.cpp:3676261689:379',
'User-Agent': '', 'User-Agent': '',
}, },
body: { appid: 1001, clientver: 9020, mid: '21511157a05844bd085308bc76ef3343', clienttime: 640612895, key: '36164c4015e704673c588ee202b9ecb8', data: { id: codeInfo.id, type: 3, userid: codeInfo.userid, collect_type: 0, page: 1, pagesize: codeInfo.count } }, body: { appid: 1001, clientver: 9020, mid: '21511157a05844bd085308bc76ef3343', clienttime: 640612895, key: '36164c4015e704673c588ee202b9ecb8', data: { id: info.id, type: 3, userid: info.userid, collect_type: 0, page: 1, pagesize: info.count } },
}) })
// console.log(songList) // console.log(songList)
let list = await getMusicInfosByList(songList || codeInfo.list) }
let list = await this.getMusicInfos(songList || songInfo.list)
return { return {
list, list,
page: 1, page: 1,
limit: codeInfo.count, limit: info.count,
total: list.length, total: list.length,
source: 'kg', source: 'kg',
info: { info: {
name: codeInfo.name, name: info.name,
img: (codeInfo.img_size && codeInfo.img_size.replace('{size}', 240)) || codeInfo.img, img: (info.img_size && info.img_size.replace('{size}', 240)) || info.img,
// desc: body.result.info.list_desc, // desc: body.result.info.list_desc,
author: codeInfo.username, author: info.username,
// play_count: formatPlayCount(info.count), // play_count: formatPlayCount(info.count),
}, },
} }
}
}, },
async getUserListDetail3(chain, page) { async getUserListDetail3(chain, page) {
const songInfo = await createHttpFetch(`http://m.kugou.com/schain/transfer?pagesize=${this.listDetailLimit}&chain=${chain}&su=1&page=${page}&n=0.7928855356604456`, { const songInfo = await this.createHttp(`http://m.kugou.com/schain/transfer?pagesize=${this.listDetailLimit}&chain=${chain}&su=1&page=${page}&n=0.7928855356604456`, {
headers: { headers: {
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1', 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',
}, },
}) })
if (!songInfo.list) { if (!songInfo.list) {
if (songInfo.global_collection_id) return this.getUserListDetailByCollectionId(songInfo.global_collection_id, page) if (songInfo.global_collection_id) return this.getUserListDetail2(songInfo.global_collection_id)
else return this.getUserListDetail4(songInfo, chain, page).catch(() => this.getUserListDetail5(chain)) else return this.getUserListDetail4(songInfo, chain, page).catch(() => this.getUserListDetail5(chain))
} }
let list = await getMusicInfosByList(songInfo.list) let list = await this.getMusicInfos(songInfo.list)
// console.log(info, songInfo) // console.log(info, songInfo)
return { return {
list, list,
@ -497,6 +398,15 @@ export default {
} }
}, },
deDuplication(datas) {
let ids = new Set()
return datas.filter(({ hash }) => {
if (ids.has(hash)) return false
ids.add(hash)
return true
})
},
async getUserListDetailByLink({ info }, link) { async getUserListDetailByLink({ info }, link) {
let listInfo = info['0'] let listInfo = info['0']
let total = listInfo.count let total = listInfo.count
@ -506,7 +416,7 @@ export default {
const limit = total > 90 ? 90 : total const limit = total > 90 ? 90 : total
total -= limit total -= limit
page += 1 page += 1
tasks.push(createHttpFetch(link.replace(/pagesize=\d+/, 'pagesize=' + limit).replace(/page=\d+/, 'page=' + page), { tasks.push(this.createHttp(link.replace(/pagesize=\d+/, 'pagesize=' + limit).replace(/page=\d+/, 'page=' + page), {
headers: { headers: {
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1', 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',
Referer: link, Referer: link,
@ -514,7 +424,7 @@ export default {
}).then(data => data.list.info)) }).then(data => data.list.info))
} }
let result = await Promise.all(tasks).then(([...datas]) => datas.flat()) let result = await Promise.all(tasks).then(([...datas]) => datas.flat())
result = await getMusicInfosByList(result) result = await this.getMusicInfos(result)
// console.log(result) // console.log(result)
return { return {
list: result, list: result,
@ -539,7 +449,7 @@ export default {
total -= limit total -= limit
page += 1 page += 1
const params = 'appid=1058&global_specialid=' + id + '&specialid=0&plat=0&version=8000&page=' + page + '&pagesize=' + limit + '&srcappid=2919&clientver=20000&clienttime=1586163263991&mid=1586163263991&uuid=1586163263991&dfid=-' const params = 'appid=1058&global_specialid=' + id + '&specialid=0&plat=0&version=8000&page=' + page + '&pagesize=' + limit + '&srcappid=2919&clientver=20000&clienttime=1586163263991&mid=1586163263991&uuid=1586163263991&dfid=-'
tasks.push(createHttpFetch(`https://mobiles.kugou.com/api/v5/special/song_v2?${params}&signature=${signatureParams(params, 5)}`, { tasks.push(this.createHttp(`https://mobiles.kugou.com/api/v5/special/song_v2?${params}&signature=${signatureParams(params, 5)}`, {
headers: { headers: {
mid: '1586163263991', mid: '1586163263991',
Referer: 'https://m3ws.kugou.com/share/index.php', Referer: 'https://m3ws.kugou.com/share/index.php',
@ -555,7 +465,7 @@ export default {
let id = global_collection_id let id = global_collection_id
if (id.length > 1000) throw new Error('get list error') if (id.length > 1000) throw new Error('get list error')
const params = 'appid=1058&specialid=0&global_specialid=' + id + '&format=jsonp&srcappid=2919&clientver=20000&clienttime=1586163242519&mid=1586163242519&uuid=1586163242519&dfid=-' const params = 'appid=1058&specialid=0&global_specialid=' + id + '&format=jsonp&srcappid=2919&clientver=20000&clienttime=1586163242519&mid=1586163242519&uuid=1586163242519&dfid=-'
let info = await createHttpFetch(`https://mobiles.kugou.com/api/v5/special/info_v2?${params}&signature=${signatureParams(params, 5)}`, { let info = await this.createHttp(`https://mobiles.kugou.com/api/v5/special/info_v2?${params}&signature=${signatureParams(params, 5)}`, {
headers: { headers: {
mid: '1586163242519', mid: '1586163242519',
Referer: 'https://m3ws.kugou.com/share/index.php', Referer: 'https://m3ws.kugou.com/share/index.php',
@ -565,7 +475,7 @@ export default {
}, },
}) })
const songInfo = await this.createGetListDetail2Task(id, info.songcount) const songInfo = await this.createGetListDetail2Task(id, info.songcount)
let list = await getMusicInfosByList(songInfo) let list = await this.getMusicInfos(songInfo)
// console.log(info, songInfo, list) // console.log(info, songInfo, list)
return { return {
list, list,
@ -590,7 +500,6 @@ export default {
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1', 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1',
}, },
}).promise }).promise
// console.log(body)
let result = body.match(/var\sphpParam\s=\s({.+?});/) let result = body.match(/var\sphpParam\s=\s({.+?});/)
if (result) result = JSON.parse(result[1]) if (result) result = JSON.parse(result[1])
this.cache.set(chain, result) this.cache.set(chain, result)
@ -608,7 +517,7 @@ export default {
let result = body.match(/var\sdataFromSmarty\s=\s(\[.+?\])/) let result = body.match(/var\sdataFromSmarty\s=\s(\[.+?\])/)
if (result) result = JSON.parse(result[1]) if (result) result = JSON.parse(result[1])
this.cache.set(chain, result) this.cache.set(chain, result)
result = await getMusicInfosByList(result) result = await this.getMusicInfos(result)
// console.log(info, songInfo) // console.log(info, songInfo)
return result return result
}, },
@ -617,7 +526,7 @@ export default {
const limit = 100 const limit = 100
const [listInfo, list] = await Promise.all([ const [listInfo, list] = await Promise.all([
this.getListInfoByChain(chain), this.getListInfoByChain(chain),
this.getUserListDetailBySpecialId(songInfo.id, page, limit), this.getUserListDetailById(songInfo.id, page, limit),
]) ])
return { return {
list: list || [], list: list || [],
@ -656,29 +565,50 @@ export default {
} }
}, },
async getUserListDetailById(id, page, limit) {
const signature = await handleSignature(id, page, limit)
let info = await this.createHttp(`https://pubsongscdn.kugou.com/v2/get_other_list_file?srcappid=2919&clientver=20000&appid=1058&type=0&module=playlist&page=${page}&pagesize=${limit}&specialid=${id}&signature=${signature}`, {
headers: {
Referer: 'https://m3ws.kugou.com/share/index.php',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
dfid: '-',
},
})
// console.log(info)
let result = await this.getMusicInfos(info.info)
// console.log(info, songInfo)
return result
},
async getUserListDetail(link, page, retryNum = 0) { async getUserListDetail(link, page, retryNum = 0) {
if (retryNum > 3) return Promise.reject(new Error('link try max num')) if (retryNum > 3) return Promise.reject(new Error('link try max num'))
if (link.includes('#')) link = link.replace(/#.*$/, '')
if (link.includes('global_collection_id')) return this.getUserListDetail2(link.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1'))
if (link.includes('chain=')) return this.getUserListDetail3(link.replace(/^.*?chain=(\w+)(?:&.*$|#.*$|$)/, '$1'), page)
if (link.includes('.html')) {
if (link.includes('zlist.html')) {
link = link.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}`
}
} else if (!link.includes('song.html')) return this.getUserListDetail3(link.replace(/.+\/(\w+).html(?:\?.*|&.*$|#.*$|$)/, '$1'), page)
}
const requestLink = httpFetch(link, { const requestObj_listDetailLink = httpFetch(link, {
headers: { headers: {
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1', 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',
Referer: link, Referer: link,
}, },
follow_max: 2,
}) })
const { headers: { location }, statusCode, body } = await requestLink.promise const { headers: { location }, statusCode, body } = await requestObj_listDetailLink.promise
// console.log(body, location, statusCode) // console.log(body, location)
if (statusCode > 400) return this.getUserListDetail(link, page, ++retryNum) if (statusCode > 400) return this.getUserListDetail(link, page, ++retryNum)
if (typeof body == 'string') {
if (body.includes('"global_collection_id":')) return this.getUserListDetailByCollectionId(body.replace(/^[\s\S]+?"global_collection_id":"(\w+)"[\s\S]+?$/, '$1'), page)
if (body.includes('"albumid":')) return album.getAlbumDetail(body.replace(/^[\s\S]+?"albumid":(\w+)[\s\S]+?$/, '$1'), page)
if (body.includes('"album_id":') && link.includes('album/info')) return album.getAlbumDetail(body.replace(/^[\s\S]+?"album_id":(\w+)[\s\S]+?$/, '$1'), page)
if (body.includes('list_id = "') && link.includes('album/info')) return album.getAlbumDetail(body.replace(/^[\s\S]+?list_id = "(\w+)"[\s\S]+?$/, '$1'), page)
}
if (location) { if (location) {
// 概念版分享链接 https://t1.kugou.com/xxx // console.log(location)
if (location.includes('global_specialid')) return this.getUserListDetailByCollectionId(location.replace(/^.*?global_specialid=(\w+)(?:&.*$|#.*$|$)/, '$1'), page) if (location.includes('global_collection_id')) return this.getUserListDetail2(location.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1'))
if (location.includes('global_collection_id')) return this.getUserListDetailByCollectionId(location.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1'), page)
if (location.includes('chain=')) return this.getUserListDetail3(location.replace(/^.*?chain=(\w+)(?:&.*$|#.*$|$)/, '$1'), page) if (location.includes('chain=')) return this.getUserListDetail3(location.replace(/^.*?chain=(\w+)(?:&.*$|#.*$|$)/, '$1'), page)
if (location.includes('.html')) { if (location.includes('.html')) {
if (location.includes('zlist.html')) { if (location.includes('zlist.html')) {
@ -691,12 +621,210 @@ export default {
return this.getUserListDetail(link, page, ++retryNum) return this.getUserListDetail(link, page, ++retryNum)
} else return this.getUserListDetail3(location.replace(/.+\/(\w+).html(?:\?.*|&.*$|#.*$|$)/, '$1'), page) } else return this.getUserListDetail3(location.replace(/.+\/(\w+).html(?:\?.*|&.*$|#.*$|$)/, '$1'), page)
} }
// console.log('location', location)
return this.getUserListDetail(location, page, ++retryNum) return this.getUserListDetail(location, page, ++retryNum)
} }
if (typeof body == 'string') return this.getUserListDetail2(body.replace(/^[\s\S]+?"global_collection_id":"(\w+)"[\s\S]+?$/, '$1'))
if (body.errcode !== 0) return this.getUserListDetail(link, page, ++retryNum) if (body.errcode !== 0) return this.getUserListDetail(link, page, ++retryNum)
return this.getUserListDetailByLink(body, link) return this.getUserListDetailByLink(body, link)
}, },
async getListDetail(id, page) { // 获取歌曲列表内的音乐
id = id.toString()
if (id.includes('special/single/')) {
id = id.replace(this.regExps.listDetailLink, '$1')
} else if (/https?:/.test(id)) {
// fix https://www.kugou.com/songlist/xxx/?uid=xxx&chl=qq_client&cover=http%3A%2F%2Fimge.kugou.com%xxx.jpg&iszlist=1
return this.getUserListDetail(id.replace(/^.*?http/, 'http'), page)
} else if (/^\d+$/.test(id)) {
return this.getUserListDetailByCode(id)
} else if (id.startsWith('id_')) {
id = id.replace('id_', '')
}
// if ((/[?&:/]/.test(id))) id = id.replace(this.regExps.listDetailLink, '$1')
return this.getListDetailBySpecialId(id, page)
},
filterData(rawList) {
// console.log(rawList)
return rawList.map(item => {
const types = []
const _types = {}
if (item.filesize !== 0) {
let size = sizeFormate(item.filesize)
types.push({ type: '128k', size, hash: item.hash })
_types['128k'] = {
size,
hash: item.hash,
}
}
if (item.filesize_320 !== 0) {
let size = sizeFormate(item.filesize_320)
types.push({ type: '320k', size, hash: item.hash_320 })
_types['320k'] = {
size,
hash: item.hash_320,
}
}
if (item.filesize_ape !== 0) {
let size = sizeFormate(item.filesize_ape)
types.push({ type: 'ape', size, hash: item.hash_ape })
_types.ape = {
size,
hash: item.hash_ape,
}
}
if (item.filesize_flac !== 0) {
let size = sizeFormate(item.filesize_flac)
types.push({ type: 'flac', size, hash: item.hash_flac })
_types.flac = {
size,
hash: item.hash_flac,
}
}
return {
singer: decodeName(item.singername),
name: decodeName(item.songname),
albumName: decodeName(item.album_name),
albumId: item.album_id,
songmid: item.audio_id,
source: 'kg',
interval: formatPlayTime(item.duration / 1000),
img: null,
lrc: null,
hash: item.hash,
types,
_types,
typeUrl: {},
}
})
},
// getSinger(singers) {
// let arr = []
// singers?.forEach(singer => {
// arr.push(singer.name)
// })
// return arr.join('、')
// },
// v9 API
// filterDatav9(rawList) {
// console.log(rawList)
// return rawList.map(item => {
// const types = []
// const _types = {}
// item.relate_goods.forEach(qualityObj => {
// if (qualityObj.level === 2) {
// let size = sizeFormate(qualityObj.size)
// types.push({ type: '128k', size, hash: qualityObj.hash })
// _types['128k'] = {
// size,
// hash: qualityObj.hash,
// }
// } else if (qualityObj.level === 4) {
// let size = sizeFormate(qualityObj.size)
// types.push({ type: '320k', size, hash: qualityObj.hash })
// _types['320k'] = {
// size,
// hash: qualityObj.hash,
// }
// } else if (qualityObj.level === 5) {
// let size = sizeFormate(qualityObj.size)
// types.push({ type: 'flac', size, hash: qualityObj.hash })
// _types.flac = {
// size,
// hash: qualityObj.hash,
// }
// } else if (qualityObj.level === 6) {
// let size = sizeFormate(qualityObj.size)
// types.push({ type: 'flac24bit', size, hash: qualityObj.hash })
// _types.flac24bit = {
// size,
// hash: qualityObj.hash,
// }
// }
// })
// const nameInfo = item.name.split(' - ')
// return {
// singer: this.getSinger(item.singerinfo),
// name: decodeName((nameInfo[1] ?? nameInfo[0]).trim()),
// albumName: decodeName(item.albuminfo.name),
// albumId: item.albuminfo.id,
// songmid: item.audio_id,
// source: 'kg',
// interval: formatPlayTime(item.timelen / 1000),
// img: null,
// lrc: null,
// hash: item.hash,
// types,
// _types,
// typeUrl: {},
// }
// })
// },
// hash list filter
filterData2(rawList) {
// console.log(rawList)
let ids = new Set()
let list = []
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 = {}
if (item.audio_info.filesize !== '0') {
let size = sizeFormate(parseInt(item.audio_info.filesize))
types.push({ type: '128k', size, hash: item.audio_info.hash })
_types['128k'] = {
size,
hash: item.audio_info.hash,
}
}
if (item.audio_info.filesize_320 !== '0') {
let size = sizeFormate(parseInt(item.audio_info.filesize_320))
types.push({ type: '320k', size, hash: item.audio_info.hash_320 })
_types['320k'] = {
size,
hash: item.audio_info.hash_320,
}
}
if (item.audio_info.filesize_flac !== '0') {
let size = sizeFormate(parseInt(item.audio_info.filesize_flac))
types.push({ type: 'flac', size, hash: item.audio_info.hash_flac })
_types.flac = {
size,
hash: item.audio_info.hash_flac,
}
}
if (item.audio_info.filesize_high !== '0') {
let size = sizeFormate(parseInt(item.audio_info.filesize_high))
types.push({ type: 'flac24bit', size, hash: item.audio_info.hash_high })
_types.flac24bit = {
size,
hash: item.audio_info.hash_high,
}
}
list.push({
singer: decodeName(item.author_name),
name: decodeName(item.ori_audio_name),
albumName: decodeName(item.album_info.album_name),
albumId: item.album_info.album_id,
songmid: item.audio_info.audio_id,
source: 'kg',
interval: formatPlayTime(parseInt(item.audio_info.timelength) / 1000),
img: null,
lrc: null,
hash: item.audio_info.hash,
otherSource: null,
types,
_types,
typeUrl: {},
})
})
return list
},
// 获取列表信息 // 获取列表信息
getListInfo(tagId, tryNum = 0) { getListInfo(tagId, tryNum = 0) {
if (this._requestObj_listInfo) this._requestObj_listInfo.cancelHttp() if (this._requestObj_listInfo) this._requestObj_listInfo.cancelHttp()
@ -759,33 +887,32 @@ export default {
}, },
search(text, page, limit = 20) { search(text, page, limit = 20) {
const params = `userid=1384394652&req_custom=1&appid=1005&req_multi=1&version=11589&page=${page}&filter=0&pagesize=${limit}&order=0&clienttime=1681779443&iscorrection=1&searchsong=0&keyword=${text}&mid=288799920684148686226285199951543865551&dfid=3eSBsO1u97EY1zeIZd40hH4p&clientver=11589&platform=AndroidFilter` // http://msearchretry.kugou.com/api/v3/search/special?version=9209&keyword=%E5%91%A8%E6%9D%B0%E4%BC%A6&pagesize=20&filter=0&page=1&sver=2&with_res_tag=0
const url = encodeURI(`http://complexsearchretry.kugou.com/v1/search/special?${params}&signature=${signatureParams(params, 1)}`) // return httpFetch(`http://ioscdn.kugou.com/api/v3/search/special?keyword=${encodeURIComponent(text)}&page=${page}&pagesize=${limit}&showtype=10&plat=2&version=7910&correct=1&sver=5`)
return createHttpFetch(url).then(body => { return httpFetch(`http://msearchretry.kugou.com/api/v3/search/special?keyword=${encodeURIComponent(text)}&page=${page}&pagesize=${limit}&showtype=10&filter=0&version=7910&sver=2`)
// console.log(body) .promise.then(({ body }) => {
if (body.errcode != 0) throw new Error('filed')
// console.log(body.data.info)
return { return {
list: body.lists.map(item => { list: body.data.info.map(item => {
return { return {
play_count: formatPlayCount(item.total_play_count), play_count: formatPlayCount(item.playcount),
id: item.gid ? `gid_${item.gid}` : `id_${item.specialid}`, id: 'id_' + item.specialid,
author: item.nickname, author: item.nickname,
name: item.specialname, name: item.specialname,
time: dateFormat(item.publish_time, 'Y-M-D'), time: dateFormat(item.publishtime, 'Y-M-D'),
img: item.img, img: item.imgurl,
grade: item.grade, grade: item.grade,
desc: item.intro, desc: item.intro,
total: item.song_count, total: item.songcount,
source: 'kg', source: 'kg',
} }
}), }),
limit, limit,
total: body.total, total: body.data.total,
source: 'kg', source: 'kg',
} }
}) })
// http://msearchretry.kugou.com/api/v3/search/special?version=9209&keyword=%E5%91%A8%E6%9D%B0%E4%BC%A6&pagesize=20&filter=0&page=1&sver=2&with_res_tag=0
// http://ioscdn.kugou.com/api/v3/search/special?keyword=${encodeURIComponent(text)}&page=${page}&pagesize=${limit}&showtype=10&plat=2&version=7910&correct=1&sver=5
// http://msearchretry.kugou.com/api/v3/search/special?keyword=${encodeURIComponent(text)}&page=${page}&pagesize=${limit}&showtype=10&filter=0&version=7910&sver=2
}, },
} }

View File

@ -1,3 +1,4 @@
import { formatSingerName } from '@renderer/utils/musicSdk/utils'
import { decodeName, formatPlayTime, sizeFormate } from '../../index' import { decodeName, formatPlayTime, sizeFormate } from '../../index'
import { signatureParams, createHttpFetch } from './util' import { signatureParams, createHttpFetch } from './util'
@ -58,8 +59,8 @@ export default {
} }
} }
list.push({ list.push({
singer: decodeName(item.SingerName), singer: decodeName(formatSingerName(item.Singers)),
name: decodeName(item.OriSongName), name: decodeName(item.SongName),
albumName: decodeName(item.AlbumName), albumName: decodeName(item.AlbumName),
albumId: item.AlbumID, albumId: item.AlbumID,
songmid: item.Audioid, songmid: item.Audioid,

View File

@ -20,25 +20,18 @@ export const decodeLyric = str => new Promise((resolve, reject) => {
// console.log(str) // console.log(str)
// }) // })
const signatureKey = { app: 'OIlwieks28dk2k092lksi2UIkp', web: 'NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt' }
/** /**
* 签名 * 签名
* @param {*} params * @param {*} params
* @param {*} apiver * @param {*} apiver
*/ */
export const signatureParams = (params, apiver = 9) => { export const signatureParams = (params, apiver = 9) => {
let key = signatureKey.app let keyparam = 'OIlwieks28dk2k092lksi2UIkp'
if (apiver === 5) key = signatureKey.web if (apiver === 5) keyparam = 'NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt'
let param_list = params.split('&')
if (typeof params === 'object') { param_list.sort()
if (!Array.isArray(params)) throw new Error('params error.') let sign_params = `${keyparam}${param_list.join('')}${keyparam}`
params = params.sort() return toMD5(sign_params)
} else if (typeof params === 'string') {
params = params.split('&').sort()
} else throw new Error('params error.')
return toMD5(`${key}${params.join('')}${key}`)
} }
/** /**
@ -59,12 +52,9 @@ export const createHttpFetch = async(url, options, retryNum = 0) => {
// console.log(result.statusCode, result.body) // console.log(result.statusCode, result.body)
if (result.statusCode !== 200 || if (result.statusCode !== 200 ||
( (
(result.body.error_code !== undefined result.body.error_code ??
? result.body.error_code result.body.errcode ??
: result.body.errcode !== undefined result.body.err_code) != 0
? result.body.errcode
: result.body.err_code
) !== 0)
) return createHttpFetch(url, options, ++retryNum) ) return createHttpFetch(url, options, ++retryNum)
if (result.body.data) return result.body.data if (result.body.data) return result.body.data
if (Array.isArray(result.body.info)) return result.body if (Array.isArray(result.body.info)) return result.body

View File

@ -27,7 +27,7 @@ export default {
desc: listInfo.desc, desc: listInfo.desc,
author: listInfo.author, author: listInfo.author,
play_count: listInfo.play_count, play_count: listInfo.play_count,
} },
} }
}, },
/** /**

View File

@ -6,10 +6,10 @@ import pic from './pic'
import lyric from './lyric' import lyric from './lyric'
import hotSearch from './hotSearch' import hotSearch from './hotSearch'
import comment from './comment' import comment from './comment'
import tipSearch from './tipSearch' // import tipSearch from './tipSearch'
const mg = { const mg = {
tipSearch, // tipSearch,
songList, songList,
musicSearch, musicSearch,
leaderboard, leaderboard,

View File

@ -2,7 +2,7 @@ import { sizeFormate } from '../../index'
import { createHttpFetch } from './utils' import { createHttpFetch } from './utils'
import { formatSingerName } from '../utils' import { formatSingerName } from '../utils'
const createGetMusicInfosTask = (ids, resType = 2) => { const createGetMusicInfosTask = (ids) => {
let list = ids let list = ids
let tasks = [] let tasks = []
while (list.length) { while (list.length) {
@ -10,13 +10,13 @@ const createGetMusicInfosTask = (ids, resType = 2) => {
if (list.length < 100) break if (list.length < 100) break
list = list.slice(100) list = list.slice(100)
} }
let url = `https://c.musicapp.migu.cn/MIGUM2.0/v1.0/content/resourceinfo.do?resourceType=${resType}` let url = 'https://c.musicapp.migu.cn/MIGUM2.0/v1.0/content/resourceinfo.do?resourceType=2'
return tasks.map(task => createHttpFetch(url, { return Promise.all(tasks.map(task => createHttpFetch(url, {
method: 'POST', method: 'POST',
form: { form: {
resourceId: task.join('|'), resourceId: task.join('|'),
}, },
}).then(data => data.resource)) }).then(data => data.resource)))
} }
export const filterMusicInfoList = (rawList) => { export const filterMusicInfoList = (rawList) => {
@ -92,5 +92,5 @@ export const getMusicInfo = async(copyrightId) => {
} }
export const getMusicInfos = async(copyrightIds) => { export const getMusicInfos = async(copyrightIds) => {
return filterMusicInfoList(await Promise.all(createGetMusicInfosTask(copyrightIds)).then(data => data)) return filterMusicInfoList(await Promise.all(createGetMusicInfosTask(copyrightIds)).then(data => data.flat()))
} }

View File

@ -1,10 +1,13 @@
import { httpFetch } from '../../request'
import { sizeFormate, formatPlayTime } from '../../index' import { sizeFormate, formatPlayTime } from '../../index'
import { createHttpFetch } from './utils' import { toMD5 } from '../utils'
import { formatSingerName, toMD5 } from '../utils' import { formatSingerName } from '@renderer/utils/musicSdk/utils'
const searchSign = (timeStr, str, deviceId) => { const sign = (time, str) => {
const key = '6cdc72a439cef99a3418d2a78aa28c73' const deviceId = '963B7AA0D21511ED807EE5846EC87D20'
return toMD5(`${str}${key}yyapp2d16148780a1dcc7408e06336b98cfd50${deviceId}${timeStr}`) const signatureMd5 = '6cdc72a439cef99a3418d2a78aa28c73'
const sign = toMD5(`${str}${signatureMd5}yyapp2d16148780a1dcc7408e06336b98cfd50${deviceId}${time}`)
return { sign, deviceId }
} }
export default { export default {
@ -12,33 +15,129 @@ export default {
total: 0, total: 0,
page: 0, page: 0,
allPage: 1, allPage: 1,
deviceId: '963B7AA0D21511ED807EE5846EC87D20',
musicSearch(str, page, limit) { // 旧版API
// musicSearch(str, page, limit) {
// const searchRequest = httpFetch(`http://pd.musicapp.migu.cn/MIGUM2.0/v1.0/content/search_all.do?ua=Android_migu&version=5.0.1&text=${encodeURIComponent(str)}&pageNo=${page}&pageSize=${limit}&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A0%2C%22mvSong%22%3A0%2C%22songlist%22%3A0%2C%22bestShow%22%3A1%7D`, {
// searchRequest = httpFetch(`http://pd.musicapp.migu.cn/MIGUM2.0/v1.0/content/search_all.do?ua=Android_migu&version=5.0.1&text=${encodeURIComponent(str)}&pageNo=${page}&pageSize=${limit}&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A0%2C%22mvSong%22%3A0%2C%22songlist%22%3A0%2C%22bestShow%22%3A1%7D`, {
// searchRequest = httpFetch(`http://jadeite.migu.cn:7090/music_search/v2/search/searchAll?sid=4f87090d01c84984a11976b828e2b02c18946be88a6b4c47bcdc92fbd40762db&isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, {
// searchRequest = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?isCopyright=1&isCorrect=1&pageNo=${page}&pageSize=${limit}&searchSwitch={%22song%22:1,%22album%22:0,%22singer%22:0,%22tagSong%22:0,%22mvSong%22:0,%22songlist%22:0,%22bestShow%22:0}&sort=0&text=${encodeURIComponent(str)}`) // searchRequest = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?isCopyright=1&isCorrect=1&pageNo=${page}&pageSize=${limit}&searchSwitch={%22song%22:1,%22album%22:0,%22singer%22:0,%22tagSong%22:0,%22mvSong%22:0,%22songlist%22:0,%22bestShow%22:0}&sort=0&text=${encodeURIComponent(str)}`)
const timeStr = Date.now().toString() // // searchRequest = httpFetch(`http://jadeite.migu.cn:7090/music_search/v2/search/searchAll?sid=4f87090d01c84984a11976b828e2b02c18946be88a6b4c47bcdc92fbd40762db&isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, {
const signResult = searchSign(timeStr, str, this.deviceId) // headers: {
return createHttpFetch(`https://jadeite.migu.cn/music_search/v3/search/searchAll?isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, { // // sign: 'c3b7ae985e2206e97f1b2de8f88691e2',
// // timestamp: 1578225871982,
// // appId: 'yyapp2',
// // mode: 'android',
// // ua: 'Android_migu',
// // version: '6.9.4',
// osVersion: 'android 7.0',
// 'User-Agent': 'okhttp/3.9.1',
// },
// })
// // searchRequest = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?isCopyright=1&isCorrect=1&pageNo=${page}&pageSize=${limit}&searchSwitch={%22song%22:1,%22album%22:0,%22singer%22:0,%22tagSong%22:0,%22mvSong%22:0,%22songlist%22:0,%22bestShow%22:0}&sort=0&text=${encodeURIComponent(str)}`)
// return searchRequest.promise.then(({ body }) => body)
// },
// handleResult(rawData) {
// // console.log(rawData)
// let ids = new Set()
// const list = []
// rawData.forEach(item => {
// if (ids.has(item.id)) return
// ids.add(item.id)
// const types = []
// const _types = {}
// item.newRateFormats && item.newRateFormats.forEach(type => {
// let size
// switch (type.formatType) {
// case 'PQ':
// size = sizeFormate(type.size ?? type.androidSize)
// types.push({ type: '128k', size })
// _types['128k'] = {
// size,
// }
// break
// case 'HQ':
// size = sizeFormate(type.size ?? type.androidSize)
// types.push({ type: '320k', size })
// _types['320k'] = {
// size,
// }
// break
// case 'SQ':
// size = sizeFormate(type.size ?? type.androidSize)
// types.push({ type: 'flac', size })
// _types.flac = {
// size,
// }
// break
// case 'ZQ':
// size = sizeFormate(type.size ?? type.androidSize)
// types.push({ type: 'flac24bit', size })
// _types.flac24bit = {
// size,
// }
// break
// }
// })
// const albumNInfo = item.albums && item.albums.length
// ? {
// id: item.albums[0].id,
// name: item.albums[0].name,
// }
// : {}
// list.push({
// singer: this.getSinger(item.singers),
// name: item.name,
// albumName: albumNInfo.name,
// albumId: albumNInfo.id,
// songmid: item.songId,
// copyrightId: item.copyrightId,
// source: 'mg',
// interval: null,
// img: item.imgItems && item.imgItems.length ? item.imgItems[0].img : null,
// lrc: null,
// lrcUrl: item.lyricUrl,
// mrcUrl: item.mrcurl,
// trcUrl: item.trcUrl,
// otherSource: null,
// types,
// _types,
// typeUrl: {},
// })
// })
// return list
// },
musicSearch(str, page, limit) {
const time = Date.now().toString()
const signData = sign(time, str)
const searchRequest = httpFetch(`https://jadeite.migu.cn/music_search/v3/search/searchAll?isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, {
headers: { headers: {
uiVersion: 'A_music_3.6.1', uiVersion: 'A_music_3.6.1',
deviceId: this.deviceId, deviceId: signData.deviceId,
timestamp: timeStr, timestamp: time,
sign: signResult, sign: signData.sign,
channel: '0146921', channel: '0146921',
'User-Agent': 'Mozilla/5.0 (Linux; U; Android 11.0.0; zh-cn; MI 11 Build/OPR1.170623.032) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30', 'User-Agent': 'Mozilla/5.0 (Linux; U; Android 11.0.0; zh-cn; MI 11 Build/OPR1.170623.032) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
}, },
}).then(body => body) })
return searchRequest.promise.then(({ body }) => body)
}, },
filterList(raw) { filterData(rawData) {
const ids = new Set() // console.log(rawData)
const list = [] const list = []
const ids = new Set()
raw.forEach(item => { rawData.forEach(item => {
if (!item.songId || !item.copyrightId || ids.has(item.copyrightId)) return item.forEach(data => {
ids.add(item.copyrightId) if (!data.songId || !data.copyrightId || ids.has(data.copyrightId)) return
ids.add(data.copyrightId)
const types = [] const types = []
const _types = {} const _types = {}
item.audioFormats && item.audioFormats.forEach(type => { data.audioFormats && data.audioFormats.forEach(type => {
let size let size
switch (type.formatType) { switch (type.formatType) {
case 'PQ': case 'PQ':
@ -72,55 +171,54 @@ export default {
} }
}) })
let img = item.img3 || item.img2 || item.img1 || null let img = data.img3 || data.img2 || data.img1 || null
if (img && !/https?:/.test(item.img3)) img = 'http://d.musicapp.migu.cn' + img if (img && !/https?:/.test(data.img3)) img = 'http://d.musicapp.migu.cn' + img
list.push({ list.push({
singer: formatSingerName(item.singerList, 'name'), singer: formatSingerName(data.singerList),
name: item.name, name: data.name,
albumName: item.album, albumName: data.album,
albumId: item.albumId, albumId: data.albumId,
songmid: item.songId, songmid: data.songId,
copyrightId: item.copyrightId, copyrightId: data.copyrightId,
source: 'mg', source: 'mg',
interval: formatPlayTime(item.duration), interval: formatPlayTime(data.duration),
img, img,
lrc: null, lrc: null,
lrcUrl: item.lrcUrl, lrcUrl: data.lrcUrl,
mrcUrl: item.mrcurl, mrcUrl: data.mrcurl,
trcUrl: item.trcUrl, trcUrl: data.trcUrl,
types, types,
_types, _types,
typeUrl: {}, typeUrl: {},
}) })
}) })
})
return list return list
}, },
handleResult(rawData) {
return this.filterList(rawData.flat())
},
search(str, page = 1, limit, retryNum = 0) { search(str, page = 1, limit, retryNum = 0) {
if (++retryNum > 3) return Promise.reject(new Error('try max num')) if (++retryNum > 3) return Promise.reject(new Error('try max num'))
if (limit == null) limit = this.limit if (limit == null) limit = this.limit
// http://newlyric.kuwo.cn/newlyric.lrc?62355680
return this.musicSearch(str, page, limit).then(result => {
// console.log(result)
if (!result || result.code !== '000000') return Promise.reject(new Error(result ? result.info : '搜索失败'))
const songResultData = result.songResultData || { resultList: [], totalCount: 0 }
return this.musicSearch(str, page, limit).then(data => { let list = this.filterData(songResultData.resultList)
const songResultData = data.songResultData || { resultList: [], totalCount: 0 }
let list = this.handleResult(songResultData.resultList)
if (list == null) return this.search(str, page, limit, retryNum) if (list == null) return this.search(str, page, limit, retryNum)
this.total = parseInt(songResultData.totalCount) this.total = parseInt(songResultData.totalCount)
this.page = page this.page = page
this.allPage = Math.ceil(this.total / limit) this.allPage = Math.ceil(this.total / limit)
return Promise.resolve({ return {
list, list,
allPage: this.allPage, allPage: this.allPage,
limit, limit,
total: this.total, total: this.total,
source: 'mg', source: 'mg',
}) }
}) })
}, },
} }

View File

@ -5,10 +5,10 @@ import musicSearch from './musicSearch'
import { apis } from '../api-source' import { apis } from '../api-source'
import hotSearch from './hotSearch' import hotSearch from './hotSearch'
import comment from './comment' import comment from './comment'
import tipSearch from './tipSearch' // import tipSearch from './tipSearch'
const tx = { const tx = {
tipSearch, // tipSearch,
leaderboard, leaderboard,
songList, songList,
musicSearch, musicSearch,

View File

@ -1,27 +1,29 @@
import { httpFetch } from '../../request' import { httpFetch } from '../../request'
export default { export default {
// regExps: {
// relWord: /RELWORD=(.+)/,
// },
requestObj: null, requestObj: null,
cancelTipSearch() { tipSearch(str) {
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
},
tipSearchBySong(str) {
this.cancelTipSearch() this.cancelTipSearch()
this.requestObj = httpFetch(`https://c.y.qq.com/splcloud/fcgi-bin/smartbox_new.fcg?&format=json&inCharset=utf-8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=1&uin=0&hostUin=0&is_xml=0&key=${encodeURIComponent(str)}`, { this.requestObj = httpFetch(`https://c.y.qq.com/splcloud/fcgi-bin/smartbox_new.fcg?is_xml=0&format=json&key=${encodeURIComponent(str)}&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq&needNewCode=0`, {
headers: { headers: {
origin: 'https://y.qq.com/', Referer: 'https://y.qq.com/portal/player.html',
referer: 'https://y.qq.com/',
}, },
}) })
return this.requestObj.promise.then(({ statusCode, body }) => { return this.requestObj.promise.then(({ statusCode, body }) => {
if (statusCode != 200 || body.code != 0) return Promise.reject(new Error('请求失败')) if (statusCode != 200 || body.code != 0) return Promise.reject(new Error('请求失败'))
return body.data.song.itemlist return body.data
}) })
}, },
handleResult(rawData) { handleResult(rawData) {
return rawData.map(info => `${info.name} - ${info.singer}`) return rawData.map(info => `${info.name} - ${info.singer}`)
}, },
cancelTipSearch() {
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
},
async search(str) { async search(str) {
return this.tipSearchBySong(str).then(result => this.handleResult(result)) return this.tipSearch(str).then(result => this.handleResult(result.song.itemlist))
}, },
} }

View File

@ -22,7 +22,6 @@ export const getHostIp = hostname => {
}) })
} }
export const dnsLookup = (hostname, options, callback) => { export const dnsLookup = (hostname, options, callback) => {
const result = getHostIp(hostname) const result = getHostIp(hostname)
if (result) return callback(null, result.address, result.family) if (result) return callback(null, result.address, result.family)
@ -34,24 +33,24 @@ export const dnsLookup = (hostname, options, callback) => {
/** /**
* 格式化歌手 * 格式化歌手
* @param singers 歌手数组 * @param singers 歌手数组
* @param obj 读取的数据 * @param nameKey 歌手名键值
* @param join 插入的字符 * @param join 歌手分割字符
*/ */
export const formatSingerName = (singers, obj = 'name', join = '、') => { export const formatSingerName = (singers, nameKey = 'name', join = '、') => {
if (typeof singers === 'string') { if (typeof singers == 'string') {
try { try {
singers = JSON.parse(singers) singers = JSON.parse(singers)
} catch (err) { } catch (err) {
return decodeName(singers) return decodeName(singers)
} }
} } else if (Array.isArray(singers)) {
if (!Array.isArray(singers)) return decodeName(singers)
const singer = [] const singer = []
singers.forEach(item => { singers.forEach(item => {
let name = item[obj] let name = item[nameKey]
if (!name) return if (!name) return
singer.push(name) singer.push(name)
}) })
return decodeName(singer.join(join)) return decodeName(singer.join(join))
} }
return decodeName(String(singers ?? ''))
}

View File

@ -6,10 +6,10 @@ import musicSearch from './musicSearch'
import songList from './songList' import songList from './songList'
import hotSearch from './hotSearch' import hotSearch from './hotSearch'
import comment from './comment' import comment from './comment'
import tipSearch from './tipSearch' // import tipSearch from './tipSearch'
const wy = { const wy = {
tipSearch, // tipSearch,
leaderboard, leaderboard,
musicSearch, musicSearch,
songList, songList,