修复kw搜索联想词 (#1452)
* 修复kw搜索联想词 * 完善 --------- Co-authored-by: lyswhut <lyswhut@qq.com>pull/1460/head
parent
e8d8feb042
commit
6423066cb2
|
@ -1,4 +1,4 @@
|
||||||
### 修复
|
### 修复
|
||||||
|
|
||||||
- 修复字体设置某些字体无法应用的问题
|
- 修复字体设置某些字体无法应用的问题
|
||||||
|
- 修复搜索提示功能失效的问题(#1452, @Folltoshe)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
import tipSearch from './tipSearch'
|
import tipSearch from './tipSearch'
|
||||||
import musicSearch from './musicSearch'
|
import musicSearch from './musicSearch'
|
||||||
import { formatSinger, getToken } from './util'
|
import { formatSinger } from './util'
|
||||||
import leaderboard from './leaderboard'
|
import leaderboard from './leaderboard'
|
||||||
import lyric from './lyric'
|
import lyric from './lyric'
|
||||||
import pic from './pic'
|
import pic from './pic'
|
||||||
|
@ -94,9 +94,9 @@ const kw = {
|
||||||
return `http://www.kuwo.cn/play_detail/${songInfo.songmid}`
|
return `http://www.kuwo.cn/play_detail/${songInfo.songmid}`
|
||||||
},
|
},
|
||||||
|
|
||||||
init() {
|
// init() {
|
||||||
return getToken()
|
// return getToken()
|
||||||
},
|
// },
|
||||||
}
|
}
|
||||||
|
|
||||||
export default kw
|
export default kw
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { decodeName } from '../../index'
|
// import { decodeName } from '../../index'
|
||||||
import { tokenRequest } from './util'
|
// import { tokenRequest } from './util'
|
||||||
|
import { httpFetch } from '../../request'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
regExps: {
|
regExps: {
|
||||||
|
@ -7,24 +8,25 @@ export default {
|
||||||
},
|
},
|
||||||
requestObj: null,
|
requestObj: null,
|
||||||
async tipSearchBySong(str) {
|
async tipSearchBySong(str) {
|
||||||
|
// 报错403,加了referer还是有问题(直接换一个
|
||||||
|
// this.requestObj = await tokenRequest(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`)
|
||||||
|
|
||||||
this.cancelTipSearch()
|
this.cancelTipSearch()
|
||||||
this.requestObj = await tokenRequest(`http://www.kuwo.cn/api/www/search/searchKey?key=${encodeURIComponent(str)}`)
|
this.requestObj = httpFetch(`https://tips.kuwo.cn/t.s?corp=kuwo&newver=3&p2p=1¬race=0&c=mbox&w=${encodeURIComponent(str)}&encoding=utf8&rformat=json`, {
|
||||||
return this.requestObj.promise.then(({ body }) => {
|
Referer: 'http://www.kuwo.cn/',
|
||||||
// console.log(body)
|
})
|
||||||
if (body.code !== 200) return Promise.reject(new Error('请求失败'))
|
return this.requestObj.promise.then(({ body, statusCode }) => {
|
||||||
return body
|
if (statusCode != 200 || !body.WORDITEMS) return Promise.reject(new Error('请求失败'))
|
||||||
|
return body.WORDITEMS
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
handleResult(rawData) {
|
handleResult(rawData) {
|
||||||
return rawData.map(info => {
|
return rawData.map(item => item.RELWORD)
|
||||||
let matchResult = info.match(this.regExps.relWord)
|
|
||||||
return matchResult ? decodeName(matchResult[1]) : ''
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
cancelTipSearch() {
|
cancelTipSearch() {
|
||||||
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
if (this.requestObj && this.requestObj.cancelHttp) this.requestObj.cancelHttp()
|
||||||
},
|
},
|
||||||
async search(str) {
|
async search(str) {
|
||||||
return this.tipSearchBySong(str).then(result => this.handleResult(result.data))
|
return this.tipSearchBySong(str).then(result => this.handleResult(result))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { httpGet, httpFetch } from '../../request'
|
// import { httpGet, httpFetch } from '../../request'
|
||||||
import { WIN_MAIN_RENDERER_EVENT_NAME } from '@common/ipcNames'
|
import { WIN_MAIN_RENDERER_EVENT_NAME } from '@common/ipcNames'
|
||||||
import { rendererInvoke } from '@common/rendererIpc'
|
import { rendererInvoke } from '@common/rendererIpc'
|
||||||
|
|
||||||
const kw_token = {
|
// const kw_token = {
|
||||||
token: null,
|
// token: null,
|
||||||
isGetingToken: false,
|
// isGetingToken: false,
|
||||||
}
|
// }
|
||||||
|
|
||||||
// const translationMap = {
|
// const translationMap = {
|
||||||
// "{'": '{"',
|
// "{'": '{"',
|
||||||
|
@ -43,46 +43,46 @@ export const matchToken = headers => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const wait = time => new Promise(resolve => setTimeout(() => resolve(), time))
|
// const wait = time => new Promise(resolve => setTimeout(() => resolve(), time))
|
||||||
|
|
||||||
|
|
||||||
export const getToken = (retryNum = 0) => new Promise((resolve, reject) => {
|
// export const getToken = (retryNum = 0) => new Promise((resolve, reject) => {
|
||||||
if (retryNum > 2) return Promise.reject(new Error('try max num'))
|
// if (retryNum > 2) return Promise.reject(new Error('try max num'))
|
||||||
|
|
||||||
if (kw_token.isGetingToken) return wait(1000).then(() => getToken(retryNum).then(token => resolve(token)))
|
// if (kw_token.isGetingToken) return wait(1000).then(() => getToken(retryNum).then(token => resolve(token)))
|
||||||
if (kw_token.token) return resolve(kw_token.token)
|
// if (kw_token.token) return resolve(kw_token.token)
|
||||||
kw_token.isGetingToken = true
|
// kw_token.isGetingToken = true
|
||||||
httpGet('http://www.kuwo.cn/', (err, resp) => {
|
// httpGet('http://www.kuwo.cn/', (err, resp) => {
|
||||||
kw_token.isGetingToken = false
|
// kw_token.isGetingToken = false
|
||||||
if (err) return getToken(++retryNum)
|
// if (err) return getToken(++retryNum)
|
||||||
if (resp.statusCode != 200) return reject(new Error('获取失败'))
|
// if (resp.statusCode != 200) return reject(new Error('获取失败'))
|
||||||
const token = kw_token.token = matchToken(resp.headers)
|
// const token = kw_token.token = matchToken(resp.headers)
|
||||||
resolve(token)
|
// resolve(token)
|
||||||
})
|
// })
|
||||||
})
|
// })
|
||||||
|
|
||||||
export const decodeLyric = base64Data => rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.handle_kw_decode_lyric, base64Data)
|
export const decodeLyric = base64Data => rendererInvoke(WIN_MAIN_RENDERER_EVENT_NAME.handle_kw_decode_lyric, base64Data)
|
||||||
|
|
||||||
export const tokenRequest = async(url, options = {}) => {
|
// export const tokenRequest = async(url, options = {}) => {
|
||||||
let token = kw_token.token
|
// let token = kw_token.token
|
||||||
if (!token) token = await getToken()
|
// if (!token) token = await getToken()
|
||||||
if (!options.headers) {
|
// if (!options.headers) {
|
||||||
options.headers = {
|
// options.headers = {
|
||||||
Referer: 'http://www.kuwo.cn/',
|
// Referer: 'http://www.kuwo.cn/',
|
||||||
csrf: token,
|
// csrf: token,
|
||||||
cookie: 'kw_token=' + token,
|
// cookie: 'kw_token=' + token,
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
const requestObj = httpFetch(url, options)
|
// const requestObj = httpFetch(url, options)
|
||||||
requestObj.promise = requestObj.promise.then(resp => {
|
// requestObj.promise = requestObj.promise.then(resp => {
|
||||||
// console.log(resp)
|
// // console.log(resp)
|
||||||
if (resp.statusCode == 200) {
|
// if (resp.statusCode == 200) {
|
||||||
kw_token.token = matchToken(resp.headers)
|
// kw_token.token = matchToken(resp.headers)
|
||||||
}
|
// }
|
||||||
return resp
|
// return resp
|
||||||
})
|
// })
|
||||||
return requestObj
|
// return requestObj
|
||||||
}
|
// }
|
||||||
|
|
||||||
export const lrcTools = {
|
export const lrcTools = {
|
||||||
rxps: {
|
rxps: {
|
||||||
|
|
Loading…
Reference in New Issue