lyswhut/lx-music-desktop · error · Error
获取评论失败
Error message
获取评论失败
What it means
Kugou (kg) newest-comment fetcher in kg/comment.js:25. It builds signed params (signatureParams) with hardcoded mid/dfid/appid/code, fetches m.comment.service.kugou.com /v1/rank/newest with an Edge Chrome UA, and requires HTTP 200 AND body.err_code === 0; otherwise throws '获取评论失败' (failed to fetch comments).
Source
Thrown at src/renderer/utils/musicSdk/kg/comment.js:25
_requestObj: null,
_requestObj2: null,
async getComment({ hash }, page = 1, limit = 20) {
if (this._requestObj) this._requestObj.cancelHttp()
// const res_id = (await getMusicInfoRaw(hash)).classification?.[0]?.res_id
// if (!res_id) throw new Error('获取评论失败')
let timestamp = Date.now()
const params = `dfid=0&mid=16249512204336365674023395779019&clienttime=${timestamp}&uuid=0&extdata=${hash}&appid=1005&code=fc4be23b4e972707f36b8a828a93ba8a&schash=${hash}&clientver=11409&p=${page}&clienttoken=&pagesize=${limit}&ver=10&kugouid=0`
// const params = `appid=1005&clienttime=${timestamp}&clienttoken=0&clientver=11409&code=fc4be23b4e972707f36b8a828a93ba8a&dfid=0&extdata=${hash}&kugouid=0&mid=16249512204336365674023395779019&mixsongid=${res_id}&p=${page}&pagesize=${limit}&uuid=0&ver=10`
const _requestObj = httpFetch(`http://m.comment.service.kugou.com/r/v1/rank/newest?${params}&signature=${signatureParams(params)}`, {
headers: {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.24',
},
})
const { body, statusCode } = await _requestObj.promise
// console.log(body)
if (statusCode != 200 || body.err_code !== 0) throw new Error('获取评论失败')
const total = body.count ?? 0
return { source: 'kg', comments: this.filterComment(body.list || []), total, page, limit, maxPage: Math.ceil(total / limit) || 1 }
},
async getHotComment({ hash }, page = 1, limit = 20) {
// console.log(songmid)
if (this._requestObj2) this._requestObj2.cancelHttp()
let timestamp = Date.now()
const params = `dfid=0&mid=16249512204336365674023395779019&clienttime=${timestamp}&uuid=0&extdata=${hash}&appid=1005&code=fc4be23b4e972707f36b8a828a93ba8a&schash=${hash}&clientver=11409&p=${page}&clienttoken=&pagesize=${limit}&ver=10&kugouid=0`
// https://github.com/GitHub-ZC/wp_MusicApi/blob/bf9307dd138dc8ac6c4f7de29361209d4f5b665f/routes/v1/kugou/comment.js#L53
const _requestObj2 = httpFetch(`http://m.comment.service.kugou.com/r/v1/rank/topliked?${params}&signature=${signatureParams(params)}`, {
headers: {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.24',
},
})
const { body, statusCode } = await _requestObj2.promise
// console.log(body)
if (statusCode != 200 || body.err_code !== 0) throw new Error('获取热门评论失败')
const total = body.count ?? 0View on GitHub (pinned to 9c364b482e)
Solutions
- Confirm signatureParams still produces a signature Kugou accepts (regenerate the algorithm if needed).
- Verify the hardcoded mid/dfid/appid/code constants haven't been deprecated.
- Retry with backoff for transient non-zero err_codes (e.g. rate-limit sentinels).
- Catch at the UI layer and render an empty comment state with a retry affordance.
Example fix
// before
if (statusCode != 200 || body.err_code !== 0) throw new Error('获取评论失败')
// after - include status and err_code for diagnosis
if (statusCode != 200 || body.err_code !== 0) {
throw new Error(`获取评论失败 (status=${statusCode}, err_code=${body?.err_code})`)
} Defensive patterns
Strategy: retry
Validate before calling
// validate response shape before treating err_code as authoritative const isKgCommentSuccess = (body) => body != null && typeof body === 'object' && typeof body.err_code === 'number'
Type guard
const isKgCommentSuccess = (body) => body != null && typeof body === 'object' && body.err_code === 0
Try / catch
async function loadKgComments(hash, page, limit) {
try {
return await kgComment.getComment({ hash }, page, limit)
} catch (e) {
// transient? retry once with backoff; otherwise degrade
return { source: 'kg', comments: [], total: 0, page, limit, maxPage: 1, error: e.message }
}
} Prevention
- Keep signatureParams aligned with Kugou's current signing algorithm.
- Rotate/verify the hardcoded mid, dfid, appid, and code constants if Kugou revokes them.
- Distinguish rate-limit err_codes from hard failures and retry the former with backoff.
When it happens
Trigger: A non-200 response, err_code != 0, an expired/invalid signature, the hardcoded UA or mid being blocked, or the comment service moving its response shape. Triggered when the user opens the comments tab for a kg song.
Common situations: The signature algorithm changed so signatureParams no longer validates; the static mid (16249...) or code (fc4be23b...) was revoked by Kugou; rate-limiting returns a non-zero err_code; network failure.
Related errors
AI-assisted analysis of lyswhut/lx-music-desktop@9c364b482e (2026-08-12).
Data as JSON: /api/errors/5f81d5a70fd7fba6.
Report an issue: GitHub.