From d970687ebe1efdf331296fe7292e242cd26b28c2 Mon Sep 17 00:00:00 2001 From: Folltoshe Date: Thu, 13 Apr 2023 14:32:59 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9F=B3=E6=BA=90API=E6=9B=B4=E6=96=B0=20&=20?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E6=94=B9=E5=8A=A8=20(#1295)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## API ### kg源 - 增加歌单歌曲flac24bit显示 - 修复酷狗码只能导入500首的问题 - 更新排行榜 ### mg源 - 修复搜索不显示时长的问题 - 修复评论加载失败的问题 - 更新排行榜 ### tx源 - 增加热门评论图片显示 - 更新排行榜 ### wy源 - 更新排行榜 ## 其他 - 添加自定义源zlib模块的支持 --------- Co-authored-by: 彭狸花喵 <94218819+helloplhm-qwq@users.noreply.github.com> Co-authored-by: lyswhut --- publish/changeLog.md | 6 + src/common/utils/tools.ts | 2 +- src/main/modules/userApi/renderer/preload.js | 21 +- .../components/MusicComment/CommentFloor.vue | 12 +- src/renderer/core/music/utils.ts | 4 +- src/renderer/utils/musicSdk/bd/index.js | 3 +- src/renderer/utils/musicSdk/kg/comment.js | 18 +- src/renderer/utils/musicSdk/kg/leaderboard.js | 7 +- src/renderer/utils/musicSdk/kg/pic.js | 3 +- src/renderer/utils/musicSdk/kg/songList.js | 195 ++++++++++--- src/renderer/utils/musicSdk/kg/util.js | 10 + src/renderer/utils/musicSdk/kw/comment.js | 4 +- src/renderer/utils/musicSdk/kw/leaderboard.js | 2 +- src/renderer/utils/musicSdk/kw/pic.js | 2 +- src/renderer/utils/musicSdk/mg/album.js | 16 +- src/renderer/utils/musicSdk/mg/comment.js | 20 +- src/renderer/utils/musicSdk/mg/hotSearch.js | 6 +- src/renderer/utils/musicSdk/mg/leaderboard.js | 81 +----- .../utils/musicSdk/mg/leaderboard2.js | 3 +- src/renderer/utils/musicSdk/mg/lyric.js | 9 +- src/renderer/utils/musicSdk/mg/musicInfo.js | 100 +++++++ src/renderer/utils/musicSdk/mg/musicSearch.js | 261 ++++++++++++------ src/renderer/utils/musicSdk/mg/pic.js | 17 +- src/renderer/utils/musicSdk/mg/songId.js | 31 +++ src/renderer/utils/musicSdk/mg/songList.js | 73 +---- src/renderer/utils/musicSdk/tx/api-test.js | 4 +- src/renderer/utils/musicSdk/tx/comment.js | 132 +++++++-- src/renderer/utils/musicSdk/tx/leaderboard.js | 5 +- src/renderer/utils/musicSdk/wy/comment.js | 4 +- src/renderer/utils/musicSdk/wy/index.js | 3 +- src/renderer/utils/musicSdk/wy/leaderboard.js | 81 +++--- src/renderer/utils/musicSdk/xm.js | 4 +- 32 files changed, 713 insertions(+), 426 deletions(-) create mode 100644 src/renderer/utils/musicSdk/mg/musicInfo.js create mode 100644 src/renderer/utils/musicSdk/mg/songId.js diff --git a/publish/changeLog.md b/publish/changeLog.md index 747cb465..84906383 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -2,11 +2,17 @@ - 优化对系统Media Session的支持,现在切歌不会再会导致信息丢失的问题了 - 启用桌面歌词时,取消对歌词窗口的聚焦 +- 增加kg歌单歌曲flac24bit显示(@helloplhm-qwq) +- 增加tx源热门评论图片显示(@Folltoshe) ### 修复 - 修复启用全局快捷键时与Media Session注册冲突的问题,启用全局快捷键时,不再注册媒体控制快捷键 +- 修复搜索不显示时长的问题(@Folltoshe) +- 修复评论加载失败的问题(@Folltoshe) ### 其他 +- 自定义源API utils对象新增`zlib.inflate`与`zlib.deflate`方法,API版本更新到 v1.3.0 +- 更新kg、tx、wy等平台排行榜列表 - 更新 electron 到 v22.3.5 diff --git a/src/common/utils/tools.ts b/src/common/utils/tools.ts index bf3f2c94..40a3fac3 100644 --- a/src/common/utils/tools.ts +++ b/src/common/utils/tools.ts @@ -2,7 +2,7 @@ export const toNewMusicInfo = (oldMusicInfo: any): LX.Music.MusicInfo => { const meta: Record = { - songId: oldMusicInfo.songmid, // 歌曲ID,mg源为copyrightId,local为文件路径 + songId: oldMusicInfo.songmid, // 歌曲ID,local为文件路径 albumName: oldMusicInfo.albumName, // 歌曲专辑名称 picUrl: oldMusicInfo.img, // 歌曲图片链接 } diff --git a/src/main/modules/userApi/renderer/preload.js b/src/main/modules/userApi/renderer/preload.js index 8e9a52c9..c32787e9 100644 --- a/src/main/modules/userApi/renderer/preload.js +++ b/src/main/modules/userApi/renderer/preload.js @@ -1,5 +1,6 @@ const { contextBridge, ipcRenderer } = require('electron') const needle = require('needle') +const zlib = require('zlib') const { createCipheriv, publicEncrypt, constants, randomBytes, createHash } = require('crypto') const USER_API_RENDERER_EVENT_NAME = require('../rendererEvent/name') @@ -233,8 +234,26 @@ contextBridge.exposeInMainWorld('lx', { return Buffer.from(buf, 'binary').toString(format) }, }, + zlib: { + inflate(buf) { + return new Promise((resolve, reject) => { + zlib.inflate(buf, (err, data) => { + if (err) reject(new Error(err.message)) + else resolve(data) + }) + }) + }, + deflate(data) { + return new Promise((resolve, reject) => { + zlib.deflate(data, (err, buf) => { + if (err) reject(new Error(err.message)) + else resolve(buf) + }) + }) + }, + }, }, - version: '1.2.0', + version: '1.3.0', // removeEvent(eventName, handler) { // if (!eventNames.includes(eventName)) return Promise.reject(new Error('The event is not supported: ' + eventName)) // let handlers diff --git a/src/renderer/components/layout/PlayDetail/components/MusicComment/CommentFloor.vue b/src/renderer/components/layout/PlayDetail/components/MusicComment/CommentFloor.vue index 795caeaa..66cdf28a 100644 --- a/src/renderer/components/layout/PlayDetail/components/MusicComment/CommentFloor.vue +++ b/src/renderer/components/layout/PlayDetail/components/MusicComment/CommentFloor.vue @@ -14,8 +14,7 @@ div(:class="$style.container") svg(:class="$style.likesIcon" version='1.1' xmlns='http://www.w3.org/2000/svg' xlink='http://www.w3.org/1999/xlink' viewBox='0 0 512 512' space='preserve') use(xlink:href='#icon-thumbs-up') | {{item.likedCount}} - div.select(:class="$style.comment_text") - p(v-for="text in item.text") {{text}} + p.select(:class="$style.comment_text") {{item.text}} div(v-if="item.images?.length" :class="$style.comment_images") img(v-for="url in item.images" :src="url" loading="lazy" decoding="async") comment-floor(v-if="item.reply && item.reply.length" :class="$style.reply_floor" :comments="item.reply") @@ -121,11 +120,10 @@ export default { text-align: justify; font-size: 14px; padding-top: 5px; - p { - line-height: 1.5; - word-break: break-all; - overflow-wrap: break-word; - } + line-height: 1.5; + word-break: break-all; + overflow-wrap: break-word; + white-space: pre-wrap; } .comment_images { display: flex; diff --git a/src/renderer/core/music/utils.ts b/src/renderer/core/music/utils.ts index 4c133046..55d35567 100644 --- a/src/renderer/core/music/utils.ts +++ b/src/renderer/core/music/utils.ts @@ -266,7 +266,7 @@ export const getOnlineOtherSourcePicUrl = async({ musicInfos, onToggleSource, is let reqPromise try { - reqPromise = musicSdk[musicInfo.source].getPic(toOldMusicInfo(musicInfo)).promise + reqPromise = musicSdk[musicInfo.source].getPic(toOldMusicInfo(musicInfo)) } catch (err: any) { reqPromise = Promise.reject(err) } @@ -296,7 +296,7 @@ export const handleGetOnlinePicUrl = async({ musicInfo, isRefresh, onToggleSourc // console.log(musicInfo.source) let reqPromise try { - reqPromise = musicSdk[musicInfo.source].getPic(toOldMusicInfo(musicInfo)).promise + reqPromise = musicSdk[musicInfo.source].getPic(toOldMusicInfo(musicInfo)) } catch (err) { reqPromise = Promise.reject(err) } diff --git a/src/renderer/utils/musicSdk/bd/index.js b/src/renderer/utils/musicSdk/bd/index.js index de780c90..adc4d623 100644 --- a/src/renderer/utils/musicSdk/bd/index.js +++ b/src/renderer/utils/musicSdk/bd/index.js @@ -16,8 +16,7 @@ const bd = { }, getPic(songInfo) { const requestObj = this.getMusicInfo(songInfo) - requestObj.promise = requestObj.promise.then(info => info.pic_premium) - return requestObj + return requestObj.promise.then(info => info.pic_premium) }, getLyric(songInfo) { const requestObj = this.getMusicInfo(songInfo) diff --git a/src/renderer/utils/musicSdk/kg/comment.js b/src/renderer/utils/musicSdk/kg/comment.js index 6d2e0ea7..91f9fe0f 100644 --- a/src/renderer/utils/musicSdk/kg/comment.js +++ b/src/renderer/utils/musicSdk/kg/comment.js @@ -1,12 +1,6 @@ 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) -} +import { signatureParams } from './util' export default { _requestObj: null, @@ -16,8 +10,7 @@ export default { 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}`, { + const _requestObj = httpFetch(`http://m.comment.service.kugou.com/v1/cmtlist?${params}&signature=${signatureParams(params)}`, { headers: { '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', }, @@ -32,8 +25,7 @@ export default { if (this._requestObj2) this._requestObj2.cancelHttp() 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}`, { + const _requestObj2 = httpFetch(`http://m.comment.service.kugou.com/v1/weightlist?${params}&signature=${signatureParams(params)}`, { headers: { 'User-Agent': 'Android712-AndroidPhone-8983-18-0-COMMENT-wifi', }, @@ -65,7 +57,7 @@ export default { return rawList.map(item => { let data = { id: item.id, - text: decodeName(item.content || '').split('\n'), + text: decodeName(item.content || ''), images: item.images ? item.images.map(i => i.url) : [], location: item.location, time: item.addtime, @@ -81,7 +73,7 @@ export default { return item.pcontent ? { id: item.id, - text: decodeName(item.pcontent).split('\n'), + text: decodeName(item.pcontent), time: null, userName: item.puser, avatar: null, diff --git a/src/renderer/utils/musicSdk/kg/leaderboard.js b/src/renderer/utils/musicSdk/kg/leaderboard.js index 49fb17a5..1e6ad109 100644 --- a/src/renderer/utils/musicSdk/kg/leaderboard.js +++ b/src/renderer/utils/musicSdk/kg/leaderboard.js @@ -1,7 +1,7 @@ import { httpFetch } from '../../request' import { decodeName, formatPlayTime, sizeFormate } from '../../index' -let boardList = [{ id: 'kg__8888', name: '酷狗TOP500', bangid: '8888' }, { id: 'kg__6666', name: '酷狗飙升榜', bangid: '6666' }, { id: 'kg__37361', name: '酷狗雷达榜', bangid: '37361' }, { id: 'kg__23784', name: '网络红歌榜', bangid: '23784' }, { id: 'kg__24971', name: 'DJ热歌榜', bangid: '24971' }, { id: 'kg__35811', name: '会员专享热歌榜', bangid: '35811' }, { id: 'kg__31308', name: '华语新歌榜', bangid: '31308' }, { id: 'kg__31310', name: '欧美新歌榜', bangid: '31310' }, { id: 'kg__31311', name: '韩国新歌榜', bangid: '31311' }, { id: 'kg__31312', name: '日本新歌榜', bangid: '31312' }, { id: 'kg__31313', name: '粤语新歌榜', bangid: '31313' }, { id: 'kg__33162', name: 'ACG新歌榜', bangid: '33162' }, { id: 'kg__21101', name: '酷狗分享榜', bangid: '21101' }, { id: 'kg__30972', name: '腾讯音乐人原创榜', bangid: '30972' }, { id: 'kg__22603', name: '5sing音乐榜', bangid: '22603' }, { id: 'kg__33160', name: '电音热歌榜', bangid: '33160' }, { id: 'kg__21335', name: '繁星音乐榜', bangid: '21335' }, { id: 'kg__33161', name: '古风新歌榜', bangid: '33161' }, { id: 'kg__33163', name: '影视金曲榜', bangid: '33163' }, { id: 'kg__33166', name: '欧美金曲榜', bangid: '33166' }, { id: 'kg__33165', name: '粤语金曲榜', bangid: '33165' }, { id: 'kg__36107', name: '小语种热歌榜', bangid: '36107' }, { id: 'kg__4681', name: '美国BillBoard榜', bangid: '4681' }, { id: 'kg__4680', name: '英国单曲榜', bangid: '4680' }, { id: 'kg__4673', name: '日本公信榜', bangid: '4673' }, { id: 'kg__38623', name: '韩国Melon音乐榜', bangid: '38623' }, { id: 'kg__42807', name: 'joox本地热歌榜', bangid: '42807' }, { id: 'kg__42808', name: '台湾KKBOX风云榜', bangid: '42808' }] +let boardList = [{ id: 'kg__8888', name: 'TOP500', bangid: '8888' }, { id: 'kg__6666', name: '飙升榜', bangid: '6666' }, { id: 'kg__59703', name: '蜂鸟流行音乐榜', bangid: '59703' }, { id: 'kg__52144', name: '抖音热歌榜', bangid: '52144' }, { id: 'kg__52767', name: '快手热歌榜', bangid: '52767' }, { id: 'kg__24971', name: 'DJ热歌榜', bangid: '24971' }, { id: 'kg__23784', name: '网络红歌榜', bangid: '23784' }, { id: 'kg__44412', name: '说唱先锋榜', bangid: '44412' }, { id: 'kg__31308', name: '内地榜', bangid: '31308' }, { id: 'kg__33160', name: '电音榜', bangid: '33160' }, { id: 'kg__31313', name: '香港地区榜', bangid: '31313' }, { id: 'kg__51341', name: '民谣榜', bangid: '51341' }, { id: 'kg__54848', name: '台湾地区榜', bangid: '54848' }, { id: 'kg__31310', name: '欧美榜', bangid: '31310' }, { id: 'kg__33162', name: 'ACG新歌榜', bangid: '33162' }, { id: 'kg__31311', name: '韩国榜', bangid: '31311' }, { id: 'kg__31312', name: '日本榜', bangid: '31312' }, { id: 'kg__49225', name: '80后热歌榜', bangid: '49225' }, { id: 'kg__49223', name: '90后热歌榜', bangid: '49223' }, { id: 'kg__49224', name: '00后热歌榜', bangid: '49224' }, { id: 'kg__33165', name: '粤语金曲榜', bangid: '33165' }, { id: 'kg__33166', name: '欧美金曲榜', bangid: '33166' }, { id: 'kg__33163', name: '影视金曲榜', bangid: '33163' }, { id: 'kg__51340', name: '伤感榜', bangid: '51340' }, { id: 'kg__35811', name: '会员专享榜', bangid: '35811' }, { id: 'kg__37361', name: '雷达榜', bangid: '37361' }, { id: 'kg__21101', name: '分享榜', bangid: '21101' }, { id: 'kg__46910', name: '综艺新歌榜', bangid: '46910' }, { id: 'kg__30972', name: '酷狗音乐人原创榜', bangid: '30972' }, { id: 'kg__60170', name: '闽南语榜', bangid: '60170' }, { id: 'kg__65234', name: '儿歌榜', bangid: '65234' }, { id: 'kg__4681', name: '美国BillBoard榜', bangid: '4681' }, { id: 'kg__25028', name: 'Beatport电子舞曲榜', bangid: '25028' }, { id: 'kg__4680', name: '英国单曲榜', bangid: '4680' }, { id: 'kg__38623', name: '韩国Melon音乐榜', bangid: '38623' }, { id: 'kg__42807', name: 'joox本地热歌榜', bangid: '42807' }, { id: 'kg__36107', name: '小语种热歌榜', bangid: '36107' }, { id: 'kg__4673', name: '日本公信榜', bangid: '4673' }, { id: 'kg__46868', name: '日本SPACE SHOWER榜', bangid: '46868' }, { id: 'kg__42808', name: 'KKBOX风云榜', bangid: '42808' }, { id: 'kg__60171', name: '越南语榜', bangid: '60171' }, { id: 'kg__60172', name: '泰语榜', bangid: '60172' }, { id: 'kg__59895', name: 'R&B榜', bangid: '59895' }, { id: 'kg__59896', name: '摇滚榜', bangid: '59896' }, { id: 'kg__59897', name: '爵士榜', bangid: '59897' }, { id: 'kg__59898', name: '乡村音乐榜', bangid: '59898' }, { id: 'kg__59900', name: '纯音乐榜', bangid: '59900' }, { id: 'kg__59899', name: '古典榜', bangid: '59899' }, { id: 'kg__22603', name: '5sing音乐榜', bangid: '22603' }, { id: 'kg__21335', name: '繁星音乐榜', bangid: '21335' }, { id: 'kg__33161', name: '古风新歌榜', bangid: '33161' }] export default { listDetailLimit: 100, @@ -74,7 +74,7 @@ export default { _requestBoardsObj: null, getBoardsData() { if (this._requestBoardsObj) this._requestBoardsObj.cancelHttp() - this._requestBoardsObj = httpFetch('http://mobilecdnbj.kugou.com/api/v3/rank/list?version=9108&plat=0&showtype=2&parentid=0&apiver=6&area_code=1&withsong=1') + this._requestBoardsObj = httpFetch('http://mobilecdnbj.kugou.com/api/v5/rank/list?version=9108&plat=0&showtype=2&parentid=0&apiver=6&area_code=1&withsong=1') return this._requestBoardsObj.promise }, getData(url) { @@ -168,7 +168,8 @@ export default { // // console.log(response.body) // if (response.statusCode !== 200 || response.body.errcode !== 0) return this.getBoards(retryNum) // const list = this.filterBoardsData(response.body.data.info) - // // console.log(list) + // console.log(list) + // // console.log(JSON.stringify(list)) // this.list = list // return { // list, diff --git a/src/renderer/utils/musicSdk/kg/pic.js b/src/renderer/utils/musicSdk/kg/pic.js index 5d9c262d..fdb40175 100644 --- a/src/renderer/utils/musicSdk/kg/pic.js +++ b/src/renderer/utils/musicSdk/kg/pic.js @@ -37,13 +37,12 @@ export default { }, }, ) - requestObj.promise = requestObj.promise.then(({ body }) => { + return requestObj.promise.then(({ body }) => { if (body.error_code !== 0) return Promise.reject('图片获取失败') let info = body.data[0].info const img = info.imgsize ? info.image.replace('{size}', info.imgsize[0]) : info.image if (!img) return Promise.reject('Pic get failed') return img }) - return requestObj }, } diff --git a/src/renderer/utils/musicSdk/kg/songList.js b/src/renderer/utils/musicSdk/kg/songList.js index 55ca6cf5..7d8cdc35 100644 --- a/src/renderer/utils/musicSdk/kg/songList.js +++ b/src/renderer/utils/musicSdk/kg/songList.js @@ -1,7 +1,7 @@ import { httpFetch } from '../../request' import { decodeName, formatPlayTime, sizeFormate, dateFormat } from '../../index' -import { toMD5 } from '../utils' import infSign from './vendors/infSign.min' +import { signatureParams } from './util' const handleSignature = (id, page, limit) => new Promise((resolve, reject) => { infSign({ appid: 1058, type: 0, module: 'playlist', page, pagesize: limit, specialid: id }, null, { @@ -52,6 +52,73 @@ export default { // https://www.kugou.com/yy/special/single/1067062.html listDetailLink: /^.+\/(\d+)\.html(?:\?.*|&.*$|#.*$|$)/, }, + async getGlobalSpecialId(specialId) { + return httpFetch(`https://m.kugou.com/plist/list/${specialId}/?json=true`, { + headers: { + 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; HLK-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Mobile Safari/537.36 EdgA/104.0.1293.70', + }, + follow_max: 2, + }).promise.then(({ body }) => { + // console.log(body) + if (!body.info.list.global_specialid) Promise.reject(new Error('Failed to get global collection id.')) + return body.info.list.global_specialid + }) + }, + // async getListInfoBySpecialId(special_id, retry = 0) { + // if (++retry > 2) throw new Error('failed') + // return httpFetch(`https://m.kugou.com/plist/list/${special_id}/?json=true`, { + // headers: { + // 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; HLK-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Mobile Safari/537.36 EdgA/104.0.1293.70', + // }, + // follow_max: 2, + // }).promise.then(({ body }) => { + // // console.log(body) + // if (!body.info.list) return this.getListInfoBySpecialId(special_id, retry) + // let listinfo = body.info.list + // return { + // listInfo: { + // name: listinfo.specialname, + // image: listinfo.imgurl.replace('{size}', '150'), + // intro: listinfo.intro, + // author: listinfo.nickname, + // playcount: listinfo.playcount, + // total: listinfo.songcount, + // }, + // globalSpecialId: listinfo.global_specialid, + // } + // }) + // }, + // async getSongListDetailByGlobalSpecialId(id, page, limit = 100, retry = 0) { + // if (++retry > 2) throw new Error('failed') + // console.log(id) + // const params = `specialid=0&need_sort=1&module=CloudMusic&clientver=11409&pagesize=${limit}&global_collection_id=${id}&userid=0&page=${page}&type=1&area_code=1&appid=1005` + // return httpFetch(`http://pubsongscdn.tx.kugou.com/v2/get_other_list_file?${params}&signature=${signatureParams(params)}`).promise.then(({ body }) => { + // // console.log(body) + // if (body.data?.info == null) return this.getSongListDetailByGlobalSpecialId(id, page, limit, retry) + // return body.data.info + // }) + // }, + async getListDetailBySpecialId(id) { + const globalSpecialId = await this.getGlobalSpecialId(id) + // const limit = 100 + // const listData = await this.getSongListDetailByGlobalSpecialId(globalSpecialId, page, limit) + // if (!Array.isArray(listData)) + return this.getUserListDetail2(globalSpecialId) + // return { + // list: this.filterDatav9(listData), + // page, + // limit, + // total: listInfo.total, + // source: 'kg', + // info: { + // name: listInfo.name, + // img: listInfo.image, + // desc: listInfo.intro, + // author: listInfo.author, + // play_count: this.formatPlayCount(listInfo.playcount), + // }, + // } + }, getInfoUrl(tagId) { return tagId ? `http://www2.kugou.kugou.com/yueku/v9/special/getSpecial?is_smarty=1&cdn=cdn&t=5&c=${tagId}` @@ -61,9 +128,9 @@ export default { if (tagId == null) tagId = '' return `http://www2.kugou.kugou.com/yueku/v9/special/getSpecial?is_ajax=1&cdn=cdn&t=${sortId}&c=${tagId}&p=${page}` }, - getSongListDetailUrl(id) { - return `http://www2.kugou.kugou.com/yueku/v9/special/single/${id}-5-9999.html` - }, + // getSongListDetailUrl(id) { + // return `http://www2.kugou.kugou.com/yueku/v9/special/single/${id}-5-9999.html` + // }, /** * 格式化播放数量 @@ -222,8 +289,17 @@ export default { body: { appid: 1001, clientver: 9020, mid: '21511157a05844bd085308bc76ef3343', clienttime: 640612895, key: '36164c4015e704673c588ee202b9ecb8', data: id }, }) // console.log(songInfo) + // type 1单曲,2歌单,3电台,4酷狗码,5别人的播放队列 let songList let info = songInfo.info + switch (info.type) { + case 2: + if (!info.global_collection_id) return this.getListDetailBySpecialId(info.id) + break + + default: + break + } if (info.global_collection_id) return this.getUserListDetail2(info.global_collection_id) if (info.userid != null) { songList = await this.createHttp('http://www2.kugou.kugou.com/apps/kucodeAndShare/app/', { @@ -332,7 +408,8 @@ export default { const limit = total > 300 ? 300 : total total -= limit page += 1 - tasks.push(this.createHttp('https://mobiles.kugou.com/api/v5/special/song_v2?appid=1058&global_specialid=' + id + '&specialid=0&plat=0&version=8000&page=' + page + '&pagesize=' + limit + '&srcappid=2919&clientver=20000&clienttime=1586163263991&mid=1586163263991&uuid=1586163263991&dfid=-&signature=' + toMD5('NVPh5oo715z5DIWAeQlhMDsWXXQV4hwtappid=1058clienttime=1586163263991clientver=20000dfid=-global_specialid=' + id + 'mid=1586163263991page=' + page + 'pagesize=' + limit + 'plat=0specialid=0srcappid=2919uuid=1586163263991version=8000NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt'), { + const params = 'appid=1058&global_specialid=' + id + '&specialid=0&plat=0&version=8000&page=' + page + '&pagesize=' + limit + '&srcappid=2919&clientver=20000&clienttime=1586163263991&mid=1586163263991&uuid=1586163263991&dfid=-' + tasks.push(this.createHttp(`https://mobiles.kugou.com/api/v5/special/song_v2?${params}&signature=${signatureParams(params, 5)}`, { headers: { mid: '1586163263991', Referer: 'https://m3ws.kugou.com/share/index.php', @@ -347,7 +424,8 @@ export default { async getUserListDetail2(global_collection_id) { let id = global_collection_id if (id.length > 1000) throw new Error('get list error') - let info = await this.createHttp('https://mobiles.kugou.com/api/v5/special/info_v2?appid=1058&specialid=0&global_specialid=' + id + '&format=jsonp&srcappid=2919&clientver=20000&clienttime=1586163242519&mid=1586163242519&uuid=1586163242519&dfid=-&signature=' + toMD5('NVPh5oo715z5DIWAeQlhMDsWXXQV4hwtappid=1058clienttime=1586163242519clientver=20000dfid=-format=jsonpglobal_specialid=' + id + 'mid=1586163242519specialid=0srcappid=2919uuid=1586163242519NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt'), { + const params = 'appid=1058&specialid=0&global_specialid=' + id + '&format=jsonp&srcappid=2919&clientver=20000&clienttime=1586163242519&mid=1586163242519&uuid=1586163242519&dfid=-' + let info = await this.createHttp(`https://mobiles.kugou.com/api/v5/special/info_v2?${params}&signature=${signatureParams(params, 5)}`, { headers: { mid: '1586163242519', Referer: 'https://m3ws.kugou.com/share/index.php', @@ -358,7 +436,7 @@ export default { }) const songInfo = await this.createGetListDetail2Task(id, info.songcount) let result = await Promise.all(this.createTask(this.deDuplication(songInfo).map(item => ({ hash: item.hash })))).then(([...datas]) => datas.flat()) - // console.log(info, songInfo) + // console.log(info, songInfo, result) return { list: this.filterData2(result) || [], page: 1, @@ -511,9 +589,7 @@ export default { return this.getUserListDetailByLink(body, link) }, - getListDetail(id, page, tryNum = 0) { // 获取歌曲列表内的音乐 - if (tryNum > 2) return Promise.reject(new Error('try max num')) - + async getListDetail(id, page) { // 获取歌曲列表内的音乐 id = id.toString() if (id.includes('special/single/')) { id = id.replace(this.regExps.listDetailLink, '$1') @@ -525,36 +601,9 @@ export default { } else if (id.startsWith('id_')) { id = id.replace('id_', '') } - // if ((/[?&:/]/.test(id))) id = id.replace(this.regExps.listDetailLink, '$1') - const requestObj_listDetail = httpFetch(this.getSongListDetailUrl(id)) - return requestObj_listDetail.promise.then(({ body }) => { - let listData = body.match(this.regExps.listData) - let listInfo = body.match(this.regExps.listInfo) - if (!listData) return this.getListDetail(id, page, ++tryNum) - listData = this.filterData(JSON.parse(listData[1])) - let name - let pic - if (listInfo) { - name = listInfo[1] - pic = listInfo[2] - } - return { - list: listData, - page: 1, - limit: 10000, - total: listData.length, - source: 'kg', - info: { - name, - img: pic, - // desc: body.result.info.list_desc, - // author: body.result.info.userinfo.username, - // play_count: this.formatPlayCount(body.result.listen_num), - }, - } - }) + return this.getListDetailBySpecialId(id, page) }, filterData(rawList) { // console.log(rawList) @@ -610,6 +659,68 @@ export default { } }) }, + // getSinger(singers) { + // let arr = [] + // singers?.forEach(singer => { + // arr.push(singer.name) + // }) + // return arr.join('、') + // }, + // v9 API + // filterDatav9(rawList) { + // console.log(rawList) + // return rawList.map(item => { + // const types = [] + // const _types = {} + // item.relate_goods.forEach(qualityObj => { + // if (qualityObj.level === 2) { + // let size = sizeFormate(qualityObj.size) + // types.push({ type: '128k', size, hash: qualityObj.hash }) + // _types['128k'] = { + // size, + // hash: qualityObj.hash, + // } + // } else if (qualityObj.level === 4) { + // let size = sizeFormate(qualityObj.size) + // types.push({ type: '320k', size, hash: qualityObj.hash }) + // _types['320k'] = { + // size, + // hash: qualityObj.hash, + // } + // } else if (qualityObj.level === 5) { + // let size = sizeFormate(qualityObj.size) + // types.push({ type: 'flac', size, hash: qualityObj.hash }) + // _types.flac = { + // size, + // hash: qualityObj.hash, + // } + // } else if (qualityObj.level === 6) { + // let size = sizeFormate(qualityObj.size) + // types.push({ type: 'flac24bit', size, hash: qualityObj.hash }) + // _types.flac24bit = { + // size, + // hash: qualityObj.hash, + // } + // } + // }) + // const nameInfo = item.name.split(' - ') + // return { + // singer: this.getSinger(item.singerinfo), + // name: decodeName((nameInfo[1] ?? nameInfo[0]).trim()), + // albumName: decodeName(item.albuminfo.name), + // albumId: item.albuminfo.id, + // songmid: item.audio_id, + // source: 'kg', + // interval: formatPlayTime(item.timelen / 1000), + // img: null, + // lrc: null, + // hash: item.hash, + // types, + // _types, + // typeUrl: {}, + // } + // }) + // }, // hash list filter filterData2(rawList) { @@ -646,6 +757,14 @@ export default { hash: item.audio_info.hash_flac, } } + if (item.audio_info.filesize_high !== '0') { + let size = sizeFormate(parseInt(item.audio_info.filesize_high)) + types.push({ type: 'flac24bit', size, hash: item.audio_info.hash_high }) + _types.flac24bit = { + size, + hash: item.audio_info.hash_high, + } + } list.push({ singer: decodeName(item.author_name), name: decodeName(item.ori_audio_name), diff --git a/src/renderer/utils/musicSdk/kg/util.js b/src/renderer/utils/musicSdk/kg/util.js index 73b5e743..6475f175 100644 --- a/src/renderer/utils/musicSdk/kg/util.js +++ b/src/renderer/utils/musicSdk/kg/util.js @@ -1,4 +1,5 @@ import { inflate } from 'zlib' +import { toMD5 } from '../utils' // https://github.com/lyswhut/lx-music-desktop/issues/296#issuecomment-683285784 const enc_key = Buffer.from([0x40, 0x47, 0x61, 0x77, 0x5e, 0x32, 0x74, 0x47, 0x51, 0x36, 0x31, 0x2d, 0xce, 0xd2, 0x6e, 0x69], 'binary') @@ -17,3 +18,12 @@ export const decodeLyric = str => new Promise((resolve, reject) => { // s.content[0].lyricContent.forEach(([str]) => { // console.log(str) // }) + +export const signatureParams = (params, apiver = 9) => { + let keyparam = 'OIlwieks28dk2k092lksi2UIkp' + if (apiver === 5) keyparam = 'NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt' + let param_list = params.split('&') + param_list.sort() + let sign_params = `${keyparam}${param_list.join('')}${keyparam}` + return toMD5(sign_params) +} diff --git a/src/renderer/utils/musicSdk/kw/comment.js b/src/renderer/utils/musicSdk/kw/comment.js index 287a376e..0559d683 100644 --- a/src/renderer/utils/musicSdk/kw/comment.js +++ b/src/renderer/utils/musicSdk/kw/comment.js @@ -35,7 +35,7 @@ export default { return rawList.map(item => { let data = { id: item.id, - text: item.msg.split('\n'), + text: item.msg, time: item.time, timeStr: dateFormat2(new Date(item.time).getTime()), userName: decodeURIComponent(item.u_name), @@ -48,7 +48,7 @@ export default { ? { id: item.id, rootId: item.reply.id, - text: item.reply.msg.split('\n'), + text: item.reply.msg, time: item.reply.time, timeStr: dateFormat2(new Date(item.reply.time).getTime()), userName: decodeURIComponent(item.reply.u_name), diff --git a/src/renderer/utils/musicSdk/kw/leaderboard.js b/src/renderer/utils/musicSdk/kw/leaderboard.js index 7c064c7b..0c639bfb 100644 --- a/src/renderer/utils/musicSdk/kw/leaderboard.js +++ b/src/renderer/utils/musicSdk/kw/leaderboard.js @@ -2,7 +2,7 @@ import { httpFetch } from '../../request' import { formatPlayTime, decodeName } from '../../index' import { formatSinger } from './util' -const boardList = [{ id: 'kw__93', name: '酷我飙升榜', bangid: '93' }, { id: 'kw__17', name: '酷我新歌榜', bangid: '17' }, { id: 'kw__16', name: '酷我热歌榜', bangid: '16' }, { id: 'kw__158', name: '抖音热歌榜', bangid: '158' }, { id: 'kw__284', name: '酷我热评榜', bangid: '284' }, { id: 'kw__290', name: 'ACG新歌榜', bangid: '290' }, { id: 'kw__286', name: '台湾KKBOX榜', bangid: '286' }, { id: 'kw__279', name: '春日浅唱榜', bangid: '279' }, { id: 'kw__281', name: '巴士随身听榜', bangid: '281' }, { id: 'kw__255', name: 'KTV点唱榜', bangid: '255' }, { id: 'kw__280', name: '家务进行曲榜', bangid: '280' }, { id: 'kw__282', name: '熬夜修仙榜', bangid: '282' }, { id: 'kw__283', name: '枕边轻音乐榜', bangid: '283' }, { id: 'kw__278', name: '古风音乐榜', bangid: '278' }, { id: 'kw__264', name: 'Vlog音乐榜', bangid: '264' }, { id: 'kw__242', name: '酷我电音榜', bangid: '242' }, { id: 'kw__187', name: '流行趋势榜', bangid: '187' }, { id: 'kw__204', name: '现场音乐榜', bangid: '204' }, { id: 'kw__186', name: 'ACG神曲榜', bangid: '186' }, { id: 'kw__185', name: '最强翻唱榜', bangid: '185' }, { id: 'kw__26', name: '经典怀旧榜', bangid: '26' }, { id: 'kw__104', name: '酷我华语榜', bangid: '104' }, { id: 'kw__182', name: '酷我粤语榜', bangid: '182' }, { id: 'kw__22', name: '酷我欧美榜', bangid: '22' }, { id: 'kw__184', name: '酷我韩语榜', bangid: '184' }, { id: 'kw__183', name: '酷我日语榜', bangid: '183' }, { id: 'kw__145', name: '会员畅听榜', bangid: '145' }, { id: 'kw__153', name: '网红新歌榜', bangid: '153' }, { id: 'kw__64', name: '影视金曲榜', bangid: '64' }, { id: 'kw__176', name: 'DJ嗨歌榜', bangid: '176' }, { id: 'kw__106', name: '酷我真声音', bangid: '106' }, { id: 'kw__12', name: 'Billboard榜', bangid: '12' }, { id: 'kw__49', name: 'iTunes音乐榜', bangid: '49' }, { id: 'kw__180', name: 'beatport电音榜', bangid: '180' }, { id: 'kw__13', name: '英国UK榜', bangid: '13' }, { id: 'kw__164', name: '百大DJ榜', bangid: '164' }, { id: 'kw__246', name: 'YouTube音乐排行榜', bangid: '246' }, { id: 'kw__265', name: '韩国Genie榜', bangid: '265' }, { id: 'kw__14', name: '韩国M-net榜', bangid: '14' }, { id: 'kw__8', name: '香港电台榜', bangid: '8' }, { id: 'kw__15', name: '日本公信榜', bangid: '15' }, { id: 'kw__151', name: '腾讯音乐人原创榜', bangid: '151' }] +const boardList = [{ id: 'kw__93', name: '酷我飙升榜', bangid: '93' }, { id: 'kw__17', name: '酷我新歌榜', bangid: '17' }, { id: 'kw__16', name: '酷我热歌榜', bangid: '16' }, { id: 'kw__158', name: '抖音热歌榜', bangid: '158' }, { id: 'kw__292', name: '酷我铃声榜', bangid: '292' }, { id: 'kw__284', name: '酷我热评榜', bangid: '284' }, { id: 'kw__290', name: 'ACG新歌榜', bangid: '290' }, { id: 'kw__286', name: '台湾KKBOX榜', bangid: '286' }, { id: 'kw__279', name: '冬日暖心榜', bangid: '279' }, { id: 'kw__281', name: '巴士随身听榜', bangid: '281' }, { id: 'kw__255', name: 'KTV点唱榜', bangid: '255' }, { id: 'kw__280', name: '家务进行曲榜', bangid: '280' }, { id: 'kw__282', name: '熬夜修仙榜', bangid: '282' }, { id: 'kw__283', name: '枕边轻音乐榜', bangid: '283' }, { id: 'kw__278', name: '古风音乐榜', bangid: '278' }, { id: 'kw__264', name: 'Vlog音乐榜', bangid: '264' }, { id: 'kw__242', name: '酷我电音榜', bangid: '242' }, { id: 'kw__187', name: '流行趋势榜', bangid: '187' }, { id: 'kw__204', name: '现场音乐榜', bangid: '204' }, { id: 'kw__186', name: 'ACG神曲榜', bangid: '186' }, { id: 'kw__185', name: '最强翻唱榜', bangid: '185' }, { id: 'kw__26', name: '经典怀旧榜', bangid: '26' }, { id: 'kw__104', name: '酷我华语榜', bangid: '104' }, { id: 'kw__182', name: '酷我粤语榜', bangid: '182' }, { id: 'kw__22', name: '酷我欧美榜', bangid: '22' }, { id: 'kw__184', name: '酷我韩语榜', bangid: '184' }, { id: 'kw__183', name: '酷我日语榜', bangid: '183' }, { id: 'kw__145', name: '会员畅听榜', bangid: '145' }, { id: 'kw__153', name: '网红新歌榜', bangid: '153' }, { id: 'kw__64', name: '影视金曲榜', bangid: '64' }, { id: 'kw__176', name: 'DJ嗨歌榜', bangid: '176' }, { id: 'kw__106', name: '酷我真声音', bangid: '106' }, { id: 'kw__12', name: 'Billboard榜', bangid: '12' }, { id: 'kw__49', name: 'iTunes音乐榜', bangid: '49' }, { id: 'kw__180', name: 'beatport电音榜', bangid: '180' }, { id: 'kw__13', name: '英国UK榜', bangid: '13' }, { id: 'kw__164', name: '百大DJ榜', bangid: '164' }, { id: 'kw__246', name: 'YouTube音乐排行榜', bangid: '246' }, { id: 'kw__265', name: '韩国Genie榜', bangid: '265' }, { id: 'kw__14', name: '韩国M-net榜', bangid: '14' }, { id: 'kw__8', name: '香港电台榜', bangid: '8' }, { id: 'kw__15', name: '日本公信榜', bangid: '15' }, { id: 'kw__151', name: '腾讯音乐人原创榜', bangid: '151' }] export default { list: [ diff --git a/src/renderer/utils/musicSdk/kw/pic.js b/src/renderer/utils/musicSdk/kw/pic.js index 7263a518..9f1ea7a1 100644 --- a/src/renderer/utils/musicSdk/kw/pic.js +++ b/src/renderer/utils/musicSdk/kw/pic.js @@ -4,6 +4,6 @@ export default { getPic({ songmid }) { const requestObj = httpFetch(`http://artistpicserver.kuwo.cn/pic.web?corp=kuwo&type=rid_pic&pictype=500&size=500&rid=${songmid}`) requestObj.promise = requestObj.promise.then(({ body }) => /^http/.test(body) ? body : null) - return requestObj + return requestObj.promise }, } diff --git a/src/renderer/utils/musicSdk/mg/album.js b/src/renderer/utils/musicSdk/mg/album.js index 625fc3ac..a41c95cb 100644 --- a/src/renderer/utils/musicSdk/mg/album.js +++ b/src/renderer/utils/musicSdk/mg/album.js @@ -2,19 +2,7 @@ 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', - }, - }) + let requestObj = httpFetch(`http://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/queryAlbumSong?albumId=${songInfo.albumId}&pageNo=1`) requestObj.promise = requestObj.promise.then(({ body }) => { if (body.code !== '000000') { if (tryNum > 5) return Promise.reject('获取专辑失败') @@ -22,7 +10,7 @@ export default { requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj) return tryRequestObj.promise } - console.log(body) + // console.log(body) return body.songList }) return requestObj diff --git a/src/renderer/utils/musicSdk/mg/comment.js b/src/renderer/utils/musicSdk/mg/comment.js index a5b6b08a..9fcdde9e 100644 --- a/src/renderer/utils/musicSdk/mg/comment.js +++ b/src/renderer/utils/musicSdk/mg/comment.js @@ -1,25 +1,15 @@ import { httpFetch } from '../../request' -import album from './album' +import getSongId from './songId' import { dateFormat2 } from '../../index' 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 = 10) { if (this._requestObj) this._requestObj.cancelHttp() if (!musicInfo.songId) { - let id = await this.getSongId(musicInfo) + let id = await getSongId(musicInfo) if (!id) throw new Error('获取评论失败') musicInfo.songId = id } @@ -39,7 +29,7 @@ export default { if (this._requestObj2) this._requestObj2.cancelHttp() if (!musicInfo.songId) { - let id = await this.getSongId(musicInfo) + let id = await getSongId(musicInfo) if (!id) throw new Error('获取评论失败') musicInfo.songId = id } @@ -71,7 +61,7 @@ export default { filterComment(rawList) { return rawList.map(item => ({ id: item.commentId, - text: item.body.split('\n'), + text: item.body, time: item.createTime, timeStr: dateFormat2(new Date(item.createTime).getTime()), userName: item.author.name, @@ -81,7 +71,7 @@ export default { replyNum: item.replyTotal, reply: item.replyCommentList.map(c => ({ id: c.commentId, - text: c.body.split('\n'), + text: c.body, time: c.createTime, timeStr: dateFormat2(new Date(c.createTime).getTime()), userName: c.author.name, diff --git a/src/renderer/utils/musicSdk/mg/hotSearch.js b/src/renderer/utils/musicSdk/mg/hotSearch.js index 70691847..4f055709 100644 --- a/src/renderer/utils/musicSdk/mg/hotSearch.js +++ b/src/renderer/utils/musicSdk/mg/hotSearch.js @@ -6,13 +6,13 @@ export default { if (this._requestObj) this._requestObj.cancelHttp() if (retryNum > 2) return Promise.reject(new Error('try max num')) - const _requestObj = httpFetch('http://jadeite.migu.cn:7090/music_search/v2/search/hotword') + const _requestObj = httpFetch('http://jadeite.migu.cn:7090/music_search/v3/search/hotword') const { body, statusCode } = await _requestObj.promise if (statusCode != 200 || body.code !== '000000') throw new Error('获取热搜词失败') // console.log(body, statusCode) - return { source: 'mg', list: this.filterList(body.data) } + return { source: 'mg', list: this.filterList(body.data.hotwords[0].hotwordList) } }, filterList(rawList) { - return rawList.map(item => item.word) + return rawList.filter(item => item.resourceType == 'song').map(item => item.word) }, } diff --git a/src/renderer/utils/musicSdk/mg/leaderboard.js b/src/renderer/utils/musicSdk/mg/leaderboard.js index 8a6733da..9905884d 100644 --- a/src/renderer/utils/musicSdk/mg/leaderboard.js +++ b/src/renderer/utils/musicSdk/mg/leaderboard.js @@ -1,5 +1,5 @@ import { httpFetch } from '../../request' -import { sizeFormate } from '../../index' +import { filterMusicInfoData } from './musicInfo' // const boardList = [{ id: 'mg__27553319', name: '咪咕尖叫新歌榜', bangid: '27553319' }, { id: 'mg__27186466', name: '咪咕尖叫热歌榜', bangid: '27186466' }, { id: 'mg__27553408', name: '咪咕尖叫原创榜', bangid: '27553408' }, { id: 'mg__23189800', name: '咪咕港台榜', bangid: '23189800' }, { id: 'mg__23189399', name: '咪咕内地榜', bangid: '23189399' }, { id: 'mg__19190036', name: '咪咕欧美榜', bangid: '19190036' }, { id: 'mg__23189813', name: '咪咕日韩榜', bangid: '23189813' }, { id: 'mg__23190126', name: '咪咕彩铃榜', bangid: '23190126' }, { id: 'mg__15140045', name: '咪咕KTV榜', bangid: '15140045' }, { id: 'mg__15140034', name: '咪咕网络榜', bangid: '15140034' }, { id: 'mg__23217754', name: 'MV榜', bangid: '23217754' }, { id: 'mg__23218151', name: '新专辑榜', bangid: '23218151' }, { id: 'mg__21958042', name: 'iTunes榜', bangid: '21958042' }, { id: 'mg__21975570', name: 'billboard榜', bangid: '21975570' }, { id: 'mg__22272815', name: '台湾Hito中文榜', bangid: '22272815' }, { id: 'mg__22272904', name: '中国TOP排行榜', bangid: '22272904' }, { id: 'mg__22272943', name: '韩国Melon榜', bangid: '22272943' }, { id: 'mg__22273437', name: '英国UK榜', bangid: '22273437' }] @@ -81,83 +81,6 @@ export default { const requestObj = httpFetch(url) return requestObj.promise }, - getSinger(singers) { - let arr = [] - singers.forEach(singer => { - arr.push(singer.name) - }) - return arr.join('、') - }, - filterData(rawData) { - // console.log(JSON.stringify(rawData)) - // console.log(rawData) - let ids = new Set() - const list = [] - rawData.forEach(({ objectInfo: item }) => { - if (ids.has(item.copyrightId)) return - ids.add(item.copyrightId) - - const types = [] - const _types = {} - item.newRateFormats && item.newRateFormats.forEach(type => { - let size - switch (type.formatType) { - case 'PQ': - size = sizeFormate(type.size ?? type.androidSize) - types.push({ type: '128k', size }) - _types['128k'] = { - size, - } - break - case 'HQ': - size = sizeFormate(type.size ?? type.androidSize) - types.push({ type: '320k', size }) - _types['320k'] = { - size, - } - break - case 'SQ': - size = sizeFormate(type.size ?? type.androidSize) - types.push({ type: 'flac', size }) - _types.flac = { - size, - } - break - case 'ZQ': - size = sizeFormate(type.size ?? type.androidSize) - types.push({ type: 'flac24bit', size }) - _types.flac24bit = { - size, - } - break - } - }) - - const intervalTest = /(\d\d:\d\d)$/.test(item.length) - - list.push({ - singer: this.getSinger(item.artists), - name: item.songName, - albumName: item.album, - albumId: item.albumId, - songmid: item.copyrightId, - songId: item.songId, - copyrightId: item.copyrightId, - source: 'mg', - interval: intervalTest ? RegExp.$1 : null, - img: item.albumImgs && item.albumImgs.length ? item.albumImgs[0].img : null, - lrc: null, - lrcUrl: item.lrcUrl, - mrcUrl: item.mrcUrl, - trcUrl: item.trcUrl, - otherSource: null, - types, - _types, - typeUrl: {}, - }) - }) - return list - }, filterBoardsData(rawList) { // console.log(rawList) let list = [] @@ -205,7 +128,7 @@ export default { return this.getData(this.getUrl(bangid, page)).then(({ statusCode, body }) => { // console.log(body) if (statusCode !== 200 || body.code !== this.successCode) return this.getList(bangid, page, retryNum) - const list = this.filterData(body.columnInfo.contents) + const list = filterMusicInfoData(body.columnInfo.contents.map(m => m.objectInfo)) return { total: list.length, list, diff --git a/src/renderer/utils/musicSdk/mg/leaderboard2.js b/src/renderer/utils/musicSdk/mg/leaderboard2.js index d5685e56..14fc6ae5 100644 --- a/src/renderer/utils/musicSdk/mg/leaderboard2.js +++ b/src/renderer/utils/musicSdk/mg/leaderboard2.js @@ -116,8 +116,7 @@ export default { name: item.name, albumName: item.album && item.album.albumName, albumId: item.album && item.album.albumId, - songmid: item.copyrightId, - songId: item.id, + songmid: item.id, copyrightId: item.copyrightId, source: 'mg', interval: item.duration ? formatPlayTime(this.getIntv(item.duration)) : null, diff --git a/src/renderer/utils/musicSdk/mg/lyric.js b/src/renderer/utils/musicSdk/mg/lyric.js index fc75e8e5..540a2e9e 100644 --- a/src/renderer/utils/musicSdk/mg/lyric.js +++ b/src/renderer/utils/musicSdk/mg/lyric.js @@ -1,5 +1,5 @@ import { httpFetch } from '../../request' -import musicSearch from './musicSearch' +import { getMusicInfo } from './musicInfo' import { decrypt } from './mrc' const mrcTools = { @@ -75,11 +75,8 @@ const mrcTools = { }, getMusicInfo(songInfo) { return songInfo.mrcUrl == null - ? musicSearch.search(`${songInfo.name} ${songInfo.singer || ''}`.trim(), 1, { limit: 25 }).then(({ list }) => { - const targetSong = list.find(s => s.songmid == songInfo.songmid) - return targetSong ? { lrcUrl: targetSong.lrcUrl, mrcUrl: targetSong.mrcUrl, trcUrl: targetSong.trcUrl } : Promise.reject('获取歌词失败') - }) - : Promise.resolve({ lrcUrl: songInfo.lrcUrl, mrcUrl: songInfo.mrcUrl, trcUrl: songInfo.trcUrl }) + ? getMusicInfo(songInfo.copyrightId) + : songInfo }, getLyric(songInfo) { return { diff --git a/src/renderer/utils/musicSdk/mg/musicInfo.js b/src/renderer/utils/musicSdk/mg/musicInfo.js new file mode 100644 index 00000000..6194498b --- /dev/null +++ b/src/renderer/utils/musicSdk/mg/musicInfo.js @@ -0,0 +1,100 @@ +import { httpFetch } from '../../request' +import { sizeFormate } from '../../index' + +const getSinger = (singers) => { + let arr = [] + singers.forEach(singer => { + arr.push(singer.name) + }) + return arr.join('、') +} + +export const filterMusicInfoData = (rawList) => { + // console.log(rawList) + let ids = new Set() + const list = [] + rawList.forEach(item => { + if (ids.has(item.songId)) return + ids.add(item.songId) + const types = [] + const _types = {} + item.newRateFormats?.forEach(type => { + let size + switch (type.formatType) { + case 'PQ': + size = sizeFormate(type.size ?? type.androidSize) + types.push({ type: '128k', size }) + _types['128k'] = { + size, + } + break + case 'HQ': + size = sizeFormate(type.size ?? type.androidSize) + types.push({ type: '320k', size }) + _types['320k'] = { + size, + } + break + case 'SQ': + size = sizeFormate(type.size ?? type.androidSize) + types.push({ type: 'flac', size }) + _types.flac = { + size, + } + break + case 'ZQ': + size = sizeFormate(type.size ?? type.androidSize) + types.push({ type: 'flac24bit', size }) + _types.flac24bit = { + size, + } + break + } + }) + + const intervalTest = /(\d\d:\d\d)$/.test(item.length) + + list.push({ + singer: getSinger(item.artists), + name: item.songName, + albumName: item.album, + albumId: item.albumId, + songmid: item.songId, + copyrightId: item.copyrightId, + source: 'mg', + interval: intervalTest ? RegExp.$1 : null, + img: item.albumImgs?.length ? item.albumImgs[0].img : null, + lrc: null, + lrcUrl: item.lrcUrl, + mrcUrl: item.mrcUrl, + trcUrl: item.trcUrl, + otherSource: null, + types, + _types, + typeUrl: {}, + }) + }) + // console.log(list) + return list +} + +export const getMusicInfos = (copyrightIds, retry = 0) => { + if (++retry > 2) return Promise.reject(new Error('Failed to get music info try max')) + return httpFetch('https://c.musicapp.migu.cn/MIGUM2.0/v1.0/content/resourceinfo.do?resourceType=2', { + method: 'POST', + form: { + resourceId: copyrightIds.join('|'), + }, + }).promise.then(({ body }) => { + if (!body) return getMusicInfos(copyrightIds, retry) + if (body.code !== '000000') return Promise.reject(new Error('Failed to get music info')) + return filterMusicInfoData(body.resource) + }) +} + +export const getMusicInfo = (copyrightId) => { + return getMusicInfos([copyrightId]).then(([musicInfo]) => { + if (musicInfo) return musicInfo + throw new Error('failed') + }) +} diff --git a/src/renderer/utils/musicSdk/mg/musicSearch.js b/src/renderer/utils/musicSdk/mg/musicSearch.js index 1dbd5e29..e5cc0c24 100644 --- a/src/renderer/utils/musicSdk/mg/musicSearch.js +++ b/src/renderer/utils/musicSdk/mg/musicSearch.js @@ -1,30 +1,127 @@ -// import '../../polyfill/array.find' - import { httpFetch } from '../../request' -import { sizeFormate } from '../../index' -// import { debug } from '../../utils/env' -// import { formatSinger } from './util' +import { sizeFormate, formatPlayTime } from '../../index' +import { toMD5 } from '../utils' + +const sign = (time, str) => { + const deviceId = '963B7AA0D21511ED807EE5846EC87D20' + const signatureMd5 = '6cdc72a439cef99a3418d2a78aa28c73' + const sign = toMD5(`${str}${signatureMd5}yyapp2d16148780a1dcc7408e06336b98cfd50${deviceId}${time}`) + return { sign, deviceId } +} export default { limit: 20, total: 0, page: 0, allPage: 1, + + // 旧版API + // musicSearch(str, page, limit) { + // const searchRequest = httpFetch(`http://pd.musicapp.migu.cn/MIGUM2.0/v1.0/content/search_all.do?ua=Android_migu&version=5.0.1&text=${encodeURIComponent(str)}&pageNo=${page}&pageSize=${limit}&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A0%2C%22mvSong%22%3A0%2C%22songlist%22%3A0%2C%22bestShow%22%3A1%7D`, { + // searchRequest = httpFetch(`http://pd.musicapp.migu.cn/MIGUM2.0/v1.0/content/search_all.do?ua=Android_migu&version=5.0.1&text=${encodeURIComponent(str)}&pageNo=${page}&pageSize=${limit}&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A0%2C%22mvSong%22%3A0%2C%22songlist%22%3A0%2C%22bestShow%22%3A1%7D`, { + // searchRequest = httpFetch(`http://jadeite.migu.cn:7090/music_search/v2/search/searchAll?sid=4f87090d01c84984a11976b828e2b02c18946be88a6b4c47bcdc92fbd40762db&isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, { + // searchRequest = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?isCopyright=1&isCorrect=1&pageNo=${page}&pageSize=${limit}&searchSwitch={%22song%22:1,%22album%22:0,%22singer%22:0,%22tagSong%22:0,%22mvSong%22:0,%22songlist%22:0,%22bestShow%22:0}&sort=0&text=${encodeURIComponent(str)}`) + // // searchRequest = httpFetch(`http://jadeite.migu.cn:7090/music_search/v2/search/searchAll?sid=4f87090d01c84984a11976b828e2b02c18946be88a6b4c47bcdc92fbd40762db&isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, { + // headers: { + // // sign: 'c3b7ae985e2206e97f1b2de8f88691e2', + // // timestamp: 1578225871982, + // // appId: 'yyapp2', + // // mode: 'android', + // // ua: 'Android_migu', + // // version: '6.9.4', + // osVersion: 'android 7.0', + // 'User-Agent': 'okhttp/3.9.1', + // }, + // }) + // // searchRequest = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?isCopyright=1&isCorrect=1&pageNo=${page}&pageSize=${limit}&searchSwitch={%22song%22:1,%22album%22:0,%22singer%22:0,%22tagSong%22:0,%22mvSong%22:0,%22songlist%22:0,%22bestShow%22:0}&sort=0&text=${encodeURIComponent(str)}`) + // return searchRequest.promise.then(({ body }) => body) + // }, + // handleResult(rawData) { + // // console.log(rawData) + // let ids = new Set() + // const list = [] + // rawData.forEach(item => { + // if (ids.has(item.id)) return + // ids.add(item.id) + // const types = [] + // const _types = {} + // item.newRateFormats && item.newRateFormats.forEach(type => { + // let size + // switch (type.formatType) { + // case 'PQ': + // size = sizeFormate(type.size ?? type.androidSize) + // types.push({ type: '128k', size }) + // _types['128k'] = { + // size, + // } + // break + // case 'HQ': + // size = sizeFormate(type.size ?? type.androidSize) + // types.push({ type: '320k', size }) + // _types['320k'] = { + // size, + // } + // break + // case 'SQ': + // size = sizeFormate(type.size ?? type.androidSize) + // types.push({ type: 'flac', size }) + // _types.flac = { + // size, + // } + // break + // case 'ZQ': + // size = sizeFormate(type.size ?? type.androidSize) + // types.push({ type: 'flac24bit', size }) + // _types.flac24bit = { + // size, + // } + // break + // } + // }) + + // const albumNInfo = item.albums && item.albums.length + // ? { + // id: item.albums[0].id, + // name: item.albums[0].name, + // } + // : {} + + // list.push({ + // singer: this.getSinger(item.singers), + // name: item.name, + // albumName: albumNInfo.name, + // albumId: albumNInfo.id, + // songmid: item.songId, + // copyrightId: item.copyrightId, + // source: 'mg', + // interval: null, + // img: item.imgItems && item.imgItems.length ? item.imgItems[0].img : null, + // lrc: null, + // lrcUrl: item.lyricUrl, + // mrcUrl: item.mrcurl, + // trcUrl: item.trcUrl, + // otherSource: null, + // types, + // _types, + // typeUrl: {}, + // }) + // }) + // return list + // }, + musicSearch(str, page, limit) { - const searchRequest = httpFetch(`http://pd.musicapp.migu.cn/MIGUM2.0/v1.0/content/search_all.do?ua=Android_migu&version=5.0.1&text=${encodeURIComponent(str)}&pageNo=${page}&pageSize=${limit}&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A0%2C%22mvSong%22%3A0%2C%22songlist%22%3A0%2C%22bestShow%22%3A1%7D`, { - // searchRequest = httpFetch(`http://jadeite.migu.cn:7090/music_search/v2/search/searchAll?sid=4f87090d01c84984a11976b828e2b02c18946be88a6b4c47bcdc92fbd40762db&isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, { + const time = Date.now().toString() + const signData = sign(time, str) + const searchRequest = httpFetch(`https://jadeite.migu.cn/music_search/v3/search/searchAll?isCorrect=1&isCopyright=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%2C%22songlist%22%3A0%2C%22lyricSong%22%3A0%7D&pageSize=${limit}&text=${encodeURIComponent(str)}&pageNo=${page}&sort=0`, { headers: { - // sign: 'c3b7ae985e2206e97f1b2de8f88691e2', - // timestamp: 1578225871982, - // appId: 'yyapp2', - // mode: 'android', - // ua: 'Android_migu', - // version: '6.9.4', - osVersion: 'android 7.0', - 'User-Agent': 'okhttp/3.9.1', + uiVersion: 'A_music_3.6.1', + deviceId: signData.deviceId, + timestamp: time, + sign: signData.sign, + channel: '0146921', + 'User-Agent': 'Mozilla/5.0 (Linux; U; Android 11.0.0; zh-cn; MI 11 Build/OPR1.170623.032) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30', }, }) - // searchRequest = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do?isCopyright=1&isCorrect=1&pageNo=${page}&pageSize=${limit}&searchSwitch={%22song%22:1,%22album%22:0,%22singer%22:0,%22tagSong%22:0,%22mvSong%22:0,%22songlist%22:0,%22bestShow%22:0}&sort=0&text=${encodeURIComponent(str)}`) return searchRequest.promise.then(({ body }) => body) }, getSinger(singers) { @@ -34,75 +131,73 @@ export default { }) return arr.join('、') }, - handleResult(rawData) { + filterData(rawData) { // console.log(rawData) - let ids = new Set() const list = [] + const ids = new Set() + rawData.forEach(item => { - if (ids.has(item.id)) return - ids.add(item.id) - const types = [] - const _types = {} - item.newRateFormats && item.newRateFormats.forEach(type => { - let size - switch (type.formatType) { - case 'PQ': - size = sizeFormate(type.size ?? type.androidSize) - types.push({ type: '128k', size }) - _types['128k'] = { - size, - } - break - case 'HQ': - size = sizeFormate(type.size ?? type.androidSize) - types.push({ type: '320k', size }) - _types['320k'] = { - size, - } - break - case 'SQ': - size = sizeFormate(type.size ?? type.androidSize) - types.push({ type: 'flac', size }) - _types.flac = { - size, - } - break - case 'ZQ': - size = sizeFormate(type.size ?? type.androidSize) - types.push({ type: 'flac24bit', size }) - _types.flac24bit = { - size, - } - break - } - }) + item.forEach(data => { + if (!data.songId || !data.copyrightId || ids.has(data.copyrightId)) return + ids.add(data.copyrightId) - const albumNInfo = item.albums && item.albums.length - ? { - id: item.albums[0].id, - name: item.albums[0].name, + const types = [] + const _types = {} + data.audioFormats && data.audioFormats.forEach(type => { + let size + switch (type.formatType) { + case 'PQ': + size = sizeFormate(type.asize ?? type.isize) + types.push({ type: '128k', size }) + _types['128k'] = { + size, + } + break + case 'HQ': + size = sizeFormate(type.asize ?? type.isize) + types.push({ type: '320k', size }) + _types['320k'] = { + size, + } + break + case 'SQ': + size = sizeFormate(type.asize ?? type.isize) + types.push({ type: 'flac', size }) + _types.flac = { + size, + } + break + case 'ZQ24': + size = sizeFormate(type.asize ?? type.isize) + types.push({ type: 'flac24bit', size }) + _types.flac24bit = { + size, + } + break } - : {} + }) - list.push({ - singer: this.getSinger(item.singers), - name: item.name, - albumName: albumNInfo.name, - albumId: albumNInfo.id, - songmid: item.copyrightId, - songId: item.songId, - copyrightId: item.copyrightId, - source: 'mg', - interval: null, - img: item.imgItems && item.imgItems.length ? item.imgItems[0].img : null, - lrc: null, - lrcUrl: item.lyricUrl, - mrcUrl: item.mrcurl, - trcUrl: item.trcUrl, - otherSource: null, - types, - _types, - typeUrl: {}, + let img = data.img3 || data.img2 || data.img1 || null + if (img && !/https?:/.test(data.img3)) img = 'http://d.musicapp.migu.cn' + img + + list.push({ + singer: this.getSinger(data.singerList), + name: data.name, + albumName: data.album, + albumId: data.albumId, + songmid: data.songId, + copyrightId: data.copyrightId, + source: 'mg', + interval: formatPlayTime(data.duration), + img, + lrc: null, + lrcUrl: data.lrcUrl, + mrcUrl: data.mrcurl, + trcUrl: data.trcUrl, + types, + _types, + typeUrl: {}, + }) }) }) return list @@ -114,22 +209,22 @@ export default { return this.musicSearch(str, page, limit).then(result => { // console.log(result) if (!result || result.code !== '000000') return Promise.reject(new Error(result ? result.info : '搜索失败')) - const songResultData = result.songResultData || { result: [], totalCount: 0 } + const songResultData = result.songResultData || { resultList: [], totalCount: 0 } - let list = this.handleResult(songResultData.result) + let list = this.filterData(songResultData.resultList) if (list == null) return this.search(str, page, limit, retryNum) this.total = parseInt(songResultData.totalCount) this.page = page this.allPage = Math.ceil(this.total / limit) - return Promise.resolve({ + return { list, allPage: this.allPage, limit, total: this.total, source: 'mg', - }) + } }) }, } diff --git a/src/renderer/utils/musicSdk/mg/pic.js b/src/renderer/utils/musicSdk/mg/pic.js index 46a40461..046eba08 100644 --- a/src/renderer/utils/musicSdk/mg/pic.js +++ b/src/renderer/utils/musicSdk/mg/pic.js @@ -1,21 +1,28 @@ import { httpFetch } from '../../request' +import getSongId from './songId' export default { - getPic(songInfo, tryNum = 0) { - let requestObj = httpFetch(`http://music.migu.cn/v3/api/music/audioPlayer/getSongPic?songId=${songInfo.songmid}`, { + async getPicUrl(songId, tryNum = 0) { + let requestObj = httpFetch(`http://music.migu.cn/v3/api/music/audioPlayer/getSongPic?songId=${songId}`, { headers: { Referer: 'http://music.migu.cn/v3/music/player/audio?from=migu', }, }) - requestObj.promise = requestObj.promise.then(({ body }) => { + requestObj.promise.then(({ body }) => { if (body.returnCode !== '000000') { if (tryNum > 5) return Promise.reject('图片获取失败') - let tryRequestObj = this.getPic(songInfo, ++tryNum) + let tryRequestObj = this.getPic(songId, ++tryNum) requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj) return tryRequestObj.promise } - return body.largePic || body.mediumPic || body.smallPic + let url = body.largePic || body.mediumPic || body.smallPic + if (!/https?:/.test(url)) url = 'http:' + url + return url }) return requestObj }, + async getPic(songInfo) { + const songId = await getSongId(songInfo) + return this.getPicUrl(songId) + }, } diff --git a/src/renderer/utils/musicSdk/mg/songId.js b/src/renderer/utils/musicSdk/mg/songId.js new file mode 100644 index 00000000..25197c28 --- /dev/null +++ b/src/renderer/utils/musicSdk/mg/songId.js @@ -0,0 +1,31 @@ +// import { httpFetch } from '../../request' +import { getMusicInfo } from './musicInfo' + +const getSongId = async(mInfo) => { + if (mInfo.songmid != mInfo.copyrightId) return mInfo.songmid + const musicInfo = await getMusicInfo(mInfo.copyrightId) + return musicInfo.songmid +} + + +// export const getSongId = async(musicInfo, retry = 0) => { +// if (musicInfo.songmid != musicInfo.copyrightId) return musicInfo.songmid +// if (++retry > 2) return Promise.reject(new Error('max retry')) + +// const requestObj = httpFetch(`https://app.c.nf.migu.cn/MIGUM2.0/v2.0/content/listen-url?netType=00&resourceType=2&songId=${musicInfo.copyrightId}&toneFlag=PQ`, { +// headers: { +// 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36', +// channel: '0146921', +// }, +// }) + +// return requestObj.promise.then(({ body }) => { +// console.log(body) +// if (!body || body.code !== '000000') return this.getSongId(musicInfo, retry) +// const id = body.data.songItem.songId +// if (!id) throw new Error('failed') +// return id +// }) +// } + +export default getSongId diff --git a/src/renderer/utils/musicSdk/mg/songList.js b/src/renderer/utils/musicSdk/mg/songList.js index d1af463d..5b0984ee 100644 --- a/src/renderer/utils/musicSdk/mg/songList.js +++ b/src/renderer/utils/musicSdk/mg/songList.js @@ -1,5 +1,6 @@ import { httpFetch } from '../../request' -import { sizeFormate, dateFormat } from '../../index' +import { dateFormat } from '../../index' +import { filterMusicInfoData } from './musicInfo' // const tagData = { code: '000000', info: 'SUCCESS', columnInfo: { columnTitle: '分类', columnId: '15244430', columnPid: '15031270', opNumItem: { playNum: 0, playNumDesc: '0', keepNum: 0, keepNumDesc: '0', commentNum: 0, commentNumDesc: '0', shareNum: 0, shareNumDesc: '0', orderNumByWeek: 0, orderNumByWeekDesc: '0', orderNumByTotal: 0, orderNumByTotalDesc: '0', thumbNum: 0, thumbNumDesc: '0', followNum: 0, followNumDesc: '0', subscribeNum: 0, subscribeNumDesc: '0', livePlayNum: 0, livePlayNumDesc: '0', popularNum: 0, popularNumDesc: '0', bookingNum: 0, bookingNumDesc: '0' }, contentsCount: 6, columnStatus: 1, columnCreateTime: '2016-11-10 10:53:05.077', columntype: 2011, contents: [{ contentId: '18464615', relationType: 2011, objectInfo: { columnTitle: '热门', columnId: '18464615', columnPid: '15244430', opNumItem: { playNum: 0, playNumDesc: '0', keepNum: 0, keepNumDesc: '0', commentNum: 0, commentNumDesc: '0', shareNum: 0, shareNumDesc: '0', orderNumByWeek: 0, orderNumByWeekDesc: '0', orderNumByTotal: 0, orderNumByTotalDesc: '0', thumbNum: 0, thumbNumDesc: '0', followNum: 0, followNumDesc: '0', subscribeNum: 0, subscribeNumDesc: '0', livePlayNum: 0, livePlayNumDesc: '0', popularNum: 0, popularNumDesc: '0', bookingNum: 0, bookingNumDesc: '0' }, contentsCount: 8, columnStatus: 1, columnCreateTime: '2017-02-20 16:09:13.400', columntype: 2011, contents: [{ contentId: '1000001672', relationType: 4034, objectInfo: { tagId: '1000001672', tagName: '流行', resourceType: '2034' }, relationSort: 9 }, { contentId: '1003449727', relationType: 4034, objectInfo: { tagId: '1003449727', tagName: '厂牌', resourceType: '2034' }, relationSort: 8 }, { contentId: '1000001795', relationType: 4034, objectInfo: { tagId: '1000001795', tagName: '伤感', resourceType: '2034' }, relationSort: 7 }, { contentId: '1001076080', relationType: 4034, objectInfo: { tagId: '1001076080', tagName: '电影', resourceType: '2034' }, relationSort: 6 }, { contentId: '1000001675', relationType: 4034, objectInfo: { tagId: '1000001675', tagName: '中国风', resourceType: '2034' }, relationSort: 5 }, { contentId: '1000001635', relationType: 4034, objectInfo: { tagId: '1000001635', tagName: '经典老歌', resourceType: '2034' }, relationSort: 4 }, { contentId: '1000001831', relationType: 4034, objectInfo: { tagId: '1000001831', tagName: '翻唱', resourceType: '2034' }, relationSort: 3 }, { contentId: '1000001762', relationType: 4034, objectInfo: { tagId: '1000001762', tagName: '国语', resourceType: '2034' }, relationSort: 1 }], dataVersion: '1620410266029', customizedPicUrls: [] }, relationSort: 6 }, { contentId: '15244503', relationType: 2011, objectInfo: { columnTitle: '主题', columnId: '15244503', columnPid: '15244430', opNumItem: { playNum: 0, playNumDesc: '0', keepNum: 0, keepNumDesc: '0', commentNum: 0, commentNumDesc: '0', shareNum: 0, shareNumDesc: '0', orderNumByWeek: 0, orderNumByWeekDesc: '0', orderNumByTotal: 0, orderNumByTotalDesc: '0', thumbNum: 0, thumbNumDesc: '0', followNum: 0, followNumDesc: '0', subscribeNum: 0, subscribeNumDesc: '0', livePlayNum: 0, livePlayNumDesc: '0', popularNum: 0, popularNumDesc: '0', bookingNum: 0, bookingNumDesc: '0' }, contentsCount: 23, columnStatus: 1, columnCreateTime: '2016-11-10 10:54:10.261', columntype: 2011, contents: [{ contentId: '1003449727', relationType: 4034, objectInfo: { tagId: '1003449727', tagName: '厂牌', resourceType: '2034' }, relationSort: 29 }, { contentId: '1001076080', relationType: 4034, objectInfo: { tagId: '1001076080', tagName: '电影', resourceType: '2034' }, relationSort: 28 }, { contentId: '1001076078', relationType: 4034, objectInfo: { tagId: '1001076078', tagName: '电视剧', resourceType: '2034' }, relationSort: 27 }, { contentId: '1001076083', relationType: 4034, objectInfo: { tagId: '1001076083', tagName: '综艺', resourceType: '2034' }, relationSort: 26 }, { contentId: '1000001827', relationType: 4034, objectInfo: { tagId: '1000001827', tagName: 'KTV', resourceType: '2034' }, relationSort: 23 }, { contentId: '1000001698', relationType: 4034, objectInfo: { tagId: '1000001698', tagName: '爱情', resourceType: '2034' }, relationSort: 22 }, { contentId: '1000001635', relationType: 4034, objectInfo: { tagId: '1000001635', tagName: '经典老歌', resourceType: '2034' }, relationSort: 21 }, { contentId: '1001076096', relationType: 4034, objectInfo: { tagId: '1001076096', tagName: '网络热歌', resourceType: '2034' }, relationSort: 20 }, { contentId: '1000001780', relationType: 4034, objectInfo: { tagId: '1000001780', tagName: '儿童歌曲', resourceType: '2034' }, relationSort: 19 }, { contentId: '1000587702', relationType: 4034, objectInfo: { tagId: '1000587702', tagName: '广场舞', resourceType: '2034' }, relationSort: 18 }, { contentId: '1000587717', relationType: 4034, objectInfo: { tagId: '1000587717', tagName: '70后', resourceType: '2034' }, relationSort: 17 }, { contentId: '1000587718', relationType: 4034, objectInfo: { tagId: '1000587718', tagName: '80后', resourceType: '2034' }, relationSort: 16 }, { contentId: '1000587726', relationType: 4034, objectInfo: { tagId: '1000587726', tagName: '90后', resourceType: '2034' }, relationSort: 15 }, { contentId: '1000001670', relationType: 4034, objectInfo: { tagId: '1000001670', tagName: '红歌', resourceType: '2034' }, relationSort: 14 }, { contentId: '1000587698', relationType: 4034, objectInfo: { tagId: '1000587698', tagName: '游戏', resourceType: '2034' }, relationSort: 13 }, { contentId: '1000587706', relationType: 4034, objectInfo: { tagId: '1000587706', tagName: '动漫', resourceType: '2034' }, relationSort: 12 }, { contentId: '1000001675', relationType: 4034, objectInfo: { tagId: '1000001675', tagName: '中国风', resourceType: '2034' }, relationSort: 11 }, { contentId: '1000587712', relationType: 4034, objectInfo: { tagId: '1000587712', tagName: '青春校园', resourceType: '2034' }, relationSort: 10 }, { contentId: '1000587673', relationType: 4034, objectInfo: { tagId: '1000587673', tagName: '小清新', resourceType: '2034' }, relationSort: 9 }, { contentId: '1000093902', relationType: 4034, objectInfo: { tagId: '1000093902', tagName: 'DJ舞曲', resourceType: '2034' }, relationSort: 7 }, { contentId: '1000093963', relationType: 4034, objectInfo: { tagId: '1000093963', tagName: '广告', resourceType: '2034' }, relationSort: 6 }, { contentId: '1000001831', relationType: 4034, objectInfo: { tagId: '1000001831', tagName: '翻唱', resourceType: '2034' }, relationSort: 2 }, { contentId: '1003449726', relationType: 4034, objectInfo: { tagId: '1003449726', tagName: '读书', resourceType: '2034' }, relationSort: 1 }], dataVersion: '1620410266055', customizedPicUrls: [] }, relationSort: 5 }, { contentId: '15244509', relationType: 2011, objectInfo: { columnTitle: '风格', columnId: '15244509', columnPid: '15244430', opNumItem: { playNum: 0, playNumDesc: '0', keepNum: 0, keepNumDesc: '0', commentNum: 0, commentNumDesc: '0', shareNum: 0, shareNumDesc: '0', orderNumByWeek: 0, orderNumByWeekDesc: '0', orderNumByTotal: 0, orderNumByTotalDesc: '0', thumbNum: 0, thumbNumDesc: '0', followNum: 0, followNumDesc: '0', subscribeNum: 0, subscribeNumDesc: '0', livePlayNum: 0, livePlayNumDesc: '0', popularNum: 0, popularNumDesc: '0', bookingNum: 0, bookingNumDesc: '0' }, contentsCount: 12, columnStatus: 1, columnCreateTime: '2016-11-10 10:54:57.257', columntype: 2011, contents: [{ contentId: '1000001672', relationType: 4034, objectInfo: { tagId: '1000001672', tagName: '流行', resourceType: '2034' }, relationSort: 14 }, { contentId: '1000001808', relationType: 4034, objectInfo: { tagId: '1000001808', tagName: 'R&B', resourceType: '2034' }, relationSort: 13 }, { contentId: '1000001809', relationType: 4034, objectInfo: { tagId: '1000001809', tagName: '嘻哈', resourceType: '2034' }, relationSort: 12 }, { contentId: '1000001674', relationType: 4034, objectInfo: { tagId: '1000001674', tagName: '摇滚', resourceType: '2034' }, relationSort: 11 }, { contentId: '1000001682', relationType: 4034, objectInfo: { tagId: '1000001682', tagName: '电子', resourceType: '2034' }, relationSort: 10 }, { contentId: '1000001852', relationType: 4034, objectInfo: { tagId: '1000001852', tagName: '电子舞曲', resourceType: '2034' }, relationSort: 9 }, { contentId: '1000001681', relationType: 4034, objectInfo: { tagId: '1000001681', tagName: '爵士', resourceType: '2034' }, relationSort: 6 }, { contentId: '1000001683', relationType: 4034, objectInfo: { tagId: '1000001683', tagName: '乡村', resourceType: '2034' }, relationSort: 5 }, { contentId: '1000001851', relationType: 4034, objectInfo: { tagId: '1000001851', tagName: '蓝调', resourceType: '2034' }, relationSort: 4 }, { contentId: '1000001775', relationType: 4034, objectInfo: { tagId: '1000001775', tagName: '民谣', resourceType: '2034' }, relationSort: 3 }, { contentId: '1000001807', relationType: 4034, objectInfo: { tagId: '1000001807', tagName: '纯音乐', resourceType: '2034' }, relationSort: 2 }, { contentId: '1000001783', relationType: 4034, objectInfo: { tagId: '1000001783', tagName: '古典', resourceType: '2034' }, relationSort: 1 }], dataVersion: '1620410266033', customizedPicUrls: [] }, relationSort: 4 }, { contentId: '18464665', relationType: 2011, objectInfo: { columnTitle: '语种', columnId: '18464665', columnPid: '15244430', opNumItem: { playNum: 0, playNumDesc: '0', keepNum: 0, keepNumDesc: '0', commentNum: 0, commentNumDesc: '0', shareNum: 0, shareNumDesc: '0', orderNumByWeek: 0, orderNumByWeekDesc: '0', orderNumByTotal: 0, orderNumByTotalDesc: '0', thumbNum: 0, thumbNumDesc: '0', followNum: 0, followNumDesc: '0', subscribeNum: 0, subscribeNumDesc: '0', livePlayNum: 0, livePlayNumDesc: '0', popularNum: 0, popularNumDesc: '0', bookingNum: 0, bookingNumDesc: '0' }, contentsCount: 6, columnStatus: 1, columnCreateTime: '2017-02-20 16:07:16.566', columntype: 2011, contents: [{ contentId: '1000001762', relationType: 4034, objectInfo: { tagId: '1000001762', tagName: '国语', resourceType: '2034' }, relationSort: 6 }, { contentId: '1000001763', relationType: 4034, objectInfo: { tagId: '1000001763', tagName: '粤语', resourceType: '2034' }, relationSort: 5 }, { contentId: '1000001766', relationType: 4034, objectInfo: { tagId: '1000001766', tagName: '英语', resourceType: '2034' }, relationSort: 4 }, { contentId: '1000001599', relationType: 4034, objectInfo: { tagId: '1000001599', tagName: '韩语', resourceType: '2034' }, relationSort: 3 }, { contentId: '1000001767', relationType: 4034, objectInfo: { tagId: '1000001767', tagName: '日语', resourceType: '2034' }, relationSort: 2 }, { contentId: '1003449724', relationType: 4034, objectInfo: { tagId: '1003449724', tagName: '小语种', resourceType: '2034' }, relationSort: 1 }], dataVersion: '1620410266036', customizedPicUrls: [] }, relationSort: 3 }, { contentId: '18464583', relationType: 2011, objectInfo: { columnTitle: '心情', columnId: '18464583', columnPid: '15244430', opNumItem: { playNum: 0, playNumDesc: '0', keepNum: 0, keepNumDesc: '0', commentNum: 0, commentNumDesc: '0', shareNum: 0, shareNumDesc: '0', orderNumByWeek: 0, orderNumByWeekDesc: '0', orderNumByTotal: 0, orderNumByTotalDesc: '0', thumbNum: 0, thumbNumDesc: '0', followNum: 0, followNumDesc: '0', subscribeNum: 0, subscribeNumDesc: '0', livePlayNum: 0, livePlayNumDesc: '0', popularNum: 0, popularNumDesc: '0', bookingNum: 0, bookingNumDesc: '0' }, contentsCount: 13, columnStatus: 1, columnCreateTime: '2017-02-20 15:59:03.412', columntype: 2011, contents: [{ contentId: '1000587677', relationType: 4034, objectInfo: { tagId: '1000587677', tagName: '幸福', resourceType: '2034' }, relationSort: 15 }, { contentId: '1000587710', relationType: 4034, objectInfo: { tagId: '1000587710', tagName: '治愈', resourceType: '2034' }, relationSort: 14 }, { contentId: '1000001703', relationType: 4034, objectInfo: { tagId: '1000001703', tagName: '思念', resourceType: '2034' }, relationSort: 13 }, { contentId: '1000587667', relationType: 4034, objectInfo: { tagId: '1000587667', tagName: '期待', resourceType: '2034' }, relationSort: 12 }, { contentId: '1000001700', relationType: 4034, objectInfo: { tagId: '1000001700', tagName: '励志', resourceType: '2034' }, relationSort: 11 }, { contentId: '1000001694', relationType: 4034, objectInfo: { tagId: '1000001694', tagName: '欢快', resourceType: '2034' }, relationSort: 10 }, { contentId: '1002600588', relationType: 4034, objectInfo: { tagId: '1002600588', tagName: '叛逆', resourceType: '2034' }, relationSort: 9 }, { contentId: '1002600585', relationType: 4034, objectInfo: { tagId: '1002600585', tagName: '宣泄', resourceType: '2034' }, relationSort: 8 }, { contentId: '1000001696', relationType: 4034, objectInfo: { tagId: '1000001696', tagName: '怀旧', resourceType: '2034' }, relationSort: 7 }, { contentId: '1000587679', relationType: 4034, objectInfo: { tagId: '1000587679', tagName: '减压', resourceType: '2034' }, relationSort: 6 }, { contentId: '1000001699', relationType: 4034, objectInfo: { tagId: '1000001699', tagName: '寂寞', resourceType: '2034' }, relationSort: 5 }, { contentId: '1002600579', relationType: 4034, objectInfo: { tagId: '1002600579', tagName: '忧郁', resourceType: '2034' }, relationSort: 4 }, { contentId: '1000001795', relationType: 4034, objectInfo: { tagId: '1000001795', tagName: '伤感', resourceType: '2034' }, relationSort: 3 }], dataVersion: '1620410266187', customizedPicUrls: [] }, relationSort: 2 }, { contentId: '18464638', relationType: 2011, objectInfo: { columnTitle: '场景', columnId: '18464638', columnPid: '15244430', opNumItem: { playNum: 0, playNumDesc: '0', keepNum: 0, keepNumDesc: '0', commentNum: 0, commentNumDesc: '0', shareNum: 0, shareNumDesc: '0', orderNumByWeek: 0, orderNumByWeekDesc: '0', orderNumByTotal: 0, orderNumByTotalDesc: '0', thumbNum: 0, thumbNumDesc: '0', followNum: 0, followNumDesc: '0', subscribeNum: 0, subscribeNumDesc: '0', livePlayNum: 0, livePlayNumDesc: '0', popularNum: 0, popularNumDesc: '0', bookingNum: 0, bookingNumDesc: '0' }, contentsCount: 13, columnStatus: 1, columnCreateTime: '2017-02-20 16:02:59.711', columntype: 2011, contents: [{ contentId: '1000587689', relationType: 4034, objectInfo: { tagId: '1000587689', tagName: '清晨', resourceType: '2034' }, relationSort: 21 }, { contentId: '1000587690', relationType: 4034, objectInfo: { tagId: '1000587690', tagName: '夜晚', resourceType: '2034' }, relationSort: 20 }, { contentId: '1000587688', relationType: 4034, objectInfo: { tagId: '1000587688', tagName: '睡前安眠', resourceType: '2034' }, relationSort: 19 }, { contentId: '1003449726', relationType: 4034, objectInfo: { tagId: '1003449726', tagName: '读书', resourceType: '2034' }, relationSort: 18 }, { contentId: '1003449723', relationType: 4034, objectInfo: { tagId: '1003449723', tagName: '下午·茶', resourceType: '2034' }, relationSort: 16 }, { contentId: '1000093923', relationType: 4034, objectInfo: { tagId: '1000093923', tagName: '驾车', resourceType: '2034' }, relationSort: 15 }, { contentId: '1003449615', relationType: 4034, objectInfo: { tagId: '1003449615', tagName: '运动', resourceType: '2034' }, relationSort: 13 }, { contentId: '1000587694', relationType: 4034, objectInfo: { tagId: '1000587694', tagName: '散步', resourceType: '2034' }, relationSort: 12 }, { contentId: '1000001749', relationType: 4034, objectInfo: { tagId: '1000001749', tagName: '旅行', resourceType: '2034' }, relationSort: 11 }, { contentId: '1000587686', relationType: 4034, objectInfo: { tagId: '1000587686', tagName: '夜店', resourceType: '2034' }, relationSort: 10 }, { contentId: '1002600606', relationType: 4034, objectInfo: { tagId: '1002600606', tagName: '派对', resourceType: '2034' }, relationSort: 9 }, { contentId: '1000001634', relationType: 4034, objectInfo: { tagId: '1000001634', tagName: '咖啡馆', resourceType: '2034' }, relationSort: 3 }, { contentId: '1000587692', relationType: 4034, objectInfo: { tagId: '1000587692', tagName: '瑜伽', resourceType: '2034' }, relationSort: 1 }], dataVersion: '1620846028994', customizedPicUrls: [] }, relationSort: 1 }], dataVersion: '1620846028941', customizedPicUrls: [] } } @@ -84,7 +85,7 @@ export default { // console.log(JSON.stringify(body)) // console.log(body) return { - list: this.filterListDetail(body.list), + list: filterMusicInfoData(body.list), page, limit: this.limit_song, total: body.totalCount, @@ -154,74 +155,6 @@ export default { return listData }) }, - filterListDetail(rawList) { - // console.log(rawList) - let ids = new Set() - const list = [] - rawList.forEach(item => { - if (ids.has(item.songId)) return - ids.add(item.songId) - const types = [] - const _types = {} - item.newRateFormats && item.newRateFormats.forEach(type => { - let size - switch (type.formatType) { - case 'PQ': - size = sizeFormate(type.size ?? type.androidSize) - types.push({ type: '128k', size }) - _types['128k'] = { - size, - } - break - case 'HQ': - size = sizeFormate(type.size ?? type.androidSize) - types.push({ type: '320k', size }) - _types['320k'] = { - size, - } - break - case 'SQ': - size = sizeFormate(type.size ?? type.androidSize) - types.push({ type: 'flac', size }) - _types.flac = { - size, - } - break - case 'ZQ': - size = sizeFormate(type.size ?? type.androidSize) - types.push({ type: 'flac24bit', size }) - _types.flac24bit = { - size, - } - break - } - }) - - const intervalTest = /(\d\d:\d\d)$/.test(item.length) - - list.push({ - singer: item.singer, - name: item.songName, - albumName: item.album, - albumId: item.albumId, - songmid: item.copyrightId, - copyrightId: item.copyrightId, - songId: item.songId, - source: 'mg', - interval: intervalTest ? RegExp.$1 : null, - img: item.albumImgs && item.albumImgs.length ? item.albumImgs[0].img : null, - lrc: null, - lrcUrl: item.lrcUrl, - mrcUrl: item.mrcUrl, - trcUrl: item.trcUrl, - otherSource: null, - types, - _types, - typeUrl: {}, - }) - }) - return list - }, // 获取列表数据 getList(sortId, tagId, page, tryNum = 0) { diff --git a/src/renderer/utils/musicSdk/tx/api-test.js b/src/renderer/utils/musicSdk/tx/api-test.js index a0fae0dd..0c7da50c 100644 --- a/src/renderer/utils/musicSdk/tx/api-test.js +++ b/src/renderer/utils/musicSdk/tx/api-test.js @@ -18,9 +18,7 @@ const api_messoer = { return requestObj }, getPic(songInfo) { - return { - promise: Promise.resolve(`https://y.gtimg.cn/music/photo_new/T002R500x500M000${songInfo.albumId}.jpg`), - } + return Promise.resolve(`https://y.gtimg.cn/music/photo_new/T002R500x500M000${songInfo.albumId}.jpg`) }, } diff --git a/src/renderer/utils/musicSdk/tx/comment.js b/src/renderer/utils/musicSdk/tx/comment.js index 10adf5c2..16ae4cb8 100644 --- a/src/renderer/utils/musicSdk/tx/comment.js +++ b/src/renderer/utils/musicSdk/tx/comment.js @@ -124,40 +124,75 @@ export default { maxPage: Math.ceil(comment.commenttotal / limit) || 1, } }, - async getHotComment(mInfo, page = 1, limit = 100) { + async getHotComment(mInfo, page = 1, limit = 20) { if (this._requestObj2) this._requestObj2.cancelHttp() const songId = await this.getSongId(mInfo) - - const _requestObj2 = httpFetch('http://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg', { - method: 'POST', - headers: { - 'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)', + // const _requestObj2 = httpFetch('http://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg', { + // method: 'POST', + // 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, + // }, + // }) + const _requestObj2 = httpFetch('https://u.y.qq.com/cgi-bin/musicu.fcg', { + method: 'post', + body: { + 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: 2101046530, + // g_tk: 2101046530, + }, + req: { + module: 'music.globalComment.CommentRead', + method: 'GetHotCommentList', + param: { + BizType: 1, + BizId: String(songId), + LastCommentSeqNo: '', + PageSize: limit, + PageNum: page - 1, + HotType: 1, + WithAirborne: 0, + PicEnable: 1, + }, + }, }, - form: { - uin: '0', - format: 'json', - cid: '205360772', - reqtype: '2', - biztype: '1', - topid: songId, - cmd: '9', - needmusiccrit: '1', - pagenum: page - 1, - pagesize: limit, + headers: { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.0.0', + 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 + // console.log('body', body) + if (statusCode != 200 || body.code !== 0 || body.req.code !== 0) throw new Error('获取热门评论失败') + const comment = body.req.data.CommentList return { source: 'tx', - comments: this.filterComment(comment.commentlist), - total: comment.commenttotal, + comments: this.filterHotComment(comment.Comments), + total: comment.Total, page, limit, - maxPage: Math.ceil(comment.commenttotal / limit) || 1, + maxPage: Math.ceil(comment.Total / limit) || 1, } }, replaceEmoji(msg) { @@ -186,7 +221,7 @@ export default { return { id: `${item.rootcommentid}_${item.commentid}`, rootId: item.rootcommentid, - text: item.rootcommentcontent ? this.replaceEmoji(item.rootcommentcontent).replace(/\\n/g, '\n').split('\n') : [], + text: item.rootcommentcontent ? this.replaceEmoji(item.rootcommentcontent).replace(/\\n/g, '\n') : '', time: item.rootcommentid == item.commentid ? time : null, timeStr: item.rootcommentid == item.commentid ? timeStr : null, userName: item.rootcommentnick ? item.rootcommentnick.substring(1) : '', @@ -198,7 +233,7 @@ export default { // let index = c.subcommentid.lastIndexOf('_') return { id: `sub_${item.rootcommentid}_${c.subcommentid}`, - text: this.replaceEmoji(c.subcommentcontent).replace(/\\n/g, '\n').split('\n'), + text: this.replaceEmoji(c.subcommentcontent).replace(/\\n/g, '\n'), time: c.subcommentid == item.commentid ? time : null, timeStr: c.subcommentid == item.commentid ? timeStr : null, userName: c.replynick.substring(1), @@ -211,4 +246,51 @@ export default { } }) }, + filterHotComment(rawList) { + // console.log(rawList) + return rawList.map(item => { + // let time = String(item.PubTime).length < 10 ? null : parseInt(item.PubTime + '000') + // let timeStr = time ? dateFormat2(time) : null + // if (item.SubComments) { + // let firstItem = item.SubComments[0] + // firstItem.avatarurl = item.avatarurl + // firstItem.praisenum = item.praisenum + // item.avatarurl = null + // item.praisenum = null + // item.SubComments.reverse() + // } + return { + id: `${item.SeqNo}_${item.EncryptUin}`, + rootId: item.SeqNo, + text: item.Content ? this.replaceEmoji(item.Content).replace(/\\n/g, '\n') : '', + time: this.formatTime(item.PubTime), + timeStr: item.PubTime ? dateFormat2(this.formatTime(item.PubTime)) : null, + userName: item.Nick ? item.Nick.substring(1) : '', + images: item.Pic ? [item.Pic] : [], + avatar: item.Avatar, + location: item.Location ? ('来自' + item.Location) : '', + userId: item.EncryptUin, + likedCount: item.PraiseNum, + reply: item.SubComments + ? item.SubComments.map(c => { + // let index = c.subcommentid.lastIndexOf('_') + return { + id: `sub_${item.SeqNo}_${c.EncryptUin}`, + text: this.replaceEmoji(c.Content).replace(/\\n/g, '\n'), + time: this.formatTime(c.PubTime), + timeStr: item.PubTime ? dateFormat2(this.formatTime(c.PubTime)) : null, + userName: c.Nick.substring(1), + avatar: c.Avatar, + images: item.Pic ? [item.Pic] : [], + userId: c.EncryptUin, + likedCount: c.PraiseNum, + } + }) + : [], + } + }) + }, + formatTime(time) { + return String(time).length < 10 ? null : parseInt(time + '000') + }, } diff --git a/src/renderer/utils/musicSdk/tx/leaderboard.js b/src/renderer/utils/musicSdk/tx/leaderboard.js index ac8d132b..2e58f93f 100644 --- a/src/renderer/utils/musicSdk/tx/leaderboard.js +++ b/src/renderer/utils/musicSdk/tx/leaderboard.js @@ -1,7 +1,7 @@ import { httpFetch } from '../../request' import { formatPlayTime, sizeFormate } from '../../index' -let boardList = [{ id: 'tx__4', name: '流行指数榜', bangid: '4' }, { id: 'tx__26', name: '热歌榜', bangid: '26' }, { id: 'tx__27', name: '新歌榜', bangid: '27' }, { id: 'tx__62', name: '飙升榜', bangid: '62' }, { id: 'tx__58', name: '说唱榜', bangid: '58' }, { id: 'tx__57', name: '电音榜', bangid: '57' }, { id: 'tx__28', name: '网络歌曲榜', bangid: '28' }, { id: 'tx__5', name: '内地榜', bangid: '5' }, { id: 'tx__3', name: '欧美榜', bangid: '3' }, { id: 'tx__59', name: '香港地区榜', bangid: '59' }, { id: 'tx__16', name: '韩国榜', bangid: '16' }, { id: 'tx__60', name: '抖音排行榜', bangid: '60' }, { id: 'tx__29', name: '影视金曲榜', bangid: '29' }, { id: 'tx__17', name: '日本榜', bangid: '17' }, { id: 'tx__52', name: '腾讯音乐人原创榜', bangid: '52' }, { id: 'tx__36', name: 'K歌金曲榜', bangid: '36' }, { id: 'tx__61', name: '台湾地区榜', bangid: '61' }, { id: 'tx__63', name: 'DJ舞曲榜', bangid: '63' }, { id: 'tx__64', name: '综艺新歌榜', bangid: '64' }, { id: 'tx__65', name: '国风热歌榜', bangid: '65' }, { id: 'tx__66', name: 'ACG新歌榜', bangid: '66' }, { id: 'tx__67', name: '听歌识曲榜', bangid: '67' }, { id: 'tx__70', name: '达人音乐榜', bangid: '70' }] +let boardList = [{ id: 'tx__4', name: '流行指数榜', bangid: '4' }, { id: 'tx__26', name: '热歌榜', bangid: '26' }, { id: 'tx__27', name: '新歌榜', bangid: '27' }, { id: 'tx__62', name: '飙升榜', bangid: '62' }, { id: 'tx__58', name: '说唱榜', bangid: '58' }, { id: 'tx__57', name: '喜力电音榜', bangid: '57' }, { id: 'tx__28', name: '网络歌曲榜', bangid: '28' }, { id: 'tx__5', name: '内地榜', bangid: '5' }, { id: 'tx__3', name: '欧美榜', bangid: '3' }, { id: 'tx__59', name: '香港地区榜', bangid: '59' }, { id: 'tx__16', name: '韩国榜', bangid: '16' }, { id: 'tx__60', name: '抖快榜', bangid: '60' }, { id: 'tx__29', name: '影视金曲榜', bangid: '29' }, { id: 'tx__17', name: '日本榜', bangid: '17' }, { id: 'tx__52', name: '腾讯音乐人原创榜', bangid: '52' }, { id: 'tx__36', name: 'K歌金曲榜', bangid: '36' }, { id: 'tx__61', name: '台湾地区榜', bangid: '61' }, { id: 'tx__63', name: 'DJ舞曲榜', bangid: '63' }, { id: 'tx__64', name: '综艺新歌榜', bangid: '64' }, { id: 'tx__65', name: '国风热歌榜', bangid: '65' }, { id: 'tx__67', name: '听歌识曲榜', bangid: '67' }, { id: 'tx__72', name: '动漫音乐榜', bangid: '72' }, { id: 'tx__73', name: '游戏音乐榜', bangid: '73' }, { id: 'tx__75', name: '有声榜', bangid: '75' }, { id: 'tx__131', name: '校园音乐人排行榜', bangid: '131' }] export default { limit: 300, @@ -214,7 +214,8 @@ export default { // // console.log(response.body) // if (response.statusCode !== 200 || response.body.code !== 0) return this.getBoards(retryNum) // const list = this.filterBoardsData(response.body.data.topList) - // // console.log(list) + // console.log(list) + // console.log(JSON.stringify(list)) // this.list = list // return { // list, diff --git a/src/renderer/utils/musicSdk/wy/comment.js b/src/renderer/utils/musicSdk/wy/comment.js index 64082281..70134700 100644 --- a/src/renderer/utils/musicSdk/wy/comment.js +++ b/src/renderer/utils/musicSdk/wy/comment.js @@ -179,7 +179,7 @@ export default { return rawList.map(item => { let data = { id: item.commentId, - text: item.content ? applyEmoji(item.content).split('\n') : '', + text: item.content ? applyEmoji(item.content) : '', time: item.time ? item.time : '', timeStr: item.time ? dateFormat2(item.time) : '', userName: item.user.nickname, @@ -194,7 +194,7 @@ export default { ? { id: item.commentId, rootId: replyData.beRepliedCommentId, - text: replyData.content ? applyEmoji(replyData.content).split('\n') : '', + text: replyData.content ? applyEmoji(replyData.content) : '', time: item.time, timeStr: null, userName: replyData.user.nickname, diff --git a/src/renderer/utils/musicSdk/wy/index.js b/src/renderer/utils/musicSdk/wy/index.js index 73122433..5fdc0251 100644 --- a/src/renderer/utils/musicSdk/wy/index.js +++ b/src/renderer/utils/musicSdk/wy/index.js @@ -21,8 +21,7 @@ const wy = { }, getPic(songInfo) { const requestObj = getMusicInfo(songInfo.songmid) - requestObj.promise = requestObj.promise.then(info => info.al.picUrl) - return requestObj + return requestObj.promise.then(info => info.al.picUrl) }, getMusicDetailPageUrl(songInfo) { return `https://music.163.com/#/song?id=${songInfo.songmid}` diff --git a/src/renderer/utils/musicSdk/wy/leaderboard.js b/src/renderer/utils/musicSdk/wy/leaderboard.js index 09bb771b..474adfa7 100644 --- a/src/renderer/utils/musicSdk/wy/leaderboard.js +++ b/src/renderer/utils/musicSdk/wy/leaderboard.js @@ -2,45 +2,48 @@ import { weapi } from './utils/crypto' import { httpFetch } from '../../request' import musicDetailApi from './musicDetail' -const topList = [ - { id: 'wy__19723756', bangid: '19723756', name: '云音乐飙升榜' }, - { id: 'wy__3778678', bangid: '3778678', name: '云音乐热歌榜' }, - { id: 'wy__3779629', bangid: '3779629', name: '云音乐新歌榜' }, - { id: 'wy__2884035', bangid: '2884035', name: '云音乐原创榜' }, - { id: 'wy__2250011882', bangid: '2250011882', name: '抖音排行榜' }, - { id: 'wy__1978921795', bangid: '1978921795', name: '云音乐电音榜' }, - { id: 'wy__4395559', bangid: '4395559', name: '华语金曲榜' }, - { id: 'wy__71384707', bangid: '71384707', name: '云音乐古典音乐榜' }, - { id: 'wy__10520166', bangid: '10520166', name: '云音乐国电榜' }, - { id: 'wy__2006508653', bangid: '2006508653', name: '电竞音乐榜' }, - { id: 'wy__991319590', bangid: '991319590', name: '云音乐说唱榜' }, - { id: 'wy__180106', bangid: '180106', name: 'UK排行榜周榜' }, - { id: 'wy__60198', bangid: '60198', name: '美国Billboard周榜' }, - { id: 'wy__21845217', bangid: '21845217', name: 'KTV嗨榜' }, - { id: 'wy__11641012', bangid: '11641012', name: 'iTunes榜' }, - { id: 'wy__120001', bangid: '120001', name: 'Hit FM Top榜' }, - { id: 'wy__60131', bangid: '60131', name: '日本Oricon周榜' }, - { id: 'wy__3733003', bangid: '3733003', name: '韩国Melon排行榜周榜' }, - { id: 'wy__60255', bangid: '60255', name: '韩国Mnet排行榜周榜' }, - { id: 'wy__46772709', bangid: '46772709', name: '韩国Melon原声周榜' }, - { id: 'wy__64016', bangid: '64016', name: '中国TOP排行榜(内地榜)' }, - { id: 'wy__112504', bangid: '112504', name: '中国TOP排行榜(港台榜)' }, - { id: 'wy__3112516681', bangid: '3112516681', name: '中国新乡村音乐排行榜' }, - { id: 'wy__10169002', bangid: '10169002', name: '香港电台中文歌曲龙虎榜' }, - { id: 'wy__27135204', bangid: '27135204', name: '法国 NRJ EuroHot 30周榜' }, - { id: 'wy__1899724', bangid: '1899724', name: '中国嘻哈榜' }, - { id: 'wy__112463', bangid: '112463', name: '台湾Hito排行榜' }, - { id: 'wy__3812895', bangid: '3812895', name: 'Beatport全球电子舞曲榜' }, - { id: 'wy__2617766278', bangid: '2617766278', name: '新声榜' }, - { id: 'wy__745956260', bangid: '745956260', name: '云音乐韩语榜' }, - { id: 'wy__2847251561', bangid: '2847251561', name: '说唱TOP榜' }, - { id: 'wy__2023401535', bangid: '2023401535', name: '英国Q杂志中文版周榜' }, - { id: 'wy__2809513713', bangid: '2809513713', name: '云音乐欧美热歌榜' }, - { id: 'wy__2809577409', bangid: '2809577409', name: '云音乐欧美新歌榜' }, - { id: 'wy__71385702', bangid: '71385702', name: '云音乐ACG音乐榜' }, - { id: 'wy__3001835560', bangid: '3001835560', name: '云音乐ACG动画榜' }, - { id: 'wy__3001795926', bangid: '3001795926', name: '云音乐ACG游戏榜' }, - { id: 'wy__3001890046', bangid: '3001890046', name: '云音乐ACG VOCALOID榜' }, +const topList = [{ id: 'wy__19723756', name: '飙升榜', bangid: '19723756' }, + { id: 'wy__3779629', name: '新歌榜', bangid: '3779629' }, + { id: 'wy__2884035', name: '原创榜', bangid: '2884035' }, + { id: 'wy__3778678', name: '热歌榜', bangid: '3778678' }, + { id: 'wy__991319590', name: '云音乐说唱榜', bangid: '991319590' }, + { id: 'wy__71384707', name: '云音乐古典榜', bangid: '71384707' }, + { id: 'wy__1978921795', name: '云音乐电音榜', bangid: '1978921795' }, + { id: 'wy__5453912201', name: '黑胶VIP爱听榜', bangid: '5453912201' }, + { id: 'wy__71385702', name: '云音乐ACG榜', bangid: '71385702' }, + { id: 'wy__745956260', name: '云音乐韩语榜', bangid: '745956260' }, + { id: 'wy__10520166', name: '云音乐国电榜', bangid: '10520166' }, + { id: 'wy__180106', name: 'UK排行榜周榜', bangid: '180106' }, + { id: 'wy__60198', name: '美国Billboard榜', bangid: '60198' }, + { id: 'wy__3812895', name: 'Beatport全球电子舞曲榜', bangid: '3812895' }, + { id: 'wy__21845217', name: 'KTV唛榜', bangid: '21845217' }, + { id: 'wy__60131', name: '日本Oricon榜', bangid: '60131' }, + { id: 'wy__2809513713', name: '云音乐欧美热歌榜', bangid: '2809513713' }, + { id: 'wy__2809577409', name: '云音乐欧美新歌榜', bangid: '2809577409' }, + { id: 'wy__27135204', name: '法国 NRJ Vos Hits 周榜', bangid: '27135204' }, + { id: 'wy__3001835560', name: '云音乐ACG动画榜', bangid: '3001835560' }, + { id: 'wy__3001795926', name: '云音乐ACG游戏榜', bangid: '3001795926' }, + { id: 'wy__3001890046', name: '云音乐ACG VOCALOID榜', bangid: '3001890046' }, + { id: 'wy__3112516681', name: '中国新乡村音乐排行榜', bangid: '3112516681' }, + { id: 'wy__5059644681', name: '云音乐日语榜', bangid: '5059644681' }, + { id: 'wy__5059633707', name: '云音乐摇滚榜', bangid: '5059633707' }, + { id: 'wy__5059642708', name: '云音乐国风榜', bangid: '5059642708' }, + { id: 'wy__5338990334', name: '潜力爆款榜', bangid: '5338990334' }, + { id: 'wy__5059661515', name: '云音乐民谣榜', bangid: '5059661515' }, + { id: 'wy__6688069460', name: '听歌识曲榜', bangid: '6688069460' }, + { id: 'wy__6723173524', name: '网络热歌榜', bangid: '6723173524' }, + { id: 'wy__6732051320', name: '俄语榜', bangid: '6732051320' }, + { id: 'wy__6732014811', name: '越南语榜', bangid: '6732014811' }, + { id: 'wy__6886768100', name: '中文DJ榜', bangid: '6886768100' }, + { id: 'wy__6939992364', name: '俄罗斯top hit流行音乐榜', bangid: '6939992364' }, + { id: 'wy__7095271308', name: '泰语榜', bangid: '7095271308' }, + { id: 'wy__7356827205', name: 'BEAT排行榜', bangid: '7356827205' }, + { id: 'wy__7325478166', name: '编辑推荐榜VOL.44 天才女子摇滚乐队boygenius剖白卑微心迹', bangid: '7325478166' }, + { id: 'wy__7603212484', name: 'LOOK直播歌曲榜', bangid: '7603212484' }, + { id: 'wy__7775163417', name: '赏音榜', bangid: '7775163417' }, + { id: 'wy__7785123708', name: '黑胶VIP新歌榜', bangid: '7785123708' }, + { id: 'wy__7785066739', name: '黑胶VIP热歌榜', bangid: '7785066739' }, + { id: 'wy__7785091694', name: '黑胶VIP爱搜榜', bangid: '7785091694' }, ] export default { diff --git a/src/renderer/utils/musicSdk/xm.js b/src/renderer/utils/musicSdk/xm.js index 5142a0db..a11b126b 100644 --- a/src/renderer/utils/musicSdk/xm.js +++ b/src/renderer/utils/musicSdk/xm.js @@ -36,9 +36,7 @@ const xm = { // return lyric.getLyric(songInfo) }, getPic(songInfo) { - return { - promise: Promise.reject(new Error('fail')), - } + return Promise.reject(new Error('fail')) // return pic.getPic(songInfo) }, // getMusicDetailPageUrl(songInfo) {