kg源数据更新 (#1232)

* kg源评论接口更新,热门评论完整支持
* kg搜索HiRes支持
---------

Co-authored-by: 彭狸花喵 <94218819+helloplhm-qwq@users.noreply.github.com>
pull/1235/head
lyswhut 2023-03-05 17:27:17 +08:00 committed by GitHub
parent fe259747dc
commit 371b8fad05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 35 deletions

View File

@ -12,6 +12,7 @@
- 支持wy源flac hires歌曲类型的显示
- 快捷键调整音量时每次加减2%音量改为4%#1220
- 音量、播放模式等设置弹出式按钮在鼠标移到按钮上时将自动弹出设置内容,保留点击切换显示/隐藏
- 支持kg源搜索列表flac hires歌曲类型的显示@helloplhm-qwq
### 修复

View File

@ -1,5 +1,12 @@
import { httpFetch } from '../../request'
import { decodeName, dateFormat2 } from '../../index'
import { toMD5 } from '../utils'
const signatureParams = (params) => {
let OIlwieks = '28dk2k092lksi2UIkp'
let sign_params = `OIlwieks${OIlwieks}${params.replace(/&/g, '')}OIlwieks${OIlwieks}`
return toMD5(sign_params)
}
export default {
_requestObj: null,
@ -7,21 +14,26 @@ export default {
async getComment({ hash }, page = 1, limit = 20) {
if (this._requestObj) this._requestObj.cancelHttp()
const _requestObj = httpFetch(`http://comment.service.kugou.com/index.php?r=commentsv2/getCommentWithLike&code=fc4be23b4e972707f36b8a828a93ba8a&extdata=${hash}&p=${page}&pagesize=${limit}&ver=1.01&clientver=8373&appid=1001&kugouid=687373022&need_show_image=1`, {
let timestamp = Date.now()
const params = `appid=1005&clienttime=${timestamp}&clienttoken=0&clientver=11409&code=fc4be23b4e972707f36b8a828a93ba8a&dfid=0&extdata=${hash}&kugouid=0&mid=16249512204336365674023395779019&mixsongid=0&p=${page}&pagesize=${limit}&uuid=0&ver=10`
let signature = signatureParams(params)
const _requestObj = httpFetch(`http://m.comment.service.kugou.com/v1/cmtlist?${params}&signature=${signature}`, {
headers: {
'User-Agent': 'Android712-AndroidPhone-8983-18-0-COMMENT-wifi',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.24',
},
})
const { body, statusCode } = await _requestObj.promise
// console.log(body)
if (statusCode != 200 || body.err_code !== 0) throw new Error('获取评论失败')
return { source: 'kg', comments: this.filterComment(body.list || []), total: body.count, page, limit, maxPage: Math.ceil(body.count / limit) || 1 }
return { source: 'kg', comments: this.filterComment(body.list || []), total: body.count, page, limit, maxPage: body.maxPage }
},
async getHotComment({ hash, songmid }, page = 1, limit = 100) {
async getHotComment({ hash }, page = 1, limit = 20) {
// console.log(songmid)
if (this._requestObj2) this._requestObj2.cancelHttp()
const _requestObj2 = httpFetch(`http://comment.service.kugou.com/index.php?r=commentsv2/getCommentWithLike&code=fc4be23b4e972707f36b8a828a93ba8a&extdata=${hash}&p=${page}&pagesize=${limit}&ver=1.01&clientver=8373&appid=1001&kugouid=687373022&need_show_image=1`, {
let timestamp = Date.now()
const params = `appid=1005&clienttime=${timestamp}&clienttoken=0&clientver=11409&code=fc4be23b4e972707f36b8a828a93ba8a&dfid=0&extdata=${hash}&kugouid=0&mid=16249512204336365674023395779019&mixsongid=0&p=${page}&pagesize=${limit}&uuid=0&ver=10`
let signature = signatureParams(params)
const _requestObj2 = httpFetch(`http://m.comment.service.kugou.com/v1/weightlist?${params}&signature=${signature}`, {
headers: {
'User-Agent': 'Android712-AndroidPhone-8983-18-0-COMMENT-wifi',
},
@ -29,8 +41,8 @@ export default {
const { body, statusCode } = await _requestObj2.promise
// console.log(body)
if (statusCode != 200 || body.err_code !== 0) throw new Error('获取热门评论失败')
const total = body.weightList?.length ?? 0
return { source: 'kg', comments: this.filterComment(body.weightList || []), total, page, limit, maxPage: 1 }
const total = body.count ?? 0
return { source: 'kg', comments: this.filterComment(body.list || []), total, page, limit, maxPage: Math.ceil(body.count / limit) || 1 }
},
async getReplyComment({ songmid, audioId }, replyId, page = 1, limit = 100) {
if (this._requestObj2) this._requestObj2.cancelHttp()

View File

@ -11,65 +11,72 @@ export default {
page: 0,
allPage: 1,
musicSearch(str, page, limit) {
const searchRequest = httpFetch(`http://ioscdn.kugou.com/api/v3/search/song?keyword=${encodeURIComponent(str)}&page=${page}&pagesize=${limit}&showtype=10&plat=2&version=7910&tag=1&correct=1&privilege=1&sver=5`)
const searchRequest = httpFetch(`https://songsearch.kugou.com/song_search_v2?keyword=${encodeURIComponent(str)}&page=${page}&pagesize=${limit}&userid=0&clientver=&platform=WebFilter&filter=2&iscorrection=1&privilege_filter=0`)
return searchRequest.promise.then(({ body }) => body)
},
filterData(rawData) {
const types = []
const _types = {}
if (rawData.filesize !== 0) {
let size = sizeFormate(rawData.filesize)
types.push({ type: '128k', size, hash: rawData.hash })
if (rawData.FileSize !== 0) {
let size = sizeFormate(rawData.FileSize)
types.push({ type: '128k', size, hash: rawData.FileHash })
_types['128k'] = {
size,
hash: rawData.hash,
hash: rawData.FileHash,
}
}
if (rawData['320filesize'] !== 0) {
let size = sizeFormate(rawData['320filesize'])
types.push({ type: '320k', size, hash: rawData['320hash'] })
if (rawData.HQFileSize !== 0) {
let size = sizeFormate(rawData.HQFileSize)
types.push({ type: '320k', size, hash: rawData.HQFileHash })
_types['320k'] = {
size,
hash: rawData['320hash'],
hash: rawData.HQFileHash,
}
}
if (rawData.sqfilesize !== 0) {
let size = sizeFormate(rawData.sqfilesize)
types.push({ type: 'flac', size, hash: rawData.sqhash })
if (rawData.SQFileSize !== 0) {
let size = sizeFormate(rawData.SQFileSize)
types.push({ type: 'flac', size, hash: rawData.SQFileHash })
_types.flac = {
size,
hash: rawData.sqhash,
hash: rawData.SQFileHash,
}
}
if (rawData.ResFileSize !== 0) {
let size = sizeFormate(rawData.ResFileSize)
types.push({ type: 'flac24bit', size, hash: rawData.ResFileHash })
_types.flac24bit = {
size,
hash: rawData.ResFileHash,
}
}
return {
singer: decodeName(rawData.singername),
name: decodeName(rawData.songname),
albumName: decodeName(rawData.album_name),
albumId: rawData.album_id,
songmid: rawData.audio_id,
singer: decodeName(rawData.SingerName),
name: decodeName(rawData.SongName),
albumName: decodeName(rawData.AlbumName),
albumId: rawData.Albumid,
songmid: rawData.Audioid,
source: 'kg',
interval: formatPlayTime(rawData.duration),
_interval: rawData.duration,
interval: formatPlayTime(rawData.Duration),
_interval: rawData.Duration,
img: null,
lrc: null,
otherSource: null,
hash: rawData.hash,
hash: rawData.FileHash,
types,
_types,
typeUrl: {},
}
},
handleResult(rawData) {
// console.log(rawData)
let ids = new Set()
const list = []
rawData.forEach(item => {
const key = item.audio_id + item.hash
const key = item.Audioid + item.FileHash
if (ids.has(key)) return
ids.add(key)
list.push(this.filterData(item))
for (const childItem of item.group) {
const key = item.audio_id + item.hash
for (const childItem of item.Grp) {
const key = item.Audioid + item.FileHash
if (ids.has(key)) continue
ids.add(key)
list.push(this.filterData(childItem))
@ -82,8 +89,8 @@ export default {
if (limit == null) limit = this.limit
// http://newlyric.kuwo.cn/newlyric.lrc?62355680
return this.musicSearch(str, page, limit).then(result => {
if (!result || result.errcode !== 0) return this.search(str, page, limit, retryNum)
let list = this.handleResult(result.data.info)
if (!result || result.error_code !== 0) return this.search(str, page, limit, retryNum)
let list = this.handleResult(result.data.lists)
if (list == null) return this.search(str, page, limit, retryNum)