From ad5b82d7e78af0dfbe5fc94f9261103ed3fbebb9 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Thu, 11 Aug 2022 15:48:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BC=81=E9=B9=85=E9=9F=B3?= =?UTF-8?q?=E4=B9=90=E6=90=9C=E7=B4=A2=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 1 + src/components/OnlineList/ListItem.js | 7 +- src/lang/en_us.json | 1 + src/lang/zh_cn.json | 1 + src/utils/music/kw/album.js | 6 ++ src/utils/music/kw/leaderboard.js | 6 ++ src/utils/music/kw/musicSearch.js | 65 ++++++++---------- src/utils/music/kw/songList.js | 44 ++++++------ src/utils/music/tx/leaderboard.js | 51 ++++++++------ src/utils/music/tx/musicSearch.js | 96 ++++++++++++++++++--------- src/utils/music/tx/songList.js | 14 ++-- src/utils/music/wy/musicDetail.js | 3 +- src/utils/music/wy/musicSearch.js | 3 +- 13 files changed, 176 insertions(+), 122 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index ed3fe73..8c5fcf3 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -1,3 +1,4 @@ ### 修复 - 修复排行榜在旋转屏幕后,选中的榜单被重置回第一个的问题 +- 修复企鹅音乐搜索失效的问题 diff --git a/src/components/OnlineList/ListItem.js b/src/components/OnlineList/ListItem.js index 4235aed..beab3c4 100644 --- a/src/components/OnlineList/ListItem.js +++ b/src/components/OnlineList/ListItem.js @@ -1,7 +1,7 @@ import React, { useCallback, memo, useRef, useMemo } from 'react' import { StyleSheet, View, Text, TouchableOpacity } from 'react-native' import { useGetter } from '@/store' -import Button from '@/components/common/Button' +// import Button from '@/components/common/Button' import Badge from '@/components/common/Badge' import { BorderWidths } from '@/theme' import { useTranslation } from '@/plugins/i18n' @@ -10,7 +10,10 @@ import { Icon } from '@/components/common/Icon' const useQualityTag = musicInfo => { const { t } = useTranslation() let info = {} - if (musicInfo._types.ape || musicInfo._types.flac) { + if (musicInfo._types.flac32bit) { + info.type = 'secondary' + info.text = t('quality_lossless_24bit') + } else if (musicInfo._types.ape || musicInfo._types.flac) { info.type = 'secondary' info.text = t('quality_lossless') } else if (musicInfo._types['320k']) { diff --git a/src/lang/en_us.json b/src/lang/en_us.json index d0a5dad..fc504db 100644 --- a/src/lang/en_us.json +++ b/src/lang/en_us.json @@ -100,6 +100,7 @@ "player_setting_lrc_font_size": "Lyric font size setting", "quality_high_quality": "HQ", "quality_lossless": "SQ", + "quality_lossless_24bit": "24bit", "setting_about": "About LX Music", "setting_backup": "Backup and Recovery", "setting_backup_all": "All data (list data and setting data)", diff --git a/src/lang/zh_cn.json b/src/lang/zh_cn.json index 1b07022..e842e5f 100644 --- a/src/lang/zh_cn.json +++ b/src/lang/zh_cn.json @@ -101,6 +101,7 @@ "player_setting_lrc_font_size": "歌词字体大小设置", "quality_high_quality": "高品质", "quality_lossless": "无损", + "quality_lossless_24bit": "24bit", "setting_about": "关于洛雪音乐", "setting_backup": "备份与恢复", "setting_backup_all": "所有数据(列表数据与设置数据)", diff --git a/src/utils/music/kw/album.js b/src/utils/music/kw/album.js index 52407b2..5110ca0 100644 --- a/src/utils/music/kw/album.js +++ b/src/utils/music/kw/album.js @@ -43,6 +43,12 @@ export default { size: null, } } + if (formats.includes('HIRFLAC')) { + types.push({ type: 'flac32bit', size: null }) + _types.flac32bit = { + size: null, + } + } // types.reverse() return { singer: formatSinger(decodeName(item.artist)), diff --git a/src/utils/music/kw/leaderboard.js b/src/utils/music/kw/leaderboard.js index 4003f27..626d035 100644 --- a/src/utils/music/kw/leaderboard.js +++ b/src/utils/music/kw/leaderboard.js @@ -115,6 +115,12 @@ export default { size: null, } } + if (formats.includes('HIRFLAC')) { + types.push({ type: 'flac32bit', size: null }) + _types.flac32bit = { + size: null, + } + } // types.reverse() return { singer: formatSinger(decodeName(item.artist)), diff --git a/src/utils/music/kw/musicSearch.js b/src/utils/music/kw/musicSearch.js index 9ecf04c..dea0a40 100644 --- a/src/utils/music/kw/musicSearch.js +++ b/src/utils/music/kw/musicSearch.js @@ -7,7 +7,7 @@ import { formatSinger } from './util' export default { regExps: { - mInfo: /bitrate:(\d+),format:(\w+),size:([\w.]+)/, + mInfo: /level:(\w+),bitrate:(\d+),format:(\w+),size:([\w.]+)/, }, limit: 30, total: 0, @@ -27,61 +27,53 @@ export default { handleResult(rawData) { const result = [] if (!rawData) return result + // console.log(rawData) for (let i = 0; i < rawData.length; i++) { const info = rawData[i] let songId = info.MUSICRID.replace('MUSIC_', '') // const format = (info.FORMATS || info.formats).split('|') - if (!info.MINFO) { - console.log('mInfo is undefined') + if (!info.N_MINFO) { + console.log('N_MINFO is undefined') return null } const types = [] const _types = {} - let infoArr = info.MINFO.split(';') - infoArr.forEach(info => { + let infoArr = info.N_MINFO.split(';') + for (let info of infoArr) { info = info.match(this.regExps.mInfo) if (info) { switch (info[2]) { - case 'flac': - types.push({ type: 'flac', size: info[3] }) - _types.flac = { - size: info[3].toLocaleUpperCase(), + case '4000': + types.push({ type: 'flac32bit', size: info[4] }) + _types.flac32bit = { + size: info[4].toLocaleUpperCase(), } break - // case 'ape': - // types.push({ type: 'ape', size: info[3] }) - // _types.ape = { - // size: info[3].toLocaleUpperCase(), - // } - // break - case 'mp3': - switch (info[1]) { - case '320': - types.push({ type: '320k', size: info[3] }) - _types['320k'] = { - size: info[3].toLocaleUpperCase(), - } - break - case '192': - // types.push({ type: '192k', size: info[3] }) - // _types['192k'] = { - // size: info[3].toLocaleUpperCase(), - // } - // break - case '128': - types.push({ type: '128k', size: info[3] }) - _types['128k'] = { - size: info[3].toLocaleUpperCase(), - } - break + case '2000': + types.push({ type: 'flac', size: info[4] }) + _types.flac = { + size: info[4].toLocaleUpperCase(), + } + break + case '320': + types.push({ type: '320k', size: info[4] }) + _types['320k'] = { + size: info[4].toLocaleUpperCase(), + } + break + case '192': + case '128': + types.push({ type: '128k', size: info[4] }) + _types['128k'] = { + size: info[4].toLocaleUpperCase(), } break } } - }) + } types.reverse() let interval = parseInt(info.DURATION) @@ -105,6 +97,7 @@ export default { typeUrl: {}, }) } + // console.log(result) return result }, search(str, page = 1, { limit } = {}, retryNum = 0) { diff --git a/src/utils/music/kw/songList.js b/src/utils/music/kw/songList.js index 81d1ece..79788eb 100644 --- a/src/utils/music/kw/songList.js +++ b/src/utils/music/kw/songList.js @@ -23,7 +23,7 @@ export default { }, ], regExps: { - mInfo: /bitrate:(\d+),format:(\w+),size:([\w.]+)/, + mInfo: /level:(\w+),bitrate:(\d+),format:(\w+),size:([\w.]+)/, // http://www.kuwo.cn/playlist_detail/2886046289 // https://m.kuwo.cn/h5app/playlist/2736267853?t=qqfriend listDetailLink: /^.+\/playlist(?:_detail)?\/(\d+)(?:\?.*|&.*$|#.*$|$)/, @@ -246,34 +246,36 @@ export default { filterListDetail(rawData) { // console.log(rawData) return rawData.map(item => { - let infoArr = item.MINFO.split(';') + let infoArr = item.N_MINFO.split(';') let types = [] let _types = {} for (let info of infoArr) { info = info.match(this.regExps.mInfo) if (info) { switch (info[2]) { - case 'flac': - types.push({ type: 'flac', size: info[3] }) - _types.flac = { - size: info[3].toLocaleUpperCase(), + case '4000': + types.push({ type: 'flac32bit', size: info[4] }) + _types.flac32bit = { + size: info[4].toLocaleUpperCase(), } break - case 'mp3': - switch (info[1]) { - case '320': - types.push({ type: '320k', size: info[3] }) - _types['320k'] = { - size: info[3].toLocaleUpperCase(), - } - break - case '192': - case '128': - types.push({ type: '128k', size: info[3] }) - _types['128k'] = { - size: info[3].toLocaleUpperCase(), - } - break + case '2000': + types.push({ type: 'flac', size: info[4] }) + _types.flac = { + size: info[4].toLocaleUpperCase(), + } + break + case '320': + types.push({ type: '320k', size: info[4] }) + _types['320k'] = { + size: info[4].toLocaleUpperCase(), + } + break + case '192': + case '128': + types.push({ type: '128k', size: info[4] }) + _types['128k'] = { + size: info[4].toLocaleUpperCase(), } break } diff --git a/src/utils/music/tx/leaderboard.js b/src/utils/music/tx/leaderboard.js index 77355b8..b01e73b 100644 --- a/src/utils/music/tx/leaderboard.js +++ b/src/utils/music/tx/leaderboard.js @@ -62,22 +62,31 @@ export default { bangid: 128, }, ], - getUrl(id, period, limit) { - return `https://u.y.qq.com/cgi-bin/musicu.fcg?format=json&inCharset=utf8&outCharset=utf-8&platform=yqq.json&needNewCode=0&data=${encodeURIComponent(JSON.stringify({ - comm: { - cv: 1602, - ct: 20, + listDetailRequest(id, period, limit) { + // console.log(id, period, limit) + return 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)', }, - toplist: { - module: 'musicToplist.ToplistInfoServer', - method: 'GetDetail', - param: { - topid: id, - num: limit, - period, + body: { + toplist: { + module: 'musicToplist.ToplistInfoServer', + method: 'GetDetail', + param: { + topid: id, + num: limit, + period, + }, + }, + comm: { + uin: 0, + format: 'json', + ct: 20, + cv: 1859, }, }, - }))}` + }).promise }, regExps: { periodList: //g, @@ -121,13 +130,6 @@ export default { size, } } - if (item.file.size_ape !== 0) { - let size = sizeFormate(item.file.size_ape) - types.push({ type: 'ape', size }) - _types.ape = { - size, - } - } if (item.file.size_flac !== 0) { let size = sizeFormate(item.file.size_flac) types.push({ type: 'flac', size }) @@ -135,6 +137,13 @@ export default { size, } } + if (item.file.size_hires !== 0) { + let size = sizeFormate(item.file.size_hires) + types.push({ type: 'flac32bit', size }) + _types.flac32bit = { + size, + } + } // types.reverse() return { singer: this.getSinger(item.singer), @@ -223,7 +232,7 @@ export default { let info = this.periods[bangid] let p = info ? Promise.resolve(info.period) : this.getPeriods(bangid) return p.then(period => { - return this.getData(this.getUrl(bangid, period, this.limit)).then(resp => { + return this.listDetailRequest(bangid, period, this.limit).then(resp => { if (resp.body.code !== 0) return this.getList(bangid, page, retryNum) return { total: resp.body.toplist.data.songInfoList.length, diff --git a/src/utils/music/tx/musicSearch.js b/src/utils/music/tx/musicSearch.js index 563a92a..15b7fba 100644 --- a/src/utils/music/tx/musicSearch.js +++ b/src/utils/music/tx/musicSearch.js @@ -1,12 +1,12 @@ // import '../../polyfill/array.find' -// import jshtmlencode from 'js-htmlencode' + import { httpFetch } from '../../request' import { formatPlayTime, sizeFormate } from '../../index' // import { debug } from '../../utils/env' // import { formatSinger } from './util' export default { - limit: 30, + limit: 50, total: 0, page: 0, allPage: 1, @@ -14,11 +14,35 @@ export default { musicSearch(str, page, limit, retryNum = 0) { if (retryNum > 5) return Promise.reject(new Error('搜索失败')) // searchRequest = httpFetch(`https://c.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&new_json=1&remoteplace=sizer.yqq.song_next&searchid=49252838123499591&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=${page}&n=${limit}&w=${encodeURIComponent(str)}&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq&needNewCode=0`) - const searchRequest = httpFetch(`https://shc.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&remoteplace=txt.yqq.top&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=${page}&n=${limit}&w=${encodeURIComponent(str)}&cv=4747474&ct=24&format=json&inCharset=utf-8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=0&uin=0&hostUin=0&loginUin=0`) + // const searchRequest = httpFetch(`https://shc.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&remoteplace=txt.yqq.top&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=${page}&n=${limit}&w=${encodeURIComponent(str)}&cv=4747474&ct=24&format=json&inCharset=utf-8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=0&uin=0&hostUin=0&loginUin=0`) + const searchRequest = 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: { + method: 'DoSearchForQQMusicDesktop', + module: 'music.search.SearchCgiService', + param: { + grp: 1, + num_per_page: limit, + page_num: page, + query: str, + search_type: 0, + }, + }, + }, + }) // searchRequest = httpFetch(`http://ioscdn.kugou.com/api/v3/search/song?keyword=${encodeURIComponent(str)}&page=${page}&pagesize=${this.limit}&showtype=10&plat=2&version=7910&tag=1&correct=1&privilege=1&sver=5`) return searchRequest.promise.then(({ body }) => { - if (body.code !== this.successCode) return this.musicSearch(str, page, limit, ++retryNum) - return body.data + if (body.code != this.successCode || body.req.code != this.successCode) return this.musicSearch(str, page, limit, ++retryNum) + return body.req.data }) }, getSinger(singers) { @@ -32,69 +56,75 @@ export default { // console.log(rawList) const list = [] rawList.forEach(item => { - if (!item.strMediaMid) return + if (!item.file?.media_mid) return let types = [] let _types = {} - if (item.size128 !== 0) { - let size = sizeFormate(item.size128) + const file = item.file + if (file.size_128mp3 != 0) { + let size = sizeFormate(file.size_128mp3) types.push({ type: '128k', size }) _types['128k'] = { size, } } - if (item.size320 !== 0) { - let size = sizeFormate(item.size320) + if (file.size_320mp3 !== 0) { + let size = sizeFormate(file.size_320mp3) types.push({ type: '320k', size }) _types['320k'] = { size, } } - if (item.sizeape !== 0) { - let size = sizeFormate(item.sizeape) - types.push({ type: 'ape', size }) - _types.ape = { - size, - } - } - if (item.sizeflac !== 0) { - let size = sizeFormate(item.sizeflac) + 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: 'flac32bit', size }) + _types.flac32bit = { + size, + } + } // types.reverse() + let albumId = '' + let albumName = '' + if (item.album) { + albumName = item.album.title + albumId = item.album.mid + } list.push({ singer: this.getSinger(item.singer), - name: item.songname, - albumName: item.albumname, - albumId: item.albummid, + name: item.title, + albumName, + albumId, source: 'tx', interval: formatPlayTime(item.interval), - songId: item.songid, - albumMid: item.albummid, - strMediaMid: item.strMediaMid, - songmid: item.songmid, - img: (item.albummid === '' || item.albummid === '空') + 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${item.albummid}.jpg`, - lrc: null, - otherSource: null, + : `https://y.gtimg.cn/music/photo_new/T002R500x500M000${albumId}.jpg`, types, _types, typeUrl: {}, }) }) + // console.log(list) return list }, search(str, page = 1, { limit } = {}) { if (limit == null) limit = this.limit // http://newlyric.kuwo.cn/newlyric.lrc?62355680 - return this.musicSearch(str, page, limit).then(({ song }) => { - let list = this.handleResult(song.list) + return this.musicSearch(str, page, limit).then(({ body, meta }) => { + let list = this.handleResult(body.song.list) - this.total = song.totalnum + this.total = meta.sum this.page = page this.allPage = Math.ceil(this.total / limit) diff --git a/src/utils/music/tx/songList.js b/src/utils/music/tx/songList.js index 2c9d92d..40a6429 100644 --- a/src/utils/music/tx/songList.js +++ b/src/utils/music/tx/songList.js @@ -255,13 +255,6 @@ export default { size, } } - if (item.file.size_ape !== 0) { - let size = sizeFormate(item.file.size_ape) - types.push({ type: 'ape', size }) - _types.ape = { - size, - } - } if (item.file.size_flac !== 0) { let size = sizeFormate(item.file.size_flac) types.push({ type: 'flac', size }) @@ -269,6 +262,13 @@ export default { size, } } + if (item.file.size_hires !== 0) { + let size = sizeFormate(item.file.size_hires) + types.push({ type: 'flac32bit', size }) + _types.flac32bit = { + size, + } + } // types.reverse() return { singer: this.getSinger(item.singer), diff --git a/src/utils/music/wy/musicDetail.js b/src/utils/music/wy/musicDetail.js index 4be288f..4b0ac34 100644 --- a/src/utils/music/wy/musicDetail.js +++ b/src/utils/music/wy/musicDetail.js @@ -24,7 +24,7 @@ export default { switch (privilege.maxbr) { case 999000: - size = null + size = item.sq ? sizeFormate(item.sq.size) : null types.push({ type: 'flac', size }) _types.flac = { size, @@ -62,6 +62,7 @@ export default { typeUrl: {}, }) }) + // console.log(list) return list }, async getList(ids = [], retryNum = 0) { diff --git a/src/utils/music/wy/musicSearch.js b/src/utils/music/wy/musicSearch.js index 59467c8..85e278b 100644 --- a/src/utils/music/wy/musicSearch.js +++ b/src/utils/music/wy/musicSearch.js @@ -35,7 +35,7 @@ export default { let size switch (item.privilege.maxbr) { case 999000: - size = null + size = item.sq ? sizeFormate(item.sq.size) : null types.push({ type: 'flac', size }) _types.flac = { size, @@ -80,6 +80,7 @@ export default { // console.log(result) if (!result || result.code !== 200) return this.search(str, page, { limit }, retryNum) let list = this.handleResult(result.result.songs || []) + // console.log(list) if (list == null) return this.search(str, page, { limit }, retryNum)