From 0a4fd996594a8e56e1fc9369182286e8482bc9f1 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Mon, 26 Dec 2022 17:42:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtx=E6=BA=90=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- publish/changeLog.md | 2 +- src/utils/listData.js | 2 + src/utils/music/tx/comment.js | 25 ++++++++- src/utils/music/tx/musicInfo.js | 98 +++++++++++++++++++++++++++++++++ 5 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 src/utils/music/tx/musicInfo.js diff --git a/package.json b/package.json index 110ac5a..0d80027 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lx-music-mobile", - "version": "0.15.4", + "version": "0.15.5-beta", "versionCode": 51, "scripts": { "ar": "react-native run-android", diff --git a/publish/changeLog.md b/publish/changeLog.md index 34efa24..247736d 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -1,3 +1,3 @@ ### 修复 -- 修复播放详情页歌词翻译、罗马音歌词匹配问题 +- 修复tx源评论加载失败的问题 diff --git a/src/utils/listData.js b/src/utils/listData.js index 7459cdb..521d9c3 100644 --- a/src/utils/listData.js +++ b/src/utils/listData.js @@ -30,6 +30,7 @@ export const toNewMusicInfo = (oldMusicInfo) => { case 'tx': meta.strMediaMid = oldMusicInfo.strMediaMid meta.albumMid = oldMusicInfo.albumMid + meta.id = oldMusicInfo.songId break case 'mg': meta.copyrightId = oldMusicInfo.copyrightId @@ -79,6 +80,7 @@ export const toOldMusicInfo = (minfo) => { case 'tx': oInfo.strMediaMid = minfo.meta.strMediaMid oInfo.albumMid = minfo.meta.albumMid + oInfo.songId = minfo.meta.id break case 'mg': oInfo.copyrightId = minfo.meta.copyrightId diff --git a/src/utils/music/tx/comment.js b/src/utils/music/tx/comment.js index 6003cd2..10adf5c 100644 --- a/src/utils/music/tx/comment.js +++ b/src/utils/music/tx/comment.js @@ -1,5 +1,6 @@ import { httpFetch } from '../../request' -import { dateFormat2 } from '../../' +import { dateFormat2 } from '../../index' +import getMusicInfo from './musicInfo' const emojis = { e400846: '😘', @@ -70,12 +71,28 @@ const emojis = { e400432: '👑', } +const songIdMap = new Map() +const promises = new Map() + export default { _requestObj: null, _requestObj2: null, - async getComment({ songId }, page = 1, limit = 20) { + async getSongId({ songId, songmid }) { + if (songId) return songId + if (songIdMap.has(songmid)) return songIdMap.get(songmid) + if (promises.has(songmid)) return (await promises.get(songmid)).songId + const promise = getMusicInfo(songmid) + promises.set(promise) + const info = await promise + songIdMap.set(songmid, info.songId) + promises.delete(songmid) + return info.songId + }, + async getComment(mInfo, page = 1, limit = 20) { if (this._requestObj) this._requestObj.cancelHttp() + const songId = await this.getSongId(mInfo) + const _requestObj = httpFetch('http://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg', { method: 'POST', headers: { @@ -107,9 +124,11 @@ export default { maxPage: Math.ceil(comment.commenttotal / limit) || 1, } }, - async getHotComment({ songId }, page = 1, limit = 100) { + async getHotComment(mInfo, page = 1, limit = 100) { 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: { diff --git a/src/utils/music/tx/musicInfo.js b/src/utils/music/tx/musicInfo.js new file mode 100644 index 0000000..ab059e8 --- /dev/null +++ b/src/utils/music/tx/musicInfo.js @@ -0,0 +1,98 @@ +import { httpFetch } from '../../request' +import { formatPlayTime, sizeFormate } from '../../index' + +const getSinger = (singers) => { + let arr = [] + singers.forEach(singer => { + arr.push(singer.name) + }) + return arr.join('、') +} + +export default (songmid) => { + const requestObj = httpFetch('https://u.y.qq.com/cgi-bin/musicu.fcg', { + method: 'post', + headers: { + 'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)', + }, + body: { + comm: { + ct: '19', + cv: '1859', + uin: '0', + }, + req: { + module: 'music.pf_song_detail_svr', + method: 'get_song_detail_yqq', + param: { + song_type: 0, + song_mid: songmid, + }, + }, + }, + }) + return requestObj.promise.then(({ body }) => { + // console.log(body) + if (body.code != 0 || body.req.code != 0) return Promise.reject('获取歌曲信息失败') + const item = body.req.data.track_info + if (!item.file?.media_mid) return null + + let types = [] + let _types = {} + const file = item.file + if (file.size_128mp3 != 0) { + let size = sizeFormate(file.size_128mp3) + types.push({ type: '128k', size }) + _types['128k'] = { + size, + } + } + if (file.size_320mp3 !== 0) { + let size = sizeFormate(file.size_320mp3) + types.push({ type: '320k', size }) + _types['320k'] = { + size, + } + } + if (file.size_flac !== 0) { + let size = sizeFormate(file.size_flac) + types.push({ type: 'flac', size }) + _types.flac = { + size, + } + } + if (file.size_hires !== 0) { + let size = sizeFormate(file.size_hires) + types.push({ type: 'flac24bit', size }) + _types.flac24bit = { + size, + } + } + // types.reverse() + let albumId = '' + let albumName = '' + if (item.album) { + albumName = item.album.title + albumId = item.album.mid + } + return { + singer: getSinger(item.singer), + name: item.title, + albumName, + albumId, + source: 'tx', + interval: formatPlayTime(item.interval), + songId: item.id, + albumMid: item.album?.mid ?? '', + strMediaMid: item.file.media_mid, + songmid: item.mid, + img: (albumId === '' || albumId === '空') + ? `https://y.gtimg.cn/music/photo_new/T001R500x500M000${item.singer[0]?.mid}.jpg` + : `https://y.gtimg.cn/music/photo_new/T002R500x500M000${albumId}.jpg`, + types, + _types, + typeUrl: {}, + } + }) +} +