Skip to content

Commit 976be6d

Browse files
committed
修复因kw源歌词接口停用导致该源歌词获取失败的问题
1 parent fe95b45 commit 976be6d

5 files changed

Lines changed: 64 additions & 5 deletions

File tree

publish/changeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
- 修复设置-控制按钮位置选项与下载歌词编码格式选项命名冲突导致选项显示异常的问题
44
- 修复播放下载列表时存在失效的歌曲会导致切歌不准确的问题
55
- 修复潜在的音乐加载超时不会切歌的问题
6+
- 修复因kw源歌词接口停用导致该源歌词获取失败的问题

src/common/ipcNames.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const names = {
3535

3636
lang_s2t: 'lang_s2t',
3737

38-
handle_kw_decode_lyric: 'handle_kw_decode_lyric',
38+
// handle_kw_decode_lyric: 'handle_kw_decode_lyric',
3939
get_lyric_info: 'get_lyric_info',
4040
set_lyric_info: 'set_lyric_info',
4141
set_config: 'set_config',

src/main/rendererEvents/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require('./lyric')
2121
require('./musicUrl')
2222
require('./systemFonts')
2323

24-
require('./kw_decodeLyric')
24+
// require('./kw_decodeLyric')
2525

2626
require('./userApi')
2727
require('./sync')

src/renderer/utils/music/kw/lyric.js

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,63 @@
11
import { httpFetch } from '../../request'
2-
import { decodeLyric } from './util'
2+
import { decodeName } from '../../index'
33

44
export default {
5+
formatTime(time) {
6+
let m = parseInt(time / 60)
7+
let s = (time % 60).toFixed(2)
8+
return (m < 10 ? '0' + m : m) + ':' + (s < 10 ? '0' + s : s)
9+
},
10+
sortLrcArr(arr) {
11+
const lrcSet = new Set()
12+
let lrc = []
13+
let lrcT = []
14+
15+
for (const item of arr) {
16+
if (lrcSet.has(item.time)) {
17+
lrc.push(item)
18+
} else {
19+
lrcT.push(item)
20+
lrcSet.add(item.time)
21+
}
22+
}
23+
if (lrc.length) {
24+
lrc.unshift(lrcT.shift())
25+
} else {
26+
lrc = lrcT
27+
lrcT = []
28+
}
29+
30+
return {
31+
lrc,
32+
lrcT,
33+
}
34+
},
35+
transformLrc(songinfo, lrclist) {
36+
return `[ti:${songinfo.songName}]\n[ar:${songinfo.artist}]\n[al:${songinfo.album}]\n[by:]\n[offset:0]\n${lrclist ? lrclist.map(l => `[${this.formatTime(l.time)}]${l.lineLyric}\n`).join('') : '暂无歌词'}`
37+
},
38+
getLyric(songId) {
39+
const requestObj = httpFetch(`http://m.kuwo.cn/newh5/singles/songinfoandlrc?musicId=${songId}`)
40+
requestObj.promise = requestObj.promise.then(({ body }) => {
41+
// console.log(body)
42+
if (!body.data?.lrclist?.length) return Promise.reject(new Error('Get lyric failed'))
43+
const { lrc, lrcT } = this.sortLrcArr(body.data.lrclist)
44+
// console.log(body.data.lrclist)
45+
// console.log(lrc, lrcT)
46+
// console.log({
47+
// lyric: decodeName(this.transformLrc(body.data.songinfo, lrc)),
48+
// tlyric: decodeName(this.transformLrc(body.data.songinfo, lrcT)),
49+
// })
50+
return {
51+
lyric: decodeName(this.transformLrc(body.data.songinfo, lrc)),
52+
tlyric: lrcT.length ? decodeName(this.transformLrc(body.data.songinfo, lrcT)) : '',
53+
}
54+
})
55+
return requestObj
56+
},
57+
}
58+
59+
60+
/* export default {
561
lrcInfoRxp: /<lyric>(.+?)<\/lyric>[\s\S]+<lyric_zz>(.+?)<\/lyric_zz>/,
662
parseLyricInfo(str) {
763
let result = str.match(this.lrcInfoRxp)
@@ -10,6 +66,7 @@ export default {
1066
getLyric(songId, isGetLyricx = false) {
1167
const requestObj = httpFetch(`http://player.kuwo.cn/webmusic/st/getNewMuiseByRid?rid=MUSIC_${songId}`)
1268
requestObj.promise = requestObj.promise.then(({ statusCode, body }) => {
69+
console.log(body)
1370
if (statusCode != 200) return Promise.reject(new Error(JSON.stringify(body)))
1471
let info = this.parseLyricInfo(body)
1572
if (!info) return Promise.reject(new Error(JSON.stringify(body)))
@@ -27,3 +84,4 @@ export default {
2784
return requestObj
2885
},
2986
}
87+
*/

src/renderer/utils/music/kw/util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { httpGet, httpFetch } from '../../request'
2-
import { rendererInvoke, NAMES } from '../../../../common/ipc'
2+
// import { rendererInvoke, NAMES } from '../../../../common/ipc'
33

44
const kw_token = {
55
token: null,
@@ -54,7 +54,7 @@ export const getToken = (retryNum = 0) => new Promise((resolve, reject) => {
5454
})
5555
})
5656

57-
export const decodeLyric = base64Data => rendererInvoke(NAMES.mainWindow.handle_kw_decode_lyric, base64Data)
57+
// export const decodeLyric = base64Data => rendererInvoke(NAMES.mainWindow.handle_kw_decode_lyric, base64Data)
5858

5959
export const tokenRequest = async(url, options = {}) => {
6060
let token = kw_token.token

0 commit comments

Comments
 (0)