完善评论功能
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { httpFetch } from '../../request'
|
||||
|
||||
export default {
|
||||
getAlbum(songInfo, tryNum = 0) {
|
||||
let requestObj = httpFetch(`http://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/queryAlbumSong?albumId=${songInfo.albumId}&pageNo=1`, {
|
||||
headers: {
|
||||
sign: '46DB65104950B98FE451AD41047CC6C4',
|
||||
timestamp: 1603451430776,
|
||||
appId: 'yyapp2',
|
||||
mode: 'android',
|
||||
ua: 'Android_migu',
|
||||
version: '6.9.4',
|
||||
osVersion: 'android 7.0',
|
||||
'User-Agent': 'okhttp/3.9.1',
|
||||
channel: '0146832',
|
||||
},
|
||||
})
|
||||
requestObj.promise = requestObj.promise.then(({ body }) => {
|
||||
if (body.code !== '000000') {
|
||||
if (tryNum > 5) return Promise.reject('获取专辑失败')
|
||||
let tryRequestObj = this.getAlbum(songInfo, ++tryNum)
|
||||
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
||||
return tryRequestObj.promise
|
||||
}
|
||||
console.log(body)
|
||||
return body.songList
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import { httpFetch } from '../../request'
|
||||
import album from './album'
|
||||
import { dateFormat2 } from '../../'
|
||||
|
||||
export default {
|
||||
_requestObj: null,
|
||||
_requestObj2: null,
|
||||
_requestObj3: null,
|
||||
async getSongId(musicInfo) {
|
||||
if (this._requestObj3) this._requestObj3.cancelHttp()
|
||||
this.requestObj3 = album.getAlbum(musicInfo)
|
||||
const list = await this.requestObj3.promise
|
||||
const copyrightId = musicInfo.copyrightId
|
||||
let info = list.find(s => s.copyrightId == copyrightId)
|
||||
const songmid = musicInfo.songmid
|
||||
if (!info) info = list.find(s => s.songId == songmid)
|
||||
return info ? info.songId : null
|
||||
},
|
||||
async getComment(musicInfo, page = 1, limit = 20) {
|
||||
if (this._requestObj) this._requestObj.cancelHttp()
|
||||
if (!musicInfo.songId) {
|
||||
let id = await this.getSongId(musicInfo)
|
||||
if (!id) throw new Error('获取评论失败')
|
||||
musicInfo.songId = id
|
||||
}
|
||||
|
||||
const _requestObj = httpFetch(`https://music.migu.cn/v3/api/comment/listComments?targetId=${musicInfo.songId}&pageSize=${limit}&pageNo=${page}`, {
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4195.1 Safari/537.36',
|
||||
Referer: 'https://music.migu.cn',
|
||||
},
|
||||
})
|
||||
const { body, statusCode } = await _requestObj.promise
|
||||
console.log(body)
|
||||
if (statusCode != 200 || body.returnCode !== '000000') throw new Error('获取评论失败')
|
||||
return { source: 'mg', comments: this.filterComment(body.data.items), total: body.data.itemTotal, page, limit, maxPage: Math.ceil(body.data.itemTotal / limit) || 1 }
|
||||
},
|
||||
async getHotComment(musicInfo, page = 1, limit = 100) {
|
||||
if (this._requestObj2) this._requestObj2.cancelHttp()
|
||||
|
||||
if (!musicInfo.songId) {
|
||||
let id = await this.getSongId(musicInfo)
|
||||
if (!id) throw new Error('获取评论失败')
|
||||
musicInfo.songId = id
|
||||
}
|
||||
|
||||
const _requestObj2 = httpFetch(`https://music.migu.cn/v3/api/comment/listTopComments?targetId=${musicInfo.songId}&pageSize=${limit}&pageNo=${page}`, {
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4195.1 Safari/537.36',
|
||||
Referer: 'https://music.migu.cn',
|
||||
},
|
||||
})
|
||||
const { body, statusCode } = await _requestObj2.promise
|
||||
// console.log(body)
|
||||
if (statusCode != 200 || body.returnCode !== '000000') throw new Error('获取热门评论失败')
|
||||
return { source: 'mg', comments: this.filterComment(body.data.items) }
|
||||
},
|
||||
async getReplyComment(musicInfo, replyId, page = 1, limit = 100) {
|
||||
if (this._requestObj2) this._requestObj2.cancelHttp()
|
||||
|
||||
const _requestObj2 = httpFetch(`https://music.migu.cn/v3/api/comment/listCommentsById?commentId=${replyId}&pageSize=${limit}&pageNo=${page}`, {
|
||||
headers: {
|
||||
'User-Agent': 'Android712-AndroidPhone-8983-18-0-COMMENT-wifi',
|
||||
},
|
||||
})
|
||||
const { body, statusCode } = await _requestObj2.promise
|
||||
// console.log(body)
|
||||
if (statusCode != 200 || body.returnCode !== '000000') throw new Error('获取回复评论失败')
|
||||
return { source: 'mg', comments: this.filterComment(body.data.items) }
|
||||
},
|
||||
filterComment(rawList) {
|
||||
return rawList.map(item => ({
|
||||
id: item.commentId,
|
||||
text: item.body.split('\n'),
|
||||
time: item.createTime,
|
||||
timeStr: dateFormat2(new Date(item.createTime).getTime()),
|
||||
userName: item.author.name,
|
||||
avatar: item.author.avatar,
|
||||
userId: item.author.id,
|
||||
likedCount: item.praiseCount,
|
||||
replyNum: item.replyTotal,
|
||||
reply: item.replyCommentList.map(c => ({
|
||||
id: c.commentId,
|
||||
text: c.body.split('\n'),
|
||||
time: c.createTime,
|
||||
timeStr: dateFormat2(new Date(c.createTime).getTime()),
|
||||
userName: c.author.name,
|
||||
avatar: c.author.avatar,
|
||||
userId: c.author.id,
|
||||
likedCount: c.praiseCount,
|
||||
replyNum: c.replyTotal,
|
||||
})),
|
||||
}))
|
||||
},
|
||||
}
|
||||
@@ -5,12 +5,14 @@ import musicSearch from './musicSearch'
|
||||
import pic from './pic'
|
||||
import lyric from './lyric'
|
||||
import hotSearch from './hotSearch'
|
||||
import comment from './comment'
|
||||
|
||||
const mg = {
|
||||
songList,
|
||||
musicSearch,
|
||||
leaderboard,
|
||||
hotSearch,
|
||||
comment,
|
||||
getMusicUrl(songInfo, type) {
|
||||
return apis('mg').getMusicUrl(songInfo, type)
|
||||
},
|
||||
|
||||
@@ -137,6 +137,7 @@ export default {
|
||||
albumName: item.album,
|
||||
albumId: item.albumId,
|
||||
songmid: item.copyrightId,
|
||||
songId: item.songId,
|
||||
copyrightId: item.copyrightId,
|
||||
source: 'mg',
|
||||
interval: null,
|
||||
@@ -195,7 +196,7 @@ export default {
|
||||
getList(bangid, page, retryNum = 0) {
|
||||
if (++retryNum > 3) return Promise.reject(new Error('try max num'))
|
||||
return this.getData(this.getUrl(bangid, page)).then(({ statusCode, body }) => {
|
||||
// console.log(body)
|
||||
console.log(body)
|
||||
if (statusCode !== 200 || body.code !== this.successCode) return this.getList(bangid, page, retryNum)
|
||||
const list = this.filterData(body.data.columnInfo.dataList)
|
||||
return {
|
||||
|
||||
@@ -36,7 +36,7 @@ export default {
|
||||
return arr.join('、')
|
||||
},
|
||||
handleResult(rawData) {
|
||||
// console.log(rawData)
|
||||
console.log(rawData)
|
||||
let ids = new Set()
|
||||
const list = []
|
||||
rawData.forEach(item => {
|
||||
@@ -82,6 +82,7 @@ export default {
|
||||
albumName: albumNInfo.name,
|
||||
albumId: albumNInfo.id,
|
||||
songmid: item.id,
|
||||
songId: item.songId,
|
||||
copyrightId: item.copyrightId,
|
||||
source: 'mg',
|
||||
interval: null,
|
||||
|
||||
@@ -24,25 +24,25 @@ export default {
|
||||
list: /<li><div class="thumb">.+?<\/li>/g,
|
||||
listInfo: /.+data-original="(.+?)".*data-id="(\d+)".*<div class="song-list-name"><a\s.*?>(.+?)<\/a>.+<i class="iconfont cf-bofangliang"><\/i>(.+?)<\/div>/,
|
||||
|
||||
// http://music.migu.cn/v3/music/playlist/161044573?page=1
|
||||
// https://music.migu.cn/v3/music/playlist/161044573?page=1
|
||||
listDetailLink: /^.+\/playlist\/(\d+)(?:\?.*|&.*$|#.*$|$)/,
|
||||
},
|
||||
tagsUrl: 'https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/indexTagPage.do?needAll=0',
|
||||
getSongListUrl(sortId, tagId, page) {
|
||||
// if (tagId == null) {
|
||||
// return sortId == 'recommend'
|
||||
// ? `http://music.migu.cn/v3/music/playlist?page=${page}&from=migu`
|
||||
// : `http://music.migu.cn/v3/music/playlist?sort=${sortId}&page=${page}&from=migu`
|
||||
// ? `https://music.migu.cn/v3/music/playlist?page=${page}&from=migu`
|
||||
// : `https://music.migu.cn/v3/music/playlist?sort=${sortId}&page=${page}&from=migu`
|
||||
// }
|
||||
// return `http://music.migu.cn/v3/music/playlist?tagId=${tagId}&page=${page}&from=migu`
|
||||
// return `https://music.migu.cn/v3/music/playlist?tagId=${tagId}&page=${page}&from=migu`
|
||||
if (tagId == null) {
|
||||
// return `http://app.c.nf.migu.cn/MIGUM2.0/v2.0/content/getMusicData.do?count=${this.limit_list}&start=${page}&templateVersion=5&type=1`
|
||||
// return `https://app.c.nf.migu.cn/MIGUM2.0/v2.0/content/getMusicData.do?count=${this.limit_list}&start=${page}&templateVersion=5&type=1`
|
||||
// return `https://c.musicapp.migu.cn/MIGUM2.0/v2.0/content/getMusicData.do?count=${this.limit_list}&start=${page}&templateVersion=5&type=${sortId}`
|
||||
// http://app.c.nf.migu.cn/MIGUM2.0/v2.0/content/getMusicData.do?count=50&start=2&templateVersion=5&type=1
|
||||
return `http://m.music.migu.cn/migu/remoting/playlist_bycolumnid_tag?playListType=2&type=1&columnId=${sortId}&startIndex=${(page - 1) * 10}`
|
||||
// https://app.c.nf.migu.cn/MIGUM2.0/v2.0/content/getMusicData.do?count=50&start=2&templateVersion=5&type=1
|
||||
return `https://m.music.migu.cn/migu/remoting/playlist_bycolumnid_tag?playListType=2&type=1&columnId=${sortId}&startIndex=${(page - 1) * 10}`
|
||||
}
|
||||
// return `https://app.c.nf.migu.cn/MIGUM2.0/v2.0/content/getMusicData.do?area=2&count=${this.limit_list}&start=${page}&tags=${tagId}&templateVersion=5&type=3`
|
||||
return `http://m.music.migu.cn/migu/remoting/playlist_bycolumnid_tag?playListType=2&type=1&tagId=${tagId}&startIndex=${(page - 1) * 10}`
|
||||
return `https://m.music.migu.cn/migu/remoting/playlist_bycolumnid_tag?playListType=2&type=1&tagId=${tagId}&startIndex=${(page - 1) * 10}`
|
||||
},
|
||||
getSongListDetailUrl(id, page) {
|
||||
return `https://app.c.nf.migu.cn/MIGUM2.0/v1.0/user/queryMusicListSongs.do?musicListId=${id}&pageNo=${page}&pageSize=${this.limit_song}`
|
||||
@@ -74,7 +74,7 @@ export default {
|
||||
return this._requestObj_listDetail.promise.then(({ body }) => {
|
||||
if (body.code !== this.successCode) return this.getListDetail(id, page, ++tryNum)
|
||||
// console.log(JSON.stringify(body))
|
||||
console.log(body)
|
||||
// console.log(body)
|
||||
return {
|
||||
list: this.filterListDetail(body.list),
|
||||
page,
|
||||
@@ -135,6 +135,7 @@ export default {
|
||||
albumId: item.albumId,
|
||||
songmid: item.copyrightId,
|
||||
copyrightId: item.copyrightId,
|
||||
songId: item.songId,
|
||||
source: 'mg',
|
||||
interval: null,
|
||||
img: item.albumImgs && item.albumImgs.length ? item.albumImgs[0].img : null,
|
||||
@@ -185,7 +186,6 @@ export default {
|
||||
// })
|
||||
return this._requestObj_list.promise.then(({ body }) => {
|
||||
if (body.retCode !== '100000' || body.retMsg.code !== this.successCode) return this.getList(sortId, tagId, page, ++tryNum)
|
||||
// console.log(body)
|
||||
return {
|
||||
list: this.filterList(body.retMsg.playlist),
|
||||
total: parseInt(body.retMsg.countSize),
|
||||
|
||||
Reference in New Issue
Block a user