支持打开短链接歌单
parent
9ca0ec82a8
commit
353e8bd0de
|
@ -12,6 +12,7 @@ export default {
|
|||
_requestObj_hotTags: null,
|
||||
_requestObj_list: null,
|
||||
_requestObj_listDetail: null,
|
||||
_requestObj_listDetailLink: null,
|
||||
limit_list: 30,
|
||||
limit_song: 100000,
|
||||
successCode: 200,
|
||||
|
@ -45,11 +46,26 @@ export default {
|
|||
return arr.join('、')
|
||||
},
|
||||
|
||||
getListDetail(id, page, tryNum = 0) { // 获取歌曲列表内的音乐
|
||||
async handleParseId(link, retryNum = 0) {
|
||||
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)
|
||||
const { headers: { location }, statusCode } = await this._requestObj_listDetailLink.promise
|
||||
// console.log(headers)
|
||||
if (statusCode > 400) return this.handleParseId(link, ++retryNum)
|
||||
return location == null ? link : location
|
||||
},
|
||||
|
||||
async 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))) {
|
||||
if (!this.regExps.listDetailLink.test(id)) id = await this.handleParseId(id)
|
||||
// console.log(id)
|
||||
id = id.replace(this.regExps.listDetailLink, '$1')
|
||||
}
|
||||
|
||||
this._requestObj_listDetail = httpFetch('https://music.163.com/api/linux/forward', {
|
||||
method: 'post',
|
||||
|
@ -64,23 +80,22 @@ export default {
|
|||
},
|
||||
}),
|
||||
})
|
||||
return this._requestObj_listDetail.promise.then(({ body }) => {
|
||||
if (body.code !== this.successCode) return this.getListDetail(id, page, ++tryNum)
|
||||
return {
|
||||
list: this.filterListDetail(body),
|
||||
page,
|
||||
limit: this.limit_song,
|
||||
total: body.playlist.tracks.length,
|
||||
source: 'wy',
|
||||
info: {
|
||||
play_count: this.formatPlayCount(body.playlist.playCount),
|
||||
name: body.playlist.name,
|
||||
img: body.playlist.coverImgUrl,
|
||||
desc: body.playlist.description,
|
||||
author: body.playlist.creator.nickname,
|
||||
},
|
||||
}
|
||||
})
|
||||
const { body } = await this._requestObj_listDetail.promise
|
||||
if (body.code !== this.successCode) return this.getListDetail(id, page, ++tryNum)
|
||||
return {
|
||||
list: this.filterListDetail(body),
|
||||
page,
|
||||
limit: this.limit_song,
|
||||
total: body.playlist.tracks.length,
|
||||
source: 'wy',
|
||||
info: {
|
||||
play_count: this.formatPlayCount(body.playlist.playCount),
|
||||
name: body.playlist.name,
|
||||
img: body.playlist.coverImgUrl,
|
||||
desc: body.playlist.description,
|
||||
author: body.playlist.creator.nickname,
|
||||
},
|
||||
}
|
||||
},
|
||||
filterListDetail({ playlist: { tracks }, privileges }) {
|
||||
// console.log(tracks, privileges)
|
||||
|
|
Loading…
Reference in New Issue