支持打开短链接歌单

pull/166/head
lyswhut 2020-03-14 23:36:38 +08:00
parent 9ca0ec82a8
commit 353e8bd0de
1 changed files with 34 additions and 19 deletions

View File

@ -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,7 +80,7 @@ export default {
},
}),
})
return this._requestObj_listDetail.promise.then(({ body }) => {
const { body } = await this._requestObj_listDetail.promise
if (body.code !== this.successCode) return this.getListDetail(id, page, ++tryNum)
return {
list: this.filterListDetail(body),
@ -80,7 +96,6 @@ export default {
author: body.playlist.creator.nickname,
},
}
})
},
filterListDetail({ playlist: { tracks }, privileges }) {
// console.log(tracks, privileges)