|
|
|
@@ -7,6 +7,7 @@ export default {
|
|
|
|
|
_requestObj_list: null,
|
|
|
|
|
_requestObj_listRecommend: null,
|
|
|
|
|
_requestObj_listDetail: null,
|
|
|
|
|
listDetailLimit: 100,
|
|
|
|
|
currentTagInfo: {
|
|
|
|
|
id: undefined,
|
|
|
|
|
info: undefined,
|
|
|
|
@@ -144,11 +145,106 @@ export default {
|
|
|
|
|
}))
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async createHttp(data, retryNum = 0) {
|
|
|
|
|
if (retryNum > 2) new Error('try max num')
|
|
|
|
|
let result
|
|
|
|
|
try {
|
|
|
|
|
result = await httpFetch('http://kmr.service.kugou.com/v2/album_audio/audio', { method: 'POST', body: data }).promise
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.log(err)
|
|
|
|
|
return this.createHttp(data, ++retryNum)
|
|
|
|
|
}
|
|
|
|
|
if (result.statusCode !== 200 || result.body.error_code !== 0) return this.createHttp(data, ++retryNum)
|
|
|
|
|
return result.body.data.map(s => s[0])
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
createTaks(hashs) {
|
|
|
|
|
let data = {
|
|
|
|
|
appid: 1001,
|
|
|
|
|
clienttime: 639437935,
|
|
|
|
|
clientver: 9020,
|
|
|
|
|
fields:
|
|
|
|
|
'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, 20) }, data))
|
|
|
|
|
if (list.length < 20) break
|
|
|
|
|
list = list.slice(20)
|
|
|
|
|
}
|
|
|
|
|
return tasks.map(task => this.createHttp(task))
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async getUserListDetail(link, page, retryNum = 0) {
|
|
|
|
|
if (link.includes('#')) link = link.replace(/#.*$/, '')
|
|
|
|
|
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}`
|
|
|
|
|
}
|
|
|
|
|
return this.getUserListDetail(link, page, ++retryNum)
|
|
|
|
|
}
|
|
|
|
|
if (this._requestObj_listDetailLink) this._requestObj_listDetailLink.cancelHttp()
|
|
|
|
|
if (retryNum > 2) return Promise.reject(new Error('link try max num'))
|
|
|
|
|
|
|
|
|
|
this._requestObj_listDetailLink = httpFetch(link, {
|
|
|
|
|
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',
|
|
|
|
|
Referer: link,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
const { headers: { location }, statusCode, body } = await this._requestObj_listDetailLink.promise
|
|
|
|
|
// console.log(body)
|
|
|
|
|
if (statusCode > 400) return this.getUserListDetail(link, page, ++retryNum)
|
|
|
|
|
if (!body && location) {
|
|
|
|
|
// console.log('location', location)
|
|
|
|
|
let link = location.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)
|
|
|
|
|
}
|
|
|
|
|
if (body.errcode !== 0) return this.getUserListDetail(link, page, ++retryNum)
|
|
|
|
|
let listInfo = body.info['0']
|
|
|
|
|
let result = body.list.info.map(item => ({ hash: item.hash }))
|
|
|
|
|
result = await Promise.all(this.createTaks(result)).then(([...datas]) => datas.flat())
|
|
|
|
|
return {
|
|
|
|
|
list: this.filterData2(result) || [],
|
|
|
|
|
page,
|
|
|
|
|
limit: this.listDetailLimit,
|
|
|
|
|
total: listInfo.count,
|
|
|
|
|
source: 'kg',
|
|
|
|
|
info: {
|
|
|
|
|
name: listInfo.name,
|
|
|
|
|
img: listInfo.pic && listInfo.pic.replace('{size}', 240),
|
|
|
|
|
// desc: body.result.info.list_desc,
|
|
|
|
|
author: listInfo.list_create_username,
|
|
|
|
|
// play_count: this.formatPlayCount(listInfo.count),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getListDetail(id, page, tryNum = 0) { // 获取歌曲列表内的音乐
|
|
|
|
|
if (this._requestObj_listDetail) this._requestObj_listDetail.cancelHttp()
|
|
|
|
|
if (tryNum > 2) return Promise.reject(new Error('try max num'))
|
|
|
|
|
|
|
|
|
|
if ((/[?&:/]/.test(id))) id = id.replace(this.regExps.listDetailLink, '$1')
|
|
|
|
|
// if ((/[?&]/.test(id))) {
|
|
|
|
|
// id = id.replace(this.regExps.listDetailLink, '$1')
|
|
|
|
|
// } else
|
|
|
|
|
if (/http(?:s):/.test(id)) {
|
|
|
|
|
return this.getUserListDetail(id, page)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if ((/[?&:/]/.test(id))) id = id.replace(this.regExps.listDetailLink, '$1')
|
|
|
|
|
|
|
|
|
|
this._requestObj_listDetail = httpFetch(this.getSongListDetailUrl(id))
|
|
|
|
|
return this._requestObj_listDetail.promise.then(({ body }) => {
|
|
|
|
@@ -233,6 +329,57 @@ export default {
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// hash list filter
|
|
|
|
|
filterData2(rawList) {
|
|
|
|
|
// console.log(rawList)
|
|
|
|
|
let list = []
|
|
|
|
|
rawList.forEach(item => {
|
|
|
|
|
if (!item) return
|
|
|
|
|
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,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
list.push({
|
|
|
|
|
singer: item.author_name,
|
|
|
|
|
name: item.ori_audio_name,
|
|
|
|
|
albumName: 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,
|
|
|
|
|
types,
|
|
|
|
|
_types,
|
|
|
|
|
typeUrl: {},
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
return list
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 获取列表信息
|
|
|
|
|
getListInfo(tagId, tryNum = 0) {
|
|
|
|
|
if (this._requestObj_listInfo) this._requestObj_listInfo.cancelHttp()
|
|
|
|
|