新增:直接播放QQ音乐排行榜音乐

This commit is contained in:
lyswhut
2019-08-17 02:22:43 +08:00
parent 43bc2b6b90
commit bccadcf13d
21 changed files with 241 additions and 108 deletions
+3 -2
View File
@@ -98,6 +98,8 @@ export default {
watch: {
changePlay(n) {
if (!n) return
// console.log('changePlay')
this.handleRemoveMusic()
this.resetChangePlay()
if (this.playIndex < 0) return
this.stopPlay()
@@ -112,7 +114,7 @@ export default {
? n.findIndex(s => s.musicInfo.songmid === this.musicInfo.songmid)
: n.findIndex(s => s.songmid === this.musicInfo.songmid)
if (index < 0) {
this.handleRemoveMusic()
this.fixPlayIndex(this.playIndex - 1)
if (n.length) this.handleNext()
} else {
this.fixPlayIndex(index)
@@ -362,7 +364,6 @@ export default {
this.musicInfo.url = null
this.nowPlayTime = 0
this.maxPlayTime = 0
this.fixPlayIndex(this.playIndex - 1)
},
sendProgressEvent(status, mode) {
// console.log(status)
+1 -1
View File
@@ -41,7 +41,7 @@ const getExt = type => {
const checkList = (list, musicInfo, type) => list.some(s => s.musicInfo.songmid === musicInfo.songmid && s.type === type)
const refreshUrl = downloadInfo => {
return music[downloadInfo.musicInfo.source].getMusicUrl(downloadInfo.musicInfo, downloadInfo.type)
return music[downloadInfo.musicInfo.source].getMusicUrl(downloadInfo.musicInfo, downloadInfo.type).promise
}
// actions
+8 -1
View File
@@ -19,7 +19,14 @@ const getters = {
// actions
const actions = {
getUrl({ commit, state }, { musicInfo, type }) {
return music[musicInfo.source].getMusicUrl(musicInfo, type).then(result => commit('setUrl', { musicInfo, url: result.url, type }))
if (state.cancelFn) state.cancelFn()
const { promise, cancelHttp } = music[musicInfo.source].getMusicUrl(musicInfo, type)
state.cancelFn = cancelHttp
return promise.then(result => {
return commit('setUrl', { musicInfo, url: result.url, type })
}).finally(() => {
state.cancelFn = null
})
},
getPic({ commit, state }, musicInfo) {
return music[musicInfo.source].getPic(musicInfo).then(url => commit('getPic', { musicInfo, url }))
+5 -5
View File
@@ -68,17 +68,17 @@ export default {
limit: /pagesize: '(\d+)',/,
listData: /global\.features = (\[.+\]);/,
},
_cancelIndex: null,
_requestObj: null,
_cancelPromiseCancelFn: null,
getData(url) {
if (this._cancelIndex != null) {
cancelHttp(this._cancelIndex)
if (this._requestObj != null) {
cancelHttp(this._requestObj)
this._cancelPromiseCancelFn(new Error('取消http请求'))
}
return new Promise((resolve, reject) => {
this._cancelPromiseCancelFn = reject
this._cancelIndex = httpGet(url, (err, resp, body) => {
this._cancelIndex = null
this._requestObj = httpGet(url, (err, resp, body) => {
this._requestObj = null
this._cancelPromiseCancelFn = null
if (err) {
console.log(err)
+33 -15
View File
@@ -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))
})
})
+10 -10
View File
@@ -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)
+5 -5
View File
@@ -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)
+5 -5
View File
@@ -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)
+7 -7
View File
@@ -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请求'))
}
},
+40
View File
@@ -1,7 +1,47 @@
import { httpGet, cancelHttp } from '../../request'
import leaderboard from './leaderboard'
import lyric from './lyric'
const tx = {
leaderboard,
getMusicUrl(songInfo, type) {
let requestObj
let cancelFn
const p = new Promise((resolve, reject) => {
cancelFn = reject
requestObj = httpGet(`https://v1.itooi.cn/tencent/url?id=${songInfo.strMediaMid}&quality=${type.replace(/k$/, '')}&isRedirect=0`, (err, resp, body) => {
requestObj = null
cancelFn = null
if (err) {
console.log(err)
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
},
getLyric(songInfo) {
// let singer = songInfo.singer.indexOf('、') > -1 ? songInfo.singer.split('、')[0] : songInfo.singer
return lyric.getLyric(songInfo.songmid)
},
getPic(songInfo) {
return Promise.resolve(`https://y.gtimg.cn/music/photo_new/T002R500x500M000${songInfo.albumId}.jpg`)
},
}
export default tx
+6 -6
View File
@@ -83,17 +83,17 @@ export default {
},
periods: {},
periodUrl: 'https://c.y.qq.com/node/pc/wk_v15/top.html',
_cancelIndex: null,
_cancelRequestObj: null,
_cancelPromiseCancelFn: 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)
@@ -143,7 +143,7 @@ export default {
size,
}
}
types.reverse()
// types.reverse()
return {
singer: this.getSinger(item.singer),
name: item.title,
+32
View File
@@ -0,0 +1,32 @@
import { httpGet, cancelHttp } from '../../request'
import { b64DecodeUnicode } from '../../index'
export default {
_musicLrcRequestObj: null,
_musicLrcPromiseCancelFn: null,
regexps: {
matchLrc: /.+"lyric":"([\w=+/]*)".+/,
},
getLyric(songmid) {
if (this._musicLrcRequestObj != null) {
cancelHttp(this._musicLrcRequestObj)
this._musicLrcPromiseCancelFn(new Error('取消http请求'))
}
return new Promise((resolve, reject) => {
this._musicLrcPromiseCancelFn = reject
this._musicLrcRequestObj = httpGet(`https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg?songmid=${songmid}&g_tk=2001461048&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8&platform=yqq`, {
headers: {
Referer: 'https://y.qq.com/portal/player.html',
},
}, (err, resp, body) => {
this._musicLrcRequestObj = null
this._musicLrcPromiseCancelFn = null
if (err) {
console.log(err)
reject(err)
}
resolve(b64DecodeUnicode(body.replace(this.regexps.matchLrc, '$1')))
})
})
},
}
+5 -5
View File
@@ -61,17 +61,17 @@ export default {
regExps: {
list: /<textarea id="song-list-pre-data" style="display:none;">(.+?)<\/textarea>/,
},
_cancelIndex: null,
_cancelRequestObj: null,
_cancelPromiseCancelFn: 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)
+14 -35
View File
@@ -3,46 +3,25 @@ import request from 'request'
import { debugRequest } from './env'
// import fs from 'fs'
const tasks = []
const fatchData = (url, method, options, callback) => {
let index = pushTask(tasks, request(url, {
method,
headers: options.headers,
Origin: options.origin,
data: options.data,
json: options.format === undefined || options.format === 'json',
}, (err, resp, body) => {
tasks[index] = null
if (err) return callback(err, null)
callback(null, resp, body)
}))
return index
}
const fatchData = (url, method, options, callback) => request(url, {
method,
headers: options.headers,
Origin: options.origin,
data: options.data,
json: options.format === undefined || options.format === 'json',
}, (err, resp, body) => {
if (err) return callback(err, null)
callback(null, resp, body)
})
/**
* 取消请求
* @param {*} index
*/
export const cancelHttp = index => {
if (index == null) return
console.log('cancel: ', index)
let r = tasks[index]
if (r == null) return
r.abort()
tasks[index] = null
}
const pushTask = (tasks, newTask) => {
for (const [index, task] of tasks.entries()) {
if (task == null) {
tasks[index] = newTask
return index
}
}
tasks.push(newTask)
return tasks.length - 1
export const cancelHttp = requestObj => {
if (!requestObj) return
console.log('cancel:', requestObj.href)
requestObj.abort()
}
+2 -2
View File
@@ -25,7 +25,7 @@
td.break(style="width: 20%;") {{item.singer}}
td.break(style="width: 25%;") {{item.albumName}}
td(style="width: 18%;")
material-list-buttons(:index="index" :search-btn="true" :play-btn="item.source == 'kw'" :download-btn="item.source == 'kw'" :remove-btn="false" @btn-click="handleBtnClick")
material-list-buttons(:index="index" :search-btn="true" :play-btn="item.source == 'kw' || item.source == 'tx'" :download-btn="item.source == 'kw' || item.source == 'tx'" :remove-btn="false" @btn-click="handleBtnClick")
//- button.btn-info(type='button' v-if="item._types['128k'] || item._types['192k'] || item._types['320k'] || item._types.flac" @click.stop='openDownloadModal(index)') 下载
//- button.btn-secondary(type='button' v-if="item._types['128k'] || item._types['192k'] || item._types['320k']" @click.stop='testPlay(index)') 试听
//- button.btn-success(type='button' v-if="(item._types['128k'] || item._types['192k'] || item._types['320k']) && userInfo" @click.stop='showListModal(index)') +
@@ -94,7 +94,7 @@ export default {
this.clickIndex = index
return
}
this.source == 'kw' ? this.testPlay(index) : this.handleSearch(index)
(this.source == 'kw' || this.source == 'tx') ? this.testPlay(index) : this.handleSearch(index)
this.clickTime = 0
this.clickIndex = -1
},