From 94f07e306e4896e4b866aea31ba5cf073b79fca2 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Fri, 21 Jul 2023 12:33:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=85=B7=E6=88=91=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E5=8C=BA=E5=B8=A6=E5=9B=BE=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/musicSdk/kw/comment.js | 67 ++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/src/utils/musicSdk/kw/comment.js b/src/utils/musicSdk/kw/comment.js index 0559d68..72910e1 100644 --- a/src/utils/musicSdk/kw/comment.js +++ b/src/utils/musicSdk/kw/comment.js @@ -7,57 +7,76 @@ export default { async getComment({ songmid }, page = 1, limit = 20) { if (this._requestObj) this._requestObj.cancelHttp() - const _requestObj = httpFetch(`http://comment.kuwo.cn/com.s?type=get_comment&uid=0&digest=15&sid=${songmid}&page=${page}&rows=${limit}&f=web&prod=MUSIC_8.7.7.0_BCS37&devid=28556413`, { + const _requestObj = httpFetch(`http://ncomment.kuwo.cn/com.s?f=web&type=get_comment&aapiver=1&prod=kwplayer_ar_10.5.2.0&digest=15&sid=${songmid}&start=${limit * (page - 1)}&msgflag=1&count=${limit}&newver=3&uid=0`, { headers: { 'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9;)', }, }) const { body, statusCode } = await _requestObj.promise - if (statusCode != 200 || body.result !== 'ok') throw new Error('获取评论失败') + if (statusCode != 200 || body.code != '200') throw new Error('获取评论失败') // console.log(body) - return { source: 'kw', comments: this.filterComment(body.rows), total: body.total, page, limit, maxPage: Math.ceil(body.total / limit) || 1 } + + const total = body.comments_counts + return { + source: 'kw', + comments: this.filterComment(body.comments), + total, + page, + limit, + maxPage: Math.ceil(total / limit) || 1, + } }, async getHotComment({ songmid }, page = 1, limit = 100) { if (this._requestObj2) this._requestObj2.cancelHttp() - const _requestObj2 = httpFetch(`http://comment.kuwo.cn/com.s?type=get_rec_comment&uid=0&digest=15&sid=${songmid}&page=${page}&rows=${limit}&f=web&prod=MUSIC_8.7.7.0_BCS37&devid=28556413`, { + const _requestObj2 = httpFetch(`http://ncomment.kuwo.cn/com.s?f=web&type=get_rec_comment&aapiver=1&prod=kwplayer_ar_10.5.2.0&digest=15&sid=${songmid}&start=${limit * (page - 1)}&msgflag=1&count=${limit}&newver=3&uid=0`, { headers: { 'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9;)', }, }) const { body, statusCode } = await _requestObj2.promise - if (statusCode != 200 || body.result !== 'ok') throw new Error('获取热门评论失败') + if (statusCode != 200 || body.code != '200') throw new Error('获取热门评论失败') // console.log(body) - return { source: 'kw', comments: this.filterComment(body.rows), total: body.total, page, limit, maxPage: Math.ceil(body.total / limit) || 1 } + + const total = body.hot_comments_counts + return { + source: 'kw', + comments: this.filterComment(body.hot_comments), + total, + page, + limit, + maxPage: Math.ceil(total / limit) || 1, + } }, filterComment(rawList) { if (!rawList) return [] return rawList.map(item => { - let data = { + return { id: item.id, text: item.msg, time: item.time, - timeStr: dateFormat2(new Date(item.time).getTime()), - userName: decodeURIComponent(item.u_name), + timeStr: dateFormat2(Number(item.time) * 1000), + userName: item.u_name, avatar: item.u_pic, userId: item.u_id, likedCount: item.like_num, - reply: [], + images: item.mpic ? [item.mpic] : [], + reply: item.child_comments + ? item.child_comments.map(i => { + return { + id: i.id, + text: i.msg, + time: i.time, + timeStr: dateFormat2(Number(i.time) * 1000), + userName: i.u_name, + avatar: i.u_pic, + userId: i.u_id, + likedCount: i.like_num, + images: i.mpic ? [i.mpic] : [], + } + }) + : [], } - return item.reply - ? { - id: item.id, - rootId: item.reply.id, - text: item.reply.msg, - time: item.reply.time, - timeStr: dateFormat2(new Date(item.reply.time).getTime()), - userName: decodeURIComponent(item.reply.u_name), - avatar: item.reply.u_pic, - userId: item.reply.u_id, - likedCount: item.reply.like_num, - reply: [data], - } - : data }) }, }