This commit is contained in:
Folltoshe 2022-12-23 03:40:22 +00:00 committed by GitHub
commit b6cba99bf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 81 deletions

View File

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

View File

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

View File

@ -99,6 +99,7 @@ export default {
if (!props.musicInfo) return lists.value = []
currentMusicInfo.value = 'progress' in props.musicInfo ? props.musicInfo.metadata.musicInfo : props.musicInfo
console.log(props.musicInfo)
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")
div(:class="$style.tab_content")
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')}}
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')}}
@ -148,10 +148,10 @@ export default {
})
})
},
async getComment(musicInfo, page, limit, retryNum = 0) {
async getComment(musicInfo, page, limit, retryNum = 0, id = 0) {
let resp
try {
resp = await music[musicInfo.source].comment.getComment(musicInfo, page, limit)
resp = await music[musicInfo.source].comment.getComment(musicInfo, page, limit, id)
} catch (error) {
if (error.message == '取消请求' || ++retryNum > 2) throw error
resp = await this.getComment(musicInfo, page, limit, retryNum)
@ -168,10 +168,10 @@ export default {
}
return resp
},
handleGetNewComment(musicInfo, page, limit) {
handleGetNewComment(musicInfo, page, limit, id) {
this.newComment.isLoadError = false
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.total = comment.total
this.newComment.maxPage = comment.maxPage
@ -228,7 +228,7 @@ export default {
this.isShowComment = true
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) {
this.hotComment.nextPage = page
@ -236,7 +236,7 @@ export default {
},
handleToggleCommentPage(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) {
if (!this.available || (!force && this.tabActiveId == id)) return

View File

@ -73,72 +73,49 @@ const emojis = {
export default {
_requestObj: null,
_requestObj2: null,
async getComment({ songId }, page = 1, limit = 20) {
async getComment({ songMid }, page = 1, limit = 20, msgId) {
if (this._requestObj) this._requestObj.cancelHttp()
const _requestObj = httpFetch('http://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg', {
method: 'POST',
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}}}`, {
method: 'GET',
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
},
form: {
uin: '0',
format: 'json',
cid: '205360772',
reqtype: '2',
biztype: '1',
topid: songId,
cmd: '8',
needmusiccrit: '1',
pagenum: page - 1,
pagesize: limit,
origin: 'https://y.qq.com',
referer: 'https://y.qq.com',
},
})
const { body, statusCode } = await _requestObj.promise
if (statusCode != 200 || body.code !== 0) throw new Error('获取评论失败')
// console.log(body, statusCode)
const comment = body.comment
if (statusCode != 200 || body.code != 0) throw new Error('获取评论失败')
const comment = body.req_1.data
return {
source: 'tx',
comments: this.filterComment(comment.commentlist),
total: comment.commenttotal,
comments: this.filterComment(comment.CommentList.Comments),
total: comment.CommentList.Total,
page,
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()
const _requestObj2 = httpFetch('http://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg', {
method: 'POST',
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: 'GET',
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
},
form: {
uin: '0',
format: 'json',
cid: '205360772',
reqtype: '2',
biztype: '1',
topid: songId,
cmd: '9',
needmusiccrit: '1',
pagenum: page - 1,
pagesize: limit,
origin: 'https://y.qq.com',
referer: 'https://y.qq.com',
},
})
const { body, statusCode } = await _requestObj2.promise
if (statusCode != 200 || body.code !== 0) throw new Error('获取热门评论失败')
// console.log(body, statusCode)
const comment = body.comment
const comment = body.req_1.data
return {
source: 'tx',
comments: this.filterComment(comment.commentlist),
total: comment.commenttotal,
comments: this.filterComment(comment.CommentList3.Comments),
total: comment.CommentList3.Total,
page,
limit,
maxPage: Math.ceil(comment.commenttotal / limit) || 1,
maxPage: Math.ceil(comment.CommentList3.Total / limit) || 1,
}
},
replaceEmoji(msg) {
@ -154,41 +131,28 @@ export default {
},
filterComment(rawList) {
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
if (item.middlecommentcontent) {
let firstItem = item.middlecommentcontent[0]
firstItem.avatarurl = item.avatarurl
firstItem.praisenum = item.praisenum
item.avatarurl = null
item.praisenum = null
item.middlecommentcontent.reverse()
}
// if (item.middlecommentcontent) {
// let firstItem = item.middlecommentcontent[0]
// firstItem.avatarurl = item.avatarurl
// firstItem.praisenum = item.praisenum
// item.avatarurl = null
// item.praisenum = null
// item.middlecommentcontent.reverse()
// }
return {
id: `${item.rootcommentid}_${item.commentid}`,
id: item.SeqNo,
rootId: item.rootcommentid,
text: item.rootcommentcontent ? this.replaceEmoji(item.rootcommentcontent).replace(/\\n/g, '\n').split('\n') : [],
time: item.rootcommentid == item.commentid ? time : null,
timeStr: item.rootcommentid == item.commentid ? timeStr : null,
userName: item.rootcommentnick ? item.rootcommentnick.substring(1) : '',
avatar: item.avatarurl,
userId: item.encrypt_rootcommentuin,
likedCount: item.praisenum,
reply: item.middlecommentcontent
? 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,
}
})
: [],
text: item.Content ? this.replaceEmoji(item.Content).replace(/\\n/g, '\n').split('\n') : [],
time,
timeStr,
userName: item.Nick ? item.Nick : '',
avatar: item.Avatar,
userId: item.EncryptUin,
likedCount: item.PraiseNum,
reply: [],
}
})
},