diff --git a/src/renderer/utils/index.ts b/src/renderer/utils/index.ts index 5b885c20..efdfa182 100644 --- a/src/renderer/utils/index.ts +++ b/src/renderer/utils/index.ts @@ -1,26 +1,10 @@ -import { dateFormat, decodeName } from '@common/utils/common' +import { dateFormat } from '@common/utils/common' export * from '@common/utils/renderer' export * from '@common/utils/nodejs' export * from '@common/utils/common' export * from '@common/utils/tools' -/** - * 获取歌手 - * @param singers 歌手数组 - * @param obj 读取的数据 - * @param join 插入的字符 - */ -export const getSingerName = (singers: [], obj = 'name', join = '、') => { - const singer: string[] = [] - singers.forEach(item => { - let name = item[obj] - if (!name) return - singer.push(name) - }) - return decodeName(singer.join(join)) -} - /** * 时间格式化 */ diff --git a/src/renderer/utils/musicSdk/kg/leaderboard.js b/src/renderer/utils/musicSdk/kg/leaderboard.js index e2464006..d9821f29 100644 --- a/src/renderer/utils/musicSdk/kg/leaderboard.js +++ b/src/renderer/utils/musicSdk/kg/leaderboard.js @@ -1,5 +1,6 @@ import { httpFetch } from '../../request' -import { decodeName, formatPlayTime, sizeFormate, getSingerName } from '../../index' +import { decodeName, formatPlayTime, sizeFormate } from '../../index' +import { formatSingerName } from '../utils' 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' }] @@ -126,7 +127,7 @@ export default { } } return { - singer: getSingerName(item.authors, 'author_name'), + singer: formatSingerName(item.authors, 'author_name'), name: decodeName(item.songname), albumName: decodeName(item.remark), albumId: item.album_id, diff --git a/src/renderer/utils/musicSdk/kg/songList.js b/src/renderer/utils/musicSdk/kg/songList.js index 61bd3a37..34ff92cd 100644 --- a/src/renderer/utils/musicSdk/kg/songList.js +++ b/src/renderer/utils/musicSdk/kg/songList.js @@ -1,5 +1,6 @@ import { httpFetch } from '../../request' -import { decodeName, formatPlayTime, sizeFormate, dateFormat, getSingerName } from '../../index' +import { formatSingerName } from '../utils' +import { decodeName, formatPlayTime, sizeFormate, dateFormat } from '../../index' import { signatureParams, createHttpFetch } from './util' import { getMusicInfosByList } from './musicInfo' import album from './album' @@ -413,7 +414,7 @@ export default { }) list.push({ - singer: getSingerName(item.singerinfo, 'name') || decodeName(item.name).split(' - ')[0].replace(/&/g, '、'), + singer: formatSingerName(item.singerinfo, 'name') || decodeName(item.name).split(' - ')[0].replace(/&/g, '、'), name: decodeName(item.name).split(' - ')[1], albumName: decodeName(item.albuminfo.name), albumId: item.albuminfo.id, diff --git a/src/renderer/utils/musicSdk/mg/album.js b/src/renderer/utils/musicSdk/mg/album.js index a41c95cb..342db14a 100644 --- a/src/renderer/utils/musicSdk/mg/album.js +++ b/src/renderer/utils/musicSdk/mg/album.js @@ -1,18 +1,9 @@ -import { httpFetch } from '../../request' +import { createHttpFetch } from './utils' 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`) - requestObj.promise = requestObj.promise.then(({ body }) => { - if (body.code !== '000000') { - if (tryNum > 5) return Promise.reject('获取专辑失败') - let tryRequestObj = this.getAlbum(songInfo, ++tryNum) - requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj) - return tryRequestObj.promise - } - // console.log(body) + getAlbumSong(songInfo) { + return createHttpFetch(`http://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/queryAlbumSong?albumId=${songInfo.albumId}&pageNo=1`).then(body => { return body.songList }) - return requestObj }, } diff --git a/src/renderer/utils/musicSdk/mg/lyric.js b/src/renderer/utils/musicSdk/mg/lyric.js index 4f03e2c8..a800a1ae 100644 --- a/src/renderer/utils/musicSdk/mg/lyric.js +++ b/src/renderer/utils/musicSdk/mg/lyric.js @@ -1,107 +1,6 @@ import { httpFetch } from '../../request' import { getMusicInfo } from './musicInfo' - -// const key = 'karakal@123Qcomyidongtiantianhaoting' -const DELTA = 2654435769n -const MIN_LENGTH = 32 -// const SPECIAL_CHAR = '0' -const keyArr = [ - 27303562373562475n, - 18014862372307051n, - 22799692160172081n, - 34058940340699235n, - 30962724186095721n, - 27303523720101991n, - 27303523720101998n, - 31244139033526382n, - 28992395054481524n, -] - -const teaDecrypt = (data, key) => { - const length = data.length - const lengthBitint = BigInt(length) - if (length >= 1) { - // let j = data[data.length - 1]; - let j2 = data[0] - let j3 = toLong((6n + (52n / lengthBitint)) * DELTA) - while (true) { - let j4 = j3 - if (j4 == 0n) break - let j5 = toLong(3n & toLong(j4 >> 2n)) - let j6 = lengthBitint - while (true) { - j6-- - if (j6 > 0n) { - let j7 = data[(j6 - 1n)] - let i = j6 - j2 = toLong(data[i] - (toLong(toLong(j2 ^ j4) + toLong(j7 ^ key[toLong(toLong(3n & j6) ^ j5)])) ^ toLong(toLong(toLong(j7 >> 5n) ^ toLong(j2 << 2n)) + toLong(toLong(j2 >> 3n) ^ toLong(j7 << 4n))))) - data[i] = j2 - } else break - } - let j8 = data[lengthBitint - 1n] - j2 = toLong(data[0n] - toLong(toLong(toLong(key[toLong(toLong(j6 & 3n) ^ j5)] ^ j8) + toLong(j2 ^ j4)) ^ toLong(toLong(toLong(j8 >> 5n) ^ toLong(j2 << 2n)) + toLong(toLong(j2 >> 3n) ^ toLong(j8 << 4n))))) - data[0] = j2 - j3 = toLong(j4 - DELTA) - } - } - return data -} - -const longArrToString = (data) => { - const arrayList = [] - for (const j of data) arrayList.push(longToBytes(j).toString('utf16le')) - return arrayList.join('') -} - -// https://stackoverflow.com/a/29132118 -const longToBytes = (l) => { - const result = Buffer.alloc(8) - for (let i = 0; i < 8; i++) { - result[i] = parseInt(l & 0xFFn) - l >>= 8n - } - return result -} - - -const toBigintArray = (data) => { - const length = Math.floor(data.length / 16) - const jArr = Array(length) - for (let i = 0; i < length; i++) { - jArr[i] = toLong(data.substring(i * 16, (i * 16) + 16)) - } - return jArr -} - -// https://github.com/lyswhut/lx-music-desktop/issues/445#issuecomment-1139338682 -const MAX = 9223372036854775807n -const MIN = -9223372036854775808n -const toLong = str => { - const num = typeof str == 'string' ? BigInt('0x' + str) : str - if (num > MAX) return toLong(num - (1n << 64n)) - else if (num < MIN) return toLong(num + (1n << 64n)) - return num -} - -const mrcDecrypt = (data) => { - // console.log(data.length) - // -3551594764563790630 - // console.log(toLongArrayFromArr(Buffer.from(key))) - // console.log(teaDecrypt(toBigintArray(data), keyArr)) - // console.log(longArrToString(teaDecrypt(toBigintArray(data), keyArr))) - // console.log(toByteArray(teaDecrypt(toBigintArray(data), keyArr))) - return (data == null || data.length < MIN_LENGTH) - ? data - : longArrToString(teaDecrypt(toBigintArray(data), keyArr)) -} - -// console.log(14895149309145760986n - ) -// console.log(toLong('14895149309145760986')) -// console.log(mrcDecrypt(str)) -// console.log(mrcDecrypt(str)) -// console.log(toByteArray([6048138644744000495n])) -// console.log(toByteArray([16325999628386395n])) -// console.log(toLong(90994076459972177136n)) +import { mrcDecrypt } from './utils/mrc' const mrcTools = { rxps: { diff --git a/src/renderer/utils/musicSdk/mg/musicInfo.js b/src/renderer/utils/musicSdk/mg/musicInfo.js index abad6e33..01109c16 100644 --- a/src/renderer/utils/musicSdk/mg/musicInfo.js +++ b/src/renderer/utils/musicSdk/mg/musicInfo.js @@ -1,5 +1,6 @@ -import { sizeFormate, getSingerName } from '../../index' -import { createHttpFetch } from './util' +import { sizeFormate } from '../../index' +import { createHttpFetch } from './utils' +import { formatSingerName } from '../utils' const createGetMusicInfosTask = (ids, resType = 2) => { let list = ids @@ -64,7 +65,7 @@ export const filterMusicInfoList = (rawList) => { const intervalTest = /(\d\d:\d\d)$/.test(item.length) list.push({ - singer: getSingerName(item.artists, 'name'), + singer: formatSingerName(item.artists, 'name'), name: item.songName, albumName: item.album, albumId: item.albumId, diff --git a/src/renderer/utils/musicSdk/mg/musicSearch.js b/src/renderer/utils/musicSdk/mg/musicSearch.js index c4f4d9a0..635f6b56 100644 --- a/src/renderer/utils/musicSdk/mg/musicSearch.js +++ b/src/renderer/utils/musicSdk/mg/musicSearch.js @@ -1,6 +1,6 @@ -import { sizeFormate, formatPlayTime, getSingerName } from '../../index' -import { toMD5 } from '../utils' -import { createHttpFetch } from './util' +import { sizeFormate, formatPlayTime } from '../../index' +import { createHttpFetch } from './utils' +import { formatSingerName, toMD5 } from '../utils' const searchSign = (timeStr, str, deviceId) => { const key = '6cdc72a439cef99a3418d2a78aa28c73' @@ -76,7 +76,7 @@ export default { if (img && !/https?:/.test(item.img3)) img = 'http://d.musicapp.migu.cn' + img list.push({ - singer: getSingerName(item.singerList, 'name'), + singer: formatSingerName(item.singerList, 'name'), name: item.name, albumName: item.album, albumId: item.albumId, diff --git a/src/renderer/utils/musicSdk/mg/tipSearch.js b/src/renderer/utils/musicSdk/mg/tipSearch.js index 41486d8d..fcd4951b 100644 --- a/src/renderer/utils/musicSdk/mg/tipSearch.js +++ b/src/renderer/utils/musicSdk/mg/tipSearch.js @@ -1,4 +1,4 @@ -import { createHttpFetch } from './util' +import { createHttpFetch } from './utils' export default { requestObj: null, diff --git a/src/renderer/utils/musicSdk/mg/util.js b/src/renderer/utils/musicSdk/mg/utils/index.js similarity index 94% rename from src/renderer/utils/musicSdk/mg/util.js rename to src/renderer/utils/musicSdk/mg/utils/index.js index efcf7548..503a85f6 100644 --- a/src/renderer/utils/musicSdk/mg/util.js +++ b/src/renderer/utils/musicSdk/mg/utils/index.js @@ -1,4 +1,4 @@ -import { httpFetch } from '../../request' +import { httpFetch } from '../../../request' /** * 创建一个适用于MG的Http请求 diff --git a/src/renderer/utils/musicSdk/mg/utils/mrc.js b/src/renderer/utils/musicSdk/mg/utils/mrc.js new file mode 100644 index 00000000..e969b809 --- /dev/null +++ b/src/renderer/utils/musicSdk/mg/utils/mrc.js @@ -0,0 +1,101 @@ +// const key = 'karakal@123Qcomyidongtiantianhaoting' +const DELTA = 2654435769n +const MIN_LENGTH = 32 +// const SPECIAL_CHAR = '0' +const keyArr = [ + 27303562373562475n, + 18014862372307051n, + 22799692160172081n, + 34058940340699235n, + 30962724186095721n, + 27303523720101991n, + 27303523720101998n, + 31244139033526382n, + 28992395054481524n, +] + +const teaDecrypt = (data, key) => { + const length = data.length + const lengthBitint = BigInt(length) + if (length >= 1) { + // let j = data[data.length - 1]; + let j2 = data[0] + let j3 = toLong((6n + (52n / lengthBitint)) * DELTA) + while (true) { + let j4 = j3 + if (j4 == 0n) break + let j5 = toLong(3n & toLong(j4 >> 2n)) + let j6 = lengthBitint + while (true) { + j6-- + if (j6 > 0n) { + let j7 = data[(j6 - 1n)] + let i = j6 + j2 = toLong(data[i] - (toLong(toLong(j2 ^ j4) + toLong(j7 ^ key[toLong(toLong(3n & j6) ^ j5)])) ^ toLong(toLong(toLong(j7 >> 5n) ^ toLong(j2 << 2n)) + toLong(toLong(j2 >> 3n) ^ toLong(j7 << 4n))))) + data[i] = j2 + } else break + } + let j8 = data[lengthBitint - 1n] + j2 = toLong(data[0n] - toLong(toLong(toLong(key[toLong(toLong(j6 & 3n) ^ j5)] ^ j8) + toLong(j2 ^ j4)) ^ toLong(toLong(toLong(j8 >> 5n) ^ toLong(j2 << 2n)) + toLong(toLong(j2 >> 3n) ^ toLong(j8 << 4n))))) + data[0] = j2 + j3 = toLong(j4 - DELTA) + } + } + return data +} + +const longArrToString = (data) => { + const arrayList = [] + for (const j of data) arrayList.push(longToBytes(j).toString('utf16le')) + return arrayList.join('') +} + +// https://stackoverflow.com/a/29132118 +const longToBytes = (l) => { + const result = Buffer.alloc(8) + for (let i = 0; i < 8; i++) { + result[i] = parseInt(l & 0xFFn) + l >>= 8n + } + return result +} + + +const toBigintArray = (data) => { + const length = Math.floor(data.length / 16) + const jArr = Array(length) + for (let i = 0; i < length; i++) { + jArr[i] = toLong(data.substring(i * 16, (i * 16) + 16)) + } + return jArr +} + +// https://github.com/lyswhut/lx-music-desktop/issues/445#issuecomment-1139338682 +const MAX = 9223372036854775807n +const MIN = -9223372036854775808n +const toLong = str => { + const num = typeof str == 'string' ? BigInt('0x' + str) : str + if (num > MAX) return toLong(num - (1n << 64n)) + else if (num < MIN) return toLong(num + (1n << 64n)) + return num +} + +export const mrcDecrypt = (data) => { + // console.log(data.length) + // -3551594764563790630 + // console.log(toLongArrayFromArr(Buffer.from(key))) + // console.log(teaDecrypt(toBigintArray(data), keyArr)) + // console.log(longArrToString(teaDecrypt(toBigintArray(data), keyArr))) + // console.log(toByteArray(teaDecrypt(toBigintArray(data), keyArr))) + return (data == null || data.length < MIN_LENGTH) + ? data + : longArrToString(teaDecrypt(toBigintArray(data), keyArr)) +} + +// console.log(14895149309145760986n - ) +// console.log(toLong('14895149309145760986')) +// console.log(mrcDecrypt(str)) +// console.log(mrcDecrypt(str)) +// console.log(toByteArray([6048138644744000495n])) +// console.log(toByteArray([16325999628386395n])) +// console.log(toLong(90994076459972177136n)) diff --git a/src/renderer/utils/musicSdk/tx/leaderboard.js b/src/renderer/utils/musicSdk/tx/leaderboard.js index a904a812..09f51746 100644 --- a/src/renderer/utils/musicSdk/tx/leaderboard.js +++ b/src/renderer/utils/musicSdk/tx/leaderboard.js @@ -1,5 +1,6 @@ import { httpFetch } from '../../request' -import { formatPlayTime, sizeFormate, getSingerName } from '../../index' +import { formatPlayTime, sizeFormate } from '../../index' +import { formatSingerName } from '../utils' 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' }] @@ -139,7 +140,7 @@ export default { } // types.reverse() return { - singer: getSingerName(item.singer, 'name'), + singer: formatSingerName(item.singer, 'name'), name: item.name, albumName: item.album.name, albumId: item.album.mid, diff --git a/src/renderer/utils/musicSdk/tx/musicInfo.js b/src/renderer/utils/musicSdk/tx/musicInfo.js index 0ca6e4e7..165f4d5c 100644 --- a/src/renderer/utils/musicSdk/tx/musicInfo.js +++ b/src/renderer/utils/musicSdk/tx/musicInfo.js @@ -1,5 +1,6 @@ import { httpFetch } from '../../request' -import { formatPlayTime, sizeFormate, getSingerName } from '../../index' +import { formatPlayTime, sizeFormate } from '../../index' +import { formatSingerName } from '../utils' export default (songmid) => { const requestObj = httpFetch('https://u.y.qq.com/cgi-bin/musicu.fcg', { @@ -68,7 +69,7 @@ export default (songmid) => { albumId = item.album.mid } return { - singer: getSingerName(item.singer, 'name'), + singer: formatSingerName(item.singer, 'name'), name: item.name, albumName, albumId, diff --git a/src/renderer/utils/musicSdk/tx/musicSearch.js b/src/renderer/utils/musicSdk/tx/musicSearch.js index 507896c6..2e011eca 100644 --- a/src/renderer/utils/musicSdk/tx/musicSearch.js +++ b/src/renderer/utils/musicSdk/tx/musicSearch.js @@ -1,7 +1,6 @@ import { httpFetch } from '../../request' -import { formatPlayTime, sizeFormate, getSingerName } from '../../index' -// import { debug } from '../../utils/env' -// import { formatSinger } from './util' +import { formatPlayTime, sizeFormate } from '../../index' +import { formatSingerName } from '../utils' export default { limit: 50, @@ -95,7 +94,7 @@ export default { albumId = item.album.mid } list.push({ - singer: getSingerName(item.singer, 'name'), + singer: formatSingerName(item.singer, 'name'), name: item.name, albumName, albumId, diff --git a/src/renderer/utils/musicSdk/tx/songList.js b/src/renderer/utils/musicSdk/tx/songList.js index 876c29a9..0f539514 100644 --- a/src/renderer/utils/musicSdk/tx/songList.js +++ b/src/renderer/utils/musicSdk/tx/songList.js @@ -1,5 +1,6 @@ import { httpFetch } from '../../request' -import { decodeName, formatPlayTime, sizeFormate, dateFormat, getSingerName } from '../../index' +import { decodeName, formatPlayTime, sizeFormate, dateFormat } from '../../index' +import { formatSingerName } from '../utils' export default { _requestObj_tags: null, @@ -267,7 +268,7 @@ export default { } // types.reverse() return { - singer: getSingerName(item.singer, 'name'), + singer: formatSingerName(item.singer, 'name'), name: item.name, albumName: item.album.name, albumId: item.album.mid, diff --git a/src/renderer/utils/musicSdk/utils.js b/src/renderer/utils/musicSdk/utils.js index 42e82232..41121a10 100644 --- a/src/renderer/utils/musicSdk/utils.js +++ b/src/renderer/utils/musicSdk/utils.js @@ -1,9 +1,9 @@ import crypto from 'crypto' import dns from 'dns' +import { decodeName } from '@common/utils/common' export const toMD5 = str => crypto.createHash('md5').update(str).digest('hex') - const ipMap = new Map() export const getHostIp = hostname => { const result = ipMap.get(hostname) @@ -27,3 +27,20 @@ export const dnsLookup = (hostname, options, callback) => { dns.lookup(hostname, options, callback) } + +/** + * 格式化歌手 + * @param singers 歌手数组 + * @param obj 读取的数据 + * @param join 插入的字符 + */ +export const formatSingerName = (singers, obj = 'name', join = '、') => { + if (typeof singers === 'string') return decodeName(singers) + const singer = [] + singers.forEach(item => { + let name = item[obj] + if (!name) return + singer.push(name) + }) + return decodeName(singer.join(join)) +} diff --git a/src/renderer/utils/musicSdk/wy/musicDetail.js b/src/renderer/utils/musicSdk/wy/musicDetail.js index 1b0130ac..7f1380e2 100644 --- a/src/renderer/utils/musicSdk/wy/musicDetail.js +++ b/src/renderer/utils/musicSdk/wy/musicDetail.js @@ -1,6 +1,7 @@ import { httpFetch } from '../../request' import { weapi } from './utils/crypto' -import { formatPlayTime, sizeFormate, getSingerName } from '../../index' +import { formatPlayTime, sizeFormate } from '../../index' +import { formatSingerName } from '../utils' // https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/module/song_detail.js export default { @@ -64,7 +65,7 @@ export default { }) } else { list.push({ - singer: getSingerName(item.ar, 'name'), + singer: formatSingerName(item.ar, 'name'), name: item.name ?? '', albumName: item.al?.name, albumId: item.al?.id, diff --git a/src/renderer/utils/musicSdk/wy/musicSearch.js b/src/renderer/utils/musicSdk/wy/musicSearch.js index 86460ada..3cb15ee5 100644 --- a/src/renderer/utils/musicSdk/wy/musicSearch.js +++ b/src/renderer/utils/musicSdk/wy/musicSearch.js @@ -1,8 +1,9 @@ // import { httpFetch } from '../../request' // import { weapi } from './utils/crypto' -import { sizeFormate, formatPlayTime, getSingerName } from '../../index' // import musicDetailApi from './musicDetail' +import { sizeFormate, formatPlayTime } from '../../index' import { eapiRequest } from './utils/index' +import { formatSingerName } from '../utils' export default { limit: 30, @@ -59,7 +60,7 @@ export default { types.reverse() return { - singer: getSingerName(item.ar, 'name'), + singer: formatSingerName(item.ar, 'name'), name: item.name, albumName: item.al.name, albumId: item.al.id, diff --git a/src/renderer/utils/musicSdk/wy/songList.js b/src/renderer/utils/musicSdk/wy/songList.js index c15e77b3..141f32a0 100644 --- a/src/renderer/utils/musicSdk/wy/songList.js +++ b/src/renderer/utils/musicSdk/wy/songList.js @@ -5,9 +5,10 @@ import { weapi, linuxapi } from './utils/crypto' import { httpFetch } from '../../request' -import { formatPlayTime, sizeFormate, dateFormat, getSingerName } from '../../index' +import { formatPlayTime, sizeFormate, dateFormat } from '../../index' import musicDetailApi from './musicDetail' import { eapiRequest } from './utils/index' +import { formatSingerName } from '../utils' export default { _requestObj_tags: null, @@ -191,7 +192,7 @@ export default { }) } else { list.push({ - singer: getSingerName(item.ar, 'name'), + singer: formatSingerName(item.ar, 'name'), name: item.name ?? '', albumName: item.al?.name, albumId: item.al?.id, @@ -225,7 +226,7 @@ export default { }), }) return this._requestObj_list.promise.then(({ body }) => { - console.log(body) + // console.log(body) if (body.code !== this.successCode) return this.getList(sortId, tagId, page, ++tryNum) return { list: this.filterList(body.playlists), diff --git a/src/renderer/utils/musicSdk/wy/tipSearch.js b/src/renderer/utils/musicSdk/wy/tipSearch.js index 1c1c9050..34afa1d7 100644 --- a/src/renderer/utils/musicSdk/wy/tipSearch.js +++ b/src/renderer/utils/musicSdk/wy/tipSearch.js @@ -1,6 +1,6 @@ import { httpFetch } from '../../request' import { weapi } from './utils/crypto' -import { getSingerName } from '../../index' +import { formatSingerName } from '../utils' export default { requestObj: null, @@ -25,7 +25,7 @@ export default { }) }, handleResult(rawData) { - return rawData.map(info => `${info.name} - ${getSingerName(info.artists, 'name')}`) + return rawData.map(info => `${info.name} - ${formatSingerName(info.artists, 'name')}`) }, async search(str) { return this.tipSearchBySong(str).then(result => this.handleResult(result))