修复tx源评论加载失败的问题

This commit is contained in:
lyswhut 2022-12-26 17:42:56 +08:00
parent c93146ab0c
commit 0a4fd99659
5 changed files with 124 additions and 5 deletions

View File

@ -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",

View File

@ -1,3 +1,3 @@
### 修复
- 修复播放详情页歌词翻译、罗马音歌词匹配问题
- 修复tx源评论加载失败的问题

View File

@ -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

View File

@ -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: {

View File

@ -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: {},
}
})
}