修复tx源无法显示评论的问题

This commit is contained in:
Folltoshe 2022-12-23 11:36:27 +08:00
parent bfc07b2a97
commit 25334fde82
5 changed files with 49 additions and 81 deletions

View File

@ -22,6 +22,7 @@ declare namespace LX {
songId: string | number // 歌曲IDmg源为copyrightIdlocal为文件路径 songId: string | number // 歌曲IDmg源为copyrightIdlocal为文件路径
albumName: string // 歌曲专辑名称 albumName: string // 歌曲专辑名称
picUrl?: string | null // 歌曲图片链接 picUrl?: string | null // 歌曲图片链接
songMid?: string | number //tx源的歌曲id用于获取评论
} }
interface MusicInfoMeta_online extends MusicInfoMetaBase { interface MusicInfoMeta_online extends MusicInfoMetaBase {

View File

@ -31,6 +31,7 @@ export const toNewMusicInfo = (oldMusicInfo: any): LX.Music.MusicInfo => {
case 'tx': case 'tx':
meta.strMediaMid = oldMusicInfo.strMediaMid meta.strMediaMid = oldMusicInfo.strMediaMid
meta.albumMid = oldMusicInfo.albumMid meta.albumMid = oldMusicInfo.albumMid
meta.songMid = oldMusicInfo.songId
break break
case 'mg': case 'mg':
meta.copyrightId = oldMusicInfo.copyrightId meta.copyrightId = oldMusicInfo.copyrightId
@ -80,6 +81,7 @@ export const toOldMusicInfo = (minfo: LX.Music.MusicInfo) => {
case 'tx': case 'tx':
oInfo.strMediaMid = minfo.meta.strMediaMid oInfo.strMediaMid = minfo.meta.strMediaMid
oInfo.albumMid = minfo.meta.albumMid oInfo.albumMid = minfo.meta.albumMid
oInfo.songMid = minfo.meta.songMid
break break
case 'mg': case 'mg':
oInfo.copyrightId = minfo.meta.copyrightId oInfo.copyrightId = minfo.meta.copyrightId

View File

@ -99,6 +99,7 @@ export default {
if (!props.musicInfo) return lists.value = [] if (!props.musicInfo) return lists.value = []
currentMusicInfo.value = 'progress' in props.musicInfo ? props.musicInfo.metadata.musicInfo : props.musicInfo currentMusicInfo.value = 'progress' in props.musicInfo ? props.musicInfo.metadata.musicInfo : props.musicInfo
console.log(props.musicInfo)
getList() getList()

View File

@ -26,7 +26,7 @@ div.comment(:class="$style.comment" ref="dom_container")
material-pagination(:count="hotComment.total" :btnLength="5" :limit="hotComment.limit" :page="hotComment.page" @btn-click="handleToggleHotCommentPage") material-pagination(:count="hotComment.total" :btnLength="5" :limit="hotComment.limit" :page="hotComment.page" @btn-click="handleToggleHotCommentPage")
div(:class="$style.tab_content") div(:class="$style.tab_content")
div.scroll(:class="$style.tab_content_scroll" ref="dom_commentNew") div.scroll(:class="$style.tab_content_scroll" ref="dom_commentNew")
p(:class="$style.commentLabel" style="cursor: pointer;" v-if="newComment.isLoadError" @click="handleGetNewComment(currentMusicInfo, newComment.nextPage, newComment.limit)") {{$t('comment__new_load_error')}} p(:class="$style.commentLabel" style="cursor: pointer;" v-if="newComment.isLoadError" @click="handleGetNewComment(currentMusicInfo, newComment.nextPage, newComment.limit, this.newComment.list.pop() === undefined ? 0 : this.newComment.list.pop().id)") {{$t('comment__new_load_error')}}
p(:class="$style.commentLabel" v-else-if="newComment.isLoading && !newComment.list.length") {{$t('comment__new_loading')}} p(:class="$style.commentLabel" v-else-if="newComment.isLoading && !newComment.list.length") {{$t('comment__new_loading')}}
comment-floor(v-if="!newComment.isLoadError && newComment.list.length" :class="[$style.commentFloor, newComment.isLoading ? $style.loading : null]" :comments="newComment.list") comment-floor(v-if="!newComment.isLoadError && newComment.list.length" :class="[$style.commentFloor, newComment.isLoading ? $style.loading : null]" :comments="newComment.list")
p(:class="$style.commentLabel" v-else-if="!newComment.isLoadError && !newComment.isLoading") {{$t('comment__no_content')}} p(:class="$style.commentLabel" v-else-if="!newComment.isLoadError && !newComment.isLoading") {{$t('comment__no_content')}}
@ -148,10 +148,10 @@ export default {
}) })
}) })
}, },
async getComment(musicInfo, page, limit, retryNum = 0) { async getComment(musicInfo, page, limit, retryNum = 0, id = 0) {
let resp let resp
try { try {
resp = await music[musicInfo.source].comment.getComment(musicInfo, page, limit) resp = await music[musicInfo.source].comment.getComment(musicInfo, page, limit, id)
} catch (error) { } catch (error) {
if (error.message == '取消请求' || ++retryNum > 2) throw error if (error.message == '取消请求' || ++retryNum > 2) throw error
resp = await this.getComment(musicInfo, page, limit, retryNum) resp = await this.getComment(musicInfo, page, limit, retryNum)
@ -168,10 +168,10 @@ export default {
} }
return resp return resp
}, },
handleGetNewComment(musicInfo, page, limit) { handleGetNewComment(musicInfo, page, limit, id) {
this.newComment.isLoadError = false this.newComment.isLoadError = false
this.newComment.isLoading = true this.newComment.isLoading = true
this.getComment(toOldMusicInfo(musicInfo), page, limit).then(comment => { this.getComment(toOldMusicInfo(musicInfo), page, limit, 0, id).then(comment => {
this.newComment.isLoading = false this.newComment.isLoading = false
this.newComment.total = comment.total this.newComment.total = comment.total
this.newComment.maxPage = comment.maxPage this.newComment.maxPage = comment.maxPage
@ -228,7 +228,7 @@ export default {
this.isShowComment = true this.isShowComment = true
this.handleGetHotComment(this.currentMusicInfo, this.hotComment.page, this.hotComment.limit) this.handleGetHotComment(this.currentMusicInfo, this.hotComment.page, this.hotComment.limit)
this.handleGetNewComment(this.currentMusicInfo, this.newComment.page, this.newComment.limit) this.handleGetNewComment(this.currentMusicInfo, this.newComment.page, this.newComment.limit, this.newComment.list.pop() === undefined ? 0 : this.newComment.list.pop().id)
}, },
handleToggleHotCommentPage(page) { handleToggleHotCommentPage(page) {
this.hotComment.nextPage = page this.hotComment.nextPage = page
@ -236,7 +236,7 @@ export default {
}, },
handleToggleCommentPage(page) { handleToggleCommentPage(page) {
this.newComment.nextPage = page this.newComment.nextPage = page
this.handleGetNewComment(this.currentMusicInfo, page, this.newComment.limit) this.handleGetNewComment(this.currentMusicInfo, page, this.newComment.limit, this.newComment.list.pop() === undefined ? 0 : this.newComment.list.pop().id)
}, },
handleToggleTab(id, force) { handleToggleTab(id, force) {
if (!this.available || (!force && this.tabActiveId == id)) return if (!this.available || (!force && this.tabActiveId == id)) return

View File

@ -73,72 +73,49 @@ const emojis = {
export default { export default {
_requestObj: null, _requestObj: null,
_requestObj2: null, _requestObj2: null,
async getComment({ songId }, page = 1, limit = 20) { async getComment({ songMid }, page = 1, limit = 20, msgId) {
if (this._requestObj) this._requestObj.cancelHttp() if (this._requestObj) this._requestObj.cancelHttp()
const _requestObj = httpFetch(`https://u.y.qq.com/cgi-bin/musicu.fcg?data={"comm":{"cv":4747474,"ct":24,"format":"json","inCharset":"utf-8","outCharset":"utf-8","notice":0,"platform":"yqq.json","needNewCode":1,"uin":0,"g_tk_new_20200303":1231670726,"g_tk":1231670726},"req_1":{"module":"music.globalComment.CommentRead","method":"GetNewCommentList","param":{"BizType":1,"BizId":"${songMid}","PageSize":20,"PageNum":${Number(page) - 1},"LastCommentSeqNo":"${msgId}","FromCommentId":"","WithHot":0,"PicEnable":1}}}`, {
const _requestObj = httpFetch('http://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg', { method: 'GET',
method: 'POST',
headers: { headers: {
'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)', 'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
}, origin: 'https://y.qq.com',
form: { referer: 'https://y.qq.com',
uin: '0',
format: 'json',
cid: '205360772',
reqtype: '2',
biztype: '1',
topid: songId,
cmd: '8',
needmusiccrit: '1',
pagenum: page - 1,
pagesize: limit,
}, },
}) })
const { body, statusCode } = await _requestObj.promise const { body, statusCode } = await _requestObj.promise
if (statusCode != 200 || body.code !== 0) throw new Error('获取评论失败') if (statusCode != 200 || body.code != 0) throw new Error('获取评论失败')
// console.log(body, statusCode) const comment = body.req_1.data
const comment = body.comment
return { return {
source: 'tx', source: 'tx',
comments: this.filterComment(comment.commentlist), comments: this.filterComment(comment.CommentList.Comments),
total: comment.commenttotal, total: comment.CommentList.Total,
page, page,
limit, limit,
maxPage: Math.ceil(comment.commenttotal / limit) || 1, maxPage: Math.ceil(comment.CommentList.Total / limit) || 1,
} }
}, },
async getHotComment({ songId }, page = 1, limit = 100) { async getHotComment({ songMid }, page = 1, limit = 100) {
if (this._requestObj2) this._requestObj2.cancelHttp() if (this._requestObj2) this._requestObj2.cancelHttp()
const _requestObj2 = httpFetch('http://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg', { const _requestObj2 = httpFetch(`https://u.y.qq.com/cgi-bin/musicu.fcg?data={"comm":{"cv":4747474,"ct":24,"format":"json","inCharset":"utf-8","outCharset":"utf-8","notice":0,"platform":"yqq.json","needNewCode":1,"uin":0,"g_tk_new_20200303":1231670726,"g_tk":1231670726},"req_1":{"module":"music.globalComment.CommentRead","method":"GetNewCommentList","param":{"BizType":1,"BizId":"${songMid}","LastCommentSeqNo":"","PageSize":20,"PageNum":${Number(page) - 1},"FromCommentId":"","WithHot":1,"PicEnable":1,"LastTotal":0,"LastTotalVer":"0"}}}`, {
method: 'POST', method: 'GET',
headers: { headers: {
'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)', 'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
}, origin: 'https://y.qq.com',
form: { referer: 'https://y.qq.com',
uin: '0',
format: 'json',
cid: '205360772',
reqtype: '2',
biztype: '1',
topid: songId,
cmd: '9',
needmusiccrit: '1',
pagenum: page - 1,
pagesize: limit,
}, },
}) })
const { body, statusCode } = await _requestObj2.promise const { body, statusCode } = await _requestObj2.promise
if (statusCode != 200 || body.code !== 0) throw new Error('获取热门评论失败') if (statusCode != 200 || body.code !== 0) throw new Error('获取热门评论失败')
// console.log(body, statusCode) const comment = body.req_1.data
const comment = body.comment
return { return {
source: 'tx', source: 'tx',
comments: this.filterComment(comment.commentlist), comments: this.filterComment(comment.CommentList3.Comments),
total: comment.commenttotal, total: comment.CommentList3.Total,
page, page,
limit, limit,
maxPage: Math.ceil(comment.commenttotal / limit) || 1, maxPage: Math.ceil(comment.CommentList3.Total / limit) || 1,
} }
}, },
replaceEmoji(msg) { replaceEmoji(msg) {
@ -154,41 +131,28 @@ export default {
}, },
filterComment(rawList) { filterComment(rawList) {
return rawList.map(item => { return rawList.map(item => {
let time = String(item.time).length < 10 ? null : parseInt(item.time + '000') // TODO 回复
let time = String(item.PubTime).length < 10 ? null : parseInt(item.PubTime + '000')
let timeStr = time ? dateFormat2(time) : null let timeStr = time ? dateFormat2(time) : null
if (item.middlecommentcontent) { // if (item.middlecommentcontent) {
let firstItem = item.middlecommentcontent[0] // let firstItem = item.middlecommentcontent[0]
firstItem.avatarurl = item.avatarurl // firstItem.avatarurl = item.avatarurl
firstItem.praisenum = item.praisenum // firstItem.praisenum = item.praisenum
item.avatarurl = null // item.avatarurl = null
item.praisenum = null // item.praisenum = null
item.middlecommentcontent.reverse() // item.middlecommentcontent.reverse()
} // }
return { return {
id: `${item.rootcommentid}_${item.commentid}`, id: item.SeqNo,
rootId: item.rootcommentid, rootId: item.rootcommentid,
text: item.rootcommentcontent ? this.replaceEmoji(item.rootcommentcontent).replace(/\\n/g, '\n').split('\n') : [], text: item.Content ? this.replaceEmoji(item.Content).replace(/\\n/g, '\n').split('\n') : [],
time: item.rootcommentid == item.commentid ? time : null, time,
timeStr: item.rootcommentid == item.commentid ? timeStr : null, timeStr,
userName: item.rootcommentnick ? item.rootcommentnick.substring(1) : '', userName: item.Nick ? item.Nick : '',
avatar: item.avatarurl, avatar: item.Avatar,
userId: item.encrypt_rootcommentuin, userId: item.EncryptUin,
likedCount: item.praisenum, likedCount: item.PraiseNum,
reply: item.middlecommentcontent reply: [],
? item.middlecommentcontent.map(c => {
// let index = c.subcommentid.lastIndexOf('_')
return {
id: `sub_${item.rootcommentid}_${c.subcommentid}`,
text: this.replaceEmoji(c.subcommentcontent).replace(/\\n/g, '\n').split('\n'),
time: c.subcommentid == item.commentid ? time : null,
timeStr: c.subcommentid == item.commentid ? timeStr : null,
userName: c.replynick.substring(1),
avatar: c.avatarurl,
userId: c.encrypt_replyuin,
likedCount: c.praisenum,
}
})
: [],
} }
}) })
}, },