更新wy评论API
This commit is contained in:
parent
bd44ae9f61
commit
e121bb7fa8
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -12,5 +12,6 @@
|
||||
],
|
||||
"i18n-ally.sortKeys": true,
|
||||
"javascript.preferences.importModuleSpecifier": "non-relative",
|
||||
"typescript.tsdk": "node_modules/typescript/lib"
|
||||
"typescript.tsdk": "node_modules/typescript/lib",
|
||||
"vue.features.codeActions.enable": false
|
||||
}
|
||||
|
||||
@ -413,7 +413,7 @@ export default {
|
||||
|
||||
switch (codeInfo.type) {
|
||||
case 2:
|
||||
if (!codeInfo.global_collection_id) return this.getListDetailBySpecialId(codeInfo.id, page)
|
||||
if (!codeInfo.global_collection_id) return this.getUserListDetailBySpecialId(codeInfo.id, page)
|
||||
break
|
||||
case 3:
|
||||
return this.getListDetailByAlbumId(codeInfo.id, page)
|
||||
@ -452,7 +452,7 @@ export default {
|
||||
* @param {*} id
|
||||
* @param {*} page
|
||||
*/
|
||||
async getListDetailBySpecialId(id, page = 1) {
|
||||
async getUserListDetailBySpecialId(id, page = 1) {
|
||||
const globalSpecialId = await this.getCollectionIdBySpecialId(id)
|
||||
return this.getUserListDetailByCollectionId(globalSpecialId, page)
|
||||
},
|
||||
@ -746,9 +746,10 @@ export default {
|
||||
// fix https://www.kugou.com/songlist/xxx/?uid=xxx&chl=qq_client&cover=http%3A%2F%2Fimge.kugou.com%xxx.jpg&iszlist=1
|
||||
if (/https?:/.test(id)) return this.getUserListDetail(id.replace(/^.*?http/, 'http'), page)
|
||||
if (/^\d+$/.test(id)) return this.getUserListDetailByCode(id, page)
|
||||
if (id.startsWith('id_')) id = id.replace('id_', '')
|
||||
if (id.startsWith('gid_')) return this.getUserListDetailByCollectionId(id.replace('gid_', ''), page)
|
||||
if (id.startsWith('id_')) return this.getUserListDetailBySpecialId(id.replace('id_', ''), page)
|
||||
|
||||
return this.getUserListDetailByCollectionId(id, page)
|
||||
return new Error('Failed.')
|
||||
},
|
||||
|
||||
filterData(rawList) {
|
||||
@ -939,7 +940,7 @@ export default {
|
||||
list: body.lists.map(item => {
|
||||
return {
|
||||
play_count: this.formatPlayCount(item.total_play_count),
|
||||
id: 'id_' + item.gid,
|
||||
id: item.gid ? `gid_${item.gid}` : `id_${item.specialid}`,
|
||||
author: item.nickname,
|
||||
name: item.specialname,
|
||||
time: dateFormat(item.publish_time, 'Y-M-D'),
|
||||
|
||||
@ -2,6 +2,7 @@ import { httpFetch } from '../../request'
|
||||
import { weapi } from './utils/crypto'
|
||||
import { dateFormat2 } from '../../index'
|
||||
|
||||
const idPrefix = 'R_SO_4_'
|
||||
const emojis = [
|
||||
['大笑', '😃'],
|
||||
['可爱', '😊'],
|
||||
@ -118,14 +119,12 @@ export default {
|
||||
_requestObj: null,
|
||||
_requestObj2: null,
|
||||
async getComment({ songmid }, page = 1, limit = 20) {
|
||||
if (this._requestObj) this._requestObj.cancelHttp()
|
||||
|
||||
const id = 'R_SO_4_' + songmid
|
||||
|
||||
const cursorInfo = cursorTools.getCursor(songmid, page, limit)
|
||||
|
||||
if (this._requestObj) this._requestObj.cancelHttp()
|
||||
const _requestObj = httpFetch('https://music.163.com/weapi/comment/resource/comments/get', {
|
||||
method: 'post',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
|
||||
origin: 'https://music.163.com',
|
||||
@ -144,36 +143,43 @@ export default {
|
||||
const { body, statusCode } = await _requestObj.promise
|
||||
// console.log(body)
|
||||
if (statusCode != 200 || body.code !== 200) throw new Error('获取评论失败')
|
||||
|
||||
cursorTools.setCursor(songmid, body.data.cursor, cursorInfo.orderType, cursorInfo.offset, page)
|
||||
return { source: 'wy', comments: this.filterComment(body.data.comments), total: body.data.totalCount, page, limit, maxPage: Math.ceil(body.data.totalCount / limit) || 1 }
|
||||
},
|
||||
async getHotComment({ songmid }, page = 1, limit = 100) {
|
||||
async getHotComment({ songmid }, page = 1, limit = 10) {
|
||||
// 这个API每次最多获取10个
|
||||
if (limit > 10) limit = 10
|
||||
const id = idPrefix + songmid
|
||||
|
||||
if (this._requestObj2) this._requestObj2.cancelHttp()
|
||||
|
||||
const id = 'R_SO_4_' + songmid
|
||||
|
||||
const _requestObj2 = httpFetch('https://music.163.com/weapi/comment/resource/comments/get', {
|
||||
method: 'post',
|
||||
const _requestObj2 = httpFetch(`https://music.163.com/weapi/v1/resource/hotcomments/${id}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
|
||||
origin: 'https://music.163.com',
|
||||
Refere: 'http://music.163.com/',
|
||||
},
|
||||
form: weapi({
|
||||
cursor: Date.now().toString(),
|
||||
offset: 0,
|
||||
orderType: 1,
|
||||
pageNo: page,
|
||||
pageSize: limit,
|
||||
rid: id,
|
||||
threadId: id,
|
||||
beforeTime: Date.now().toString(),
|
||||
offset: page === 1 ? 0 : (page - 1) * limit,
|
||||
pageSize: limit,
|
||||
}),
|
||||
})
|
||||
|
||||
const { body, statusCode } = await _requestObj2.promise
|
||||
if (statusCode != 200 || body.code !== 200) throw new Error('获取热门评论失败')
|
||||
// console.log(body)
|
||||
const total = body.data.hotComments?.length ?? 0
|
||||
return { source: 'wy', comments: this.filterComment(body.data.hotComments), total, page, limit, maxPage: 1 }
|
||||
|
||||
return {
|
||||
source: 'wy',
|
||||
comments: this.filterComment(body.hotComments),
|
||||
total: body.total,
|
||||
page,
|
||||
limit,
|
||||
maxPage: Math.ceil(body.total / limit) || 1,
|
||||
}
|
||||
},
|
||||
filterComment(rawList) {
|
||||
return rawList.map(item => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user