新增:直接播放QQ音乐排行榜音乐
This commit is contained in:
@@ -6,9 +6,9 @@ import leaderboard from './leaderboard'
|
||||
import lyric from './lyric'
|
||||
|
||||
const kw = {
|
||||
_musicInfoIndex: null,
|
||||
_musicInfoRequestObj: null,
|
||||
_musicInfoPromiseCancelFn: null,
|
||||
_musicPicIndex: null,
|
||||
_musicPicRequestObj: null,
|
||||
_musicPicPromiseCancelFn: null,
|
||||
// context: null,
|
||||
|
||||
@@ -52,26 +52,45 @@ const kw = {
|
||||
},
|
||||
|
||||
getMusicUrl(songInfo, type) {
|
||||
return new Promise((resolve, reject) => {
|
||||
httpGet(`https://v1.itooi.cn/kuwo/url?id=${songInfo.songmid}&quality=${type.replace(/k$/, '')}&isRedirect=0`, (err, resp, body) => {
|
||||
let requestObj
|
||||
let cancelFn
|
||||
const p = new Promise((resolve, reject) => {
|
||||
cancelFn = reject
|
||||
requestObj = httpGet(`https://v1.itooi.cn/kuwo/url?id=${songInfo.songmid}&quality=${type.replace(/k$/, '')}&isRedirect=0`, (err, resp, body) => {
|
||||
requestObj = null
|
||||
cancelFn = null
|
||||
if (err) {
|
||||
console.log(err)
|
||||
return this.getMusicUrl(songInfo, type)
|
||||
const { promise, cancelHttp } = this.getMusicUrl(songInfo, type)
|
||||
obj.cancelHttp = cancelHttp
|
||||
return promise
|
||||
}
|
||||
body.code === 200 ? resolve({ type, url: body.data }) : reject(new Error(body.msg))
|
||||
})
|
||||
})
|
||||
const obj = {
|
||||
promise: p,
|
||||
cancelHttp() {
|
||||
console.log('cancel')
|
||||
if (!requestObj) return
|
||||
cancelHttp(requestObj)
|
||||
cancelFn(new Error('取消http请求'))
|
||||
requestObj = null
|
||||
cancelFn = null
|
||||
},
|
||||
}
|
||||
return obj
|
||||
},
|
||||
|
||||
getMusicInfo(songInfo) {
|
||||
if (this._musicInfoIndex != null) {
|
||||
cancelHttp(this._musicInfoIndex)
|
||||
if (this._musicInfoRequestObj != null) {
|
||||
cancelHttp(this._musicInfoRequestObj)
|
||||
this._musicInfoPromiseCancelFn(new Error('取消http请求'))
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this._musicInfoPromiseCancelFn = reject
|
||||
this._musicInfoIndex = httpGet(`http://www.kuwo.cn/api/www/music/musicInfo?mid=${songInfo.songmid}`, (err, resp, body) => {
|
||||
this._musicInfoIndex = null
|
||||
this._musicInfoRequestObj = httpGet(`http://www.kuwo.cn/api/www/music/musicInfo?mid=${songInfo.songmid}`, (err, resp, body) => {
|
||||
this._musicInfoRequestObj = null
|
||||
this._musicInfoPromiseCancelFn = null
|
||||
if (err) {
|
||||
console.log(err)
|
||||
@@ -86,7 +105,7 @@ const kw = {
|
||||
let tasks = []
|
||||
let songId = musicInfo.songmid
|
||||
musicInfo.types.forEach(type => {
|
||||
tasks.push(kw.getMusicUrl(songId, type.type))
|
||||
tasks.push(kw.getMusicUrl(songId, type.type).promise)
|
||||
})
|
||||
Promise.all(tasks).then(urlInfo => {
|
||||
let typeUrl = {}
|
||||
@@ -98,20 +117,19 @@ const kw = {
|
||||
},
|
||||
|
||||
getPic(songInfo) {
|
||||
if (this._musicPicIndex != null) {
|
||||
cancelHttp(this._musicPicIndex)
|
||||
if (this._musicPicRequestObj != null) {
|
||||
cancelHttp(this._musicPicRequestObj)
|
||||
this._musicPicPromiseCancelFn(new Error('取消http请求'))
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this._musicPicPromiseCancelFn = reject
|
||||
this._musicPicIndex = httpGet(`https://v1.itooi.cn/kuwo/pic?id=${songInfo.songmid}&isRedirect=0`, (err, resp, body) => {
|
||||
this._musicPicIndex = null
|
||||
this._musicPicRequestObj = httpGet(`https://v1.itooi.cn/kuwo/pic?id=${songInfo.songmid}&isRedirect=0`, (err, resp, body) => {
|
||||
this._musicPicRequestObj = null
|
||||
this._musicPicPromiseCancelFn = null
|
||||
if (err) {
|
||||
console.log(err)
|
||||
reject(err)
|
||||
}
|
||||
console.log(body)
|
||||
body.code === 200 ? resolve(body.data) : reject(new Error(body.msg))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -65,19 +65,19 @@ export default {
|
||||
|
||||
},
|
||||
limit: 30,
|
||||
_cancelIndex: null,
|
||||
_cancelRequestObj: null,
|
||||
_cancelPromiseCancelFn: null,
|
||||
_cancelIndex2: null,
|
||||
_cancelRequestObj2: null,
|
||||
_cancelPromiseCancelFn2: null,
|
||||
getData(url) {
|
||||
if (this._cancelIndex != null) {
|
||||
cancelHttp(this._cancelIndex)
|
||||
if (this._cancelRequestObj != null) {
|
||||
cancelHttp(this._cancelRequestObj)
|
||||
this._cancelPromiseCancelFn(new Error('取消http请求'))
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this._cancelPromiseCancelFn = reject
|
||||
this._cancelIndex = httpGet(url, (err, resp, body) => {
|
||||
this._cancelIndex = null
|
||||
this._cancelRequestObj = httpGet(url, (err, resp, body) => {
|
||||
this._cancelRequestObj = null
|
||||
this._cancelPromiseCancelFn = null
|
||||
if (err) {
|
||||
console.log(err)
|
||||
@@ -88,14 +88,14 @@ export default {
|
||||
})
|
||||
},
|
||||
getData2(url) {
|
||||
if (this._cancelIndex2 != null) {
|
||||
cancelHttp(this._cancelIndex2)
|
||||
if (this._cancelRequestObj2 != null) {
|
||||
cancelHttp(this._cancelRequestObj2)
|
||||
this._cancelPromiseCancelFn2(new Error('取消http请求'))
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this._cancelPromiseCancelFn2 = reject
|
||||
this._cancelIndex2 = httpGet(url, (err, resp, body) => {
|
||||
this._cancelIndex2 = null
|
||||
this._cancelRequestObj2 = httpGet(url, (err, resp, body) => {
|
||||
this._cancelRequestObj2 = null
|
||||
this._cancelPromiseCancelFn2 = null
|
||||
if (err) {
|
||||
console.log(err)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { httpGet, cancelHttp } from '../../request'
|
||||
|
||||
export default {
|
||||
_musicLrcIndex: null,
|
||||
_musicLrcRequestObj: null,
|
||||
_musicLrcPromiseCancelFn: null,
|
||||
formatTime(time) {
|
||||
let m = parseInt(time / 60)
|
||||
@@ -9,14 +9,14 @@ export default {
|
||||
return (m < 10 ? '0' + m : m) + ':' + (s < 10 ? '0' + s : s)
|
||||
},
|
||||
getLyric(songId) {
|
||||
if (this._musicLrcIndex != null) {
|
||||
cancelHttp(this._musicLrcIndex)
|
||||
if (this._musicLrcRequestObj != null) {
|
||||
cancelHttp(this._musicLrcRequestObj)
|
||||
this._musicLrcPromiseCancelFn(new Error('取消http请求'))
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this._musicLrcPromiseCancelFn = reject
|
||||
this._musicLrcIndex = httpGet(`https://v1.itooi.cn/kuwo/lrc?id=${songId}`, (err, resp, body) => {
|
||||
this._musicLrcIndex = null
|
||||
this._musicLrcRequestObj = httpGet(`https://v1.itooi.cn/kuwo/lrc?id=${songId}`, (err, resp, body) => {
|
||||
this._musicLrcRequestObj = null
|
||||
this._musicLrcPromiseCancelFn = null
|
||||
if (err) {
|
||||
console.log(err)
|
||||
|
||||
@@ -9,7 +9,7 @@ export default {
|
||||
regExps: {
|
||||
mInfo: /bitrate:(\d+),format:(\w+),size:([\w.]+)/,
|
||||
},
|
||||
_musicSearchIndex: null,
|
||||
_musicSearchRequestObj: null,
|
||||
_musicSearchPromiseCancelFn: null,
|
||||
limit: 30,
|
||||
total: 0,
|
||||
@@ -17,14 +17,14 @@ export default {
|
||||
allPage: 1,
|
||||
// cancelFn: null,
|
||||
musicSearch(str, page) {
|
||||
if (this._musicSearchIndex != null) {
|
||||
cancelHttp(this._musicSearchIndex)
|
||||
if (this._musicSearchRequestObj != null) {
|
||||
cancelHttp(this._musicSearchRequestObj)
|
||||
this._musicSearchPromiseCancelFn(new Error('取消http请求'))
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this._musicSearchPromiseCancelFn = reject
|
||||
this._musicSearchIndex = httpGet(`http://search.kuwo.cn/r.s?client=kt&all=${encodeURIComponent(str)}&pn=${page - 1}&rn=${this.limit}&uid=794762570&ver=kwplayer_ar_9.2.2.1&vipver=1&show_copyright_off=1&newver=1&ft=music&cluster=0&strategy=2012&encoding=utf8&rformat=json&vermerge=1&mobi=1&issubtitle=1`, (err, resp, body) => {
|
||||
this._musicSearchIndex = null
|
||||
this._musicSearchRequestObj = httpGet(`http://search.kuwo.cn/r.s?client=kt&all=${encodeURIComponent(str)}&pn=${page - 1}&rn=${this.limit}&uid=794762570&ver=kwplayer_ar_9.2.2.1&vipver=1&show_copyright_off=1&newver=1&ft=music&cluster=0&strategy=2012&encoding=utf8&rformat=json&vermerge=1&mobi=1&issubtitle=1`, (err, resp, body) => {
|
||||
this._musicSearchRequestObj = null
|
||||
this._musicSearchPromiseCancelFn = null
|
||||
if (err) {
|
||||
console.log(err)
|
||||
|
||||
@@ -5,17 +5,17 @@ export default {
|
||||
regExps: {
|
||||
relWord: /RELWORD=(.+)/,
|
||||
},
|
||||
_musicTempSearchIndex: null,
|
||||
_musicTempSearchRequestObj: null,
|
||||
_musicTempSearchPromiseCancelFn: null,
|
||||
tempSearch(str) {
|
||||
if (this._musicTempSearchIndex != null) {
|
||||
cancelHttp(this._musicTempSearchIndex)
|
||||
if (this._musicTempSearchRequestObj != null) {
|
||||
cancelHttp(this._musicTempSearchRequestObj)
|
||||
this._musicTempSearchPromiseCancelFn(new Error('取消http请求'))
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this._musicTempSearchPromiseCancelFn = reject
|
||||
this._musicTempSearchIndex = httpGet(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`, (err, resp, body) => {
|
||||
this._musicTempSearchIndex = null
|
||||
this._musicTempSearchRequestObj = httpGet(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`, (err, resp, body) => {
|
||||
this._musicTempSearchRequestObj = null
|
||||
this._musicTempSearchPromiseCancelFn = null
|
||||
if (err) {
|
||||
console.log(err)
|
||||
@@ -32,8 +32,8 @@ export default {
|
||||
})
|
||||
},
|
||||
cancelTempSearch() {
|
||||
if (this._musicTempSearchIndex != null) {
|
||||
cancelHttp(this._musicTempSearchIndex)
|
||||
if (this._musicTempSearchRequestObj != null) {
|
||||
cancelHttp(this._musicTempSearchRequestObj)
|
||||
this._musicTempSearchPromiseCancelFn(new Error('取消http请求'))
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user