更换kw歌词获取方式
parent
2913c0c7de
commit
1fd3e6c9fa
|
@ -26,7 +26,7 @@ require('./nativeTheme')
|
||||||
|
|
||||||
if (isWin) require('./taskbar')
|
if (isWin) require('./taskbar')
|
||||||
|
|
||||||
// require('./kw_decodeLyric')
|
require('./kw_decodeLyric')
|
||||||
|
|
||||||
require('./userApi')
|
require('./userApi')
|
||||||
require('./sync')
|
require('./sync')
|
||||||
|
|
|
@ -40,7 +40,7 @@ const kw = {
|
||||||
comment,
|
comment,
|
||||||
getLyric(songInfo, isGetLyricx) {
|
getLyric(songInfo, isGetLyricx) {
|
||||||
// let singer = songInfo.singer.indexOf('、') > -1 ? songInfo.singer.split('、')[0] : songInfo.singer
|
// let singer = songInfo.singer.indexOf('、') > -1 ? songInfo.singer.split('、')[0] : songInfo.singer
|
||||||
return lyric.getLyric(songInfo.songmid, isGetLyricx)
|
return lyric.getLyric(songInfo, isGetLyricx)
|
||||||
},
|
},
|
||||||
handleMusicInfo(songInfo) {
|
handleMusicInfo(songInfo) {
|
||||||
return this.getMusicInfo(songInfo).then(info => {
|
return this.getMusicInfo(songInfo).then(info => {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import { httpFetch } from '../../request'
|
import { httpFetch } from '../../request'
|
||||||
|
import { decodeLyric } from './util'
|
||||||
import { decodeName } from '../../index'
|
import { decodeName } from '../../index'
|
||||||
|
|
||||||
|
/*
|
||||||
export default {
|
export default {
|
||||||
formatTime(time) {
|
formatTime(time) {
|
||||||
let m = parseInt(time / 60)
|
let m = parseInt(time / 60)
|
||||||
|
@ -63,33 +65,99 @@ export default {
|
||||||
return requestObj
|
return requestObj
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
const buf_key = Buffer.from('yeelion')
|
||||||
|
const buf_key_len = buf_key.length
|
||||||
|
const buildParams = (id, isGetLyricx) => {
|
||||||
|
let params = `user=12345,web,web,web&requester=localhost&req=1&rid=MUSIC_${id}`
|
||||||
|
if (isGetLyricx) params += '&lrcx=1'
|
||||||
|
const buf_str = Buffer.from(params)
|
||||||
|
const buf_str_len = buf_str.length
|
||||||
|
const output = new Uint16Array(buf_str_len)
|
||||||
|
let i = 0
|
||||||
|
while (i < buf_str_len) {
|
||||||
|
let j = 0
|
||||||
|
while (j < buf_key_len && i < buf_str_len) {
|
||||||
|
output[i] = buf_key[j] ^ buf_str[i]
|
||||||
|
i++
|
||||||
|
j++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Buffer.from(output).toString('base64')
|
||||||
|
}
|
||||||
|
|
||||||
/* export default {
|
// console.log(buildParams('207527604', false))
|
||||||
lrcInfoRxp: /<lyric>(.+?)<\/lyric>[\s\S]+<lyric_zz>(.+?)<\/lyric_zz>/,
|
// console.log(buildParams('207527604', true))
|
||||||
parseLyricInfo(str) {
|
|
||||||
let result = str.match(this.lrcInfoRxp)
|
const timeExp = /^\[([\d:.]*)\]{1}/g
|
||||||
return result ? { lyric: result[1], lyric_zz: result[2] } : null
|
export default {
|
||||||
|
sortLrcArr(arr) {
|
||||||
|
const lrcSet = new Set()
|
||||||
|
let lrc = []
|
||||||
|
let lrcT = []
|
||||||
|
|
||||||
|
for (const item of arr) {
|
||||||
|
if (lrcSet.has(item.time)) {
|
||||||
|
const tItem = lrc.pop()
|
||||||
|
tItem.time = lrc[lrc.length - 1].time
|
||||||
|
lrcT.push(tItem)
|
||||||
|
lrc.push(item)
|
||||||
|
} else {
|
||||||
|
lrc.push(item)
|
||||||
|
lrcSet.add(item.time)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lrcT.length && lrc.length > lrcT.length) {
|
||||||
|
const tItem = lrc.pop()
|
||||||
|
tItem.time = lrc[lrc.length - 1].time
|
||||||
|
lrcT.push(tItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
lrc,
|
||||||
|
lrcT,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
getLyric(songId, isGetLyricx = false) {
|
transformLrc(songinfo, lrclist) {
|
||||||
const requestObj = httpFetch(`http://player.kuwo.cn/webmusic/st/getNewMuiseByRid?rid=MUSIC_${songId}`)
|
return `[ti:${songinfo.name ?? ''}]\n[ar:${songinfo.singer ?? ''}]\n[al:${songinfo.albumName ?? ''}]\n[by:]\n[offset:0]\n${lrclist ? lrclist.map(l => `[${l.time}]${l.text}\n`).join('') : '暂无歌词'}`
|
||||||
requestObj.promise = requestObj.promise.then(({ statusCode, body }) => {
|
},
|
||||||
console.log(body)
|
parseLrc(musicInfo, lrc) {
|
||||||
if (statusCode != 200) return Promise.reject(new Error(JSON.stringify(body)))
|
const lines = lrc.split(/\r\n|\r|\n/)
|
||||||
let info = this.parseLyricInfo(body)
|
let lrcArr = []
|
||||||
if (!info) return Promise.reject(new Error(JSON.stringify(body)))
|
for (let i = 0; i < lines.length; i++) {
|
||||||
Object.assign(requestObj, httpFetch(`http://newlyric.kuwo.cn/newlyric.lrc?${isGetLyricx ? info.lyric_zz : info.lyric}`))
|
const line = lines[i].trim()
|
||||||
return requestObj.promise.then(({ statusCode, body, raw }) => {
|
let result = timeExp.exec(line)
|
||||||
|
if (result) {
|
||||||
|
const text = line.replace(timeExp, '').trim()
|
||||||
|
lrcArr.push({
|
||||||
|
time: RegExp.$1,
|
||||||
|
text,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const lrcInfo = this.sortLrcArr(lrcArr)
|
||||||
|
return {
|
||||||
|
lyric: decodeName(this.transformLrc(musicInfo, lrcInfo.lrc)),
|
||||||
|
tlyric: lrcInfo.lrcT.length ? decodeName(this.transformLrc(musicInfo, lrcInfo.lrcT)) : '',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getLyric(musicInfo, isGetLyricx = false) {
|
||||||
|
const requestObj = httpFetch(`http://newlyric.kuwo.cn/newlyric.lrc?${buildParams(musicInfo.songmid, isGetLyricx)}`)
|
||||||
|
requestObj.promise = requestObj.promise.then(({ statusCode, body, raw }) => {
|
||||||
if (statusCode != 200) return Promise.reject(new Error(JSON.stringify(body)))
|
if (statusCode != 200) return Promise.reject(new Error(JSON.stringify(body)))
|
||||||
return decodeLyric({ lrcBase64: raw.toString('base64'), isGetLyricx }).then(base64Data => {
|
return decodeLyric({ lrcBase64: raw.toString('base64'), isGetLyricx }).then(base64Data => {
|
||||||
return {
|
let lrcInfo
|
||||||
lyric: Buffer.from(base64Data, 'base64').toString(),
|
try {
|
||||||
tlyric: '',
|
lrcInfo = this.parseLrc(musicInfo, Buffer.from(base64Data, 'base64').toString())
|
||||||
|
} catch {
|
||||||
|
return Promise.reject(new Error('Get lyric failed'))
|
||||||
}
|
}
|
||||||
})
|
// console.log(lrcInfo)
|
||||||
|
return lrcInfo
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return requestObj
|
return requestObj
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { httpGet, httpFetch } from '../../request'
|
import { httpGet, httpFetch } from '../../request'
|
||||||
// import { rendererInvoke, NAMES } from '../../../../common/ipc'
|
import { rendererInvoke, NAMES } from '@common/ipc'
|
||||||
|
|
||||||
const kw_token = {
|
const kw_token = {
|
||||||
token: null,
|
token: null,
|
||||||
|
@ -54,7 +54,7 @@ export const getToken = (retryNum = 0) => new Promise((resolve, reject) => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// export const decodeLyric = base64Data => rendererInvoke(NAMES.mainWindow.handle_kw_decode_lyric, base64Data)
|
export const decodeLyric = base64Data => rendererInvoke(NAMES.mainWindow.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
|
||||||
|
|
Loading…
Reference in New Issue