diff --git a/src/renderer/utils/musicSdk/kg/singer.js b/src/renderer/utils/musicSdk/kg/singer.js index b1398336..d0ec7c29 100644 --- a/src/renderer/utils/musicSdk/kg/singer.js +++ b/src/renderer/utils/musicSdk/kg/singer.js @@ -15,15 +15,15 @@ export default { source: 'kg', id: body.singerid, info: { - name: body.singername, - desc: body.intro, - avatar: body.imgurl.replace('{size}', 480), - gender: body.grade === 1 ? 'man' : 'woman', + name: body.singername, + desc: body.intro, + avatar: body.imgurl.replace('{size}', 480), + gender: body.grade === 1 ? 'man' : 'woman', }, count: { - music: body.songcount, - album: body.albumcount, - } + music: body.songcount, + album: body.albumcount, + }, } }) }, @@ -83,4 +83,3 @@ export default { }) }, } - diff --git a/src/renderer/utils/musicSdk/tx/lyric.js b/src/renderer/utils/musicSdk/tx/lyric.js index 924c54fe..6e1ac45c 100644 --- a/src/renderer/utils/musicSdk/tx/lyric.js +++ b/src/renderer/utils/musicSdk/tx/lyric.js @@ -1,5 +1,5 @@ import { httpFetch } from '../../request' -import { getMusicInfo } from './musicInfo' +import getMusicInfo from './musicInfo' import { rendererInvoke } from '@common/rendererIpc' import { WIN_MAIN_RENDERER_EVENT_NAME } from '@common/ipcNames' diff --git a/src/renderer/utils/musicSdk/tx/musicInfo.js b/src/renderer/utils/musicSdk/tx/musicInfo.js index 4101d62f..ce8c52fb 100644 --- a/src/renderer/utils/musicSdk/tx/musicInfo.js +++ b/src/renderer/utils/musicSdk/tx/musicInfo.js @@ -1,9 +1,20 @@ -import { filterMusicInfoItem } from './util' import { httpFetch } from '../../request' +import { formatPlayTime, sizeFormate } from '../../index' -export const getMusicInfo = id => { - return httpFetch('https://u.y.qq.com/cgi-bin/musicu.fcg', { - method: 'POST', +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', @@ -15,19 +26,73 @@ export const getMusicInfo = id => { method: 'get_song_detail_yqq', param: { song_type: 0, - song_mid: id, + song_mid: songmid, }, }, }, - headers: { - 'User-Angent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)', - }, - }).then(({ body }) => { - if (body.req.code != 0) throw new Error('get music info faild.') - + }) + 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 - return filterMusicInfoItem(item) + 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.name + albumId = item.album.mid + } + return { + singer: getSinger(item.singer), + name: item.name, + 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 === '空') + ? item.singer?.length ? `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: {}, + } }) } + diff --git a/src/renderer/utils/musicSdk/tx/musicSearch.js b/src/renderer/utils/musicSdk/tx/musicSearch.js index 1f4a5952..2e011eca 100644 --- a/src/renderer/utils/musicSdk/tx/musicSearch.js +++ b/src/renderer/utils/musicSdk/tx/musicSearch.js @@ -1,5 +1,6 @@ import { httpFetch } from '../../request' -import { filterMusicInfoItem } from './util' +import { formatPlayTime, sizeFormate } from '../../index' +import { formatSingerName } from '../utils' export default { limit: 50, @@ -49,11 +50,69 @@ export default { }) }, handleResult(rawList) { + // console.log(rawList) const list = [] rawList.forEach(item => { if (!item.file?.media_mid) return - list.push(filterMusicInfoItem(item)) + + 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.name + albumId = item.album.mid + } + list.push({ + singer: formatSingerName(item.singer, 'name'), + name: item.name, + 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 === '空') + ? item.singer?.length ? `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: {}, + }) }) + // console.log(list) return list }, search(str, page = 1, limit) { diff --git a/src/renderer/utils/musicSdk/tx/singer.js b/src/renderer/utils/musicSdk/tx/singer.js index aad93e1d..3e66a4d1 100644 --- a/src/renderer/utils/musicSdk/tx/singer.js +++ b/src/renderer/utils/musicSdk/tx/singer.js @@ -1,6 +1,64 @@ -import { createMusicuFetch, filterMusicInfoItem } from './util' import { httpFetch } from '../../request' +import { formatPlayTime, sizeFormate } from '../../index' +import { formatSingerName } from '../utils' + +export const filterMusicInfoItem = item => { + const types = [] + const _types = {} + if (item.file.size_128mp3 != 0) { + let size = sizeFormate(item.file.size_128mp3) + types.push({ type: '128k', size }) + _types['128k'] = { + size, + } + } + if (item.file.size_320mp3 !== 0) { + let size = sizeFormate(item.file.size_320mp3) + types.push({ type: '320k', size }) + _types['320k'] = { + size, + } + } + if (item.file.size_flac !== 0) { + let size = sizeFormate(item.file.size_flac) + types.push({ type: 'flac', size }) + _types.flac = { + size, + } + } + if (item.file.size_hires !== 0) { + let size = sizeFormate(item.file.size_hires) + types.push({ type: 'flac24bit', size }) + _types.flac24bit = { + size, + } + } + + const albumId = item.album.id ?? '' + const albumMid = item.album.mid ?? '' + const albumName = item.album.name ?? '' + return { + source: 'tx', + singer: formatSingerName(item.singer, 'name'), + name: item.name, + albumName, + albumId, + albumMid, + interval: formatPlayTime(item.interval), + songId: item.id, + songmid: item.mid, + strMediaMid: item.file.media_mid, + img: (albumId === '' || albumId === '空') + ? item.singer?.length ? `https://y.gtimg.cn/music/photo_new/T001R500x500M000${item.singer[0].mid}.jpg` : '' + : `https://y.gtimg.cn/music/photo_new/T002R500x500M000${albumMid}.jpg`, + types, + _types, + typeUrl: {}, + } +} + + /** * 创建一个适用于TX的Http请求 * @param {*} url @@ -186,6 +244,6 @@ export default { raw.map(item => { return filterMusicInfoItem(item.songInfo) }) - } + }, } diff --git a/src/renderer/utils/musicSdk/tx/util.js b/src/renderer/utils/musicSdk/tx/util.js deleted file mode 100644 index bf12a393..00000000 --- a/src/renderer/utils/musicSdk/tx/util.js +++ /dev/null @@ -1,57 +0,0 @@ -import { formatPlayTime, sizeFormate } from '../../index' -import { formatSingerName } from '../utils' - -export const filterMusicInfoItem = item => { - const types = [] - const _types = {} - if (item.file.size_128mp3 != 0) { - let size = sizeFormate(item.file.size_128mp3) - types.push({ type: '128k', size }) - _types['128k'] = { - size, - } - } - if (item.file.size_320mp3 !== 0) { - let size = sizeFormate(item.file.size_320mp3) - types.push({ type: '320k', size }) - _types['320k'] = { - size, - } - } - if (item.file.size_flac !== 0) { - let size = sizeFormate(item.file.size_flac) - types.push({ type: 'flac', size }) - _types.flac = { - size, - } - } - if (item.file.size_hires !== 0) { - let size = sizeFormate(item.file.size_hires) - types.push({ type: 'flac24bit', size }) - _types.flac24bit = { - size, - } - } - - const albumId = item.album.id ?? '' - const albumMid = item.album.mid ?? '' - const albumName = item.album.name ?? '' - return { - source: 'tx', - singer: formatSingerName(item.singer, 'name'), - name: item.name, - albumName, - albumId, - albumMid, - interval: formatPlayTime(item.interval), - songId: item.id, - songmid: item.mid, - strMediaMid: item.file.media_mid, - img: (albumId === '' || albumId === '空') - ? item.singer?.length ? `https://y.gtimg.cn/music/photo_new/T001R500x500M000${item.singer[0].mid}.jpg` : '' - : `https://y.gtimg.cn/music/photo_new/T002R500x500M000${albumMid}.jpg`, - types, - _types, - typeUrl: {}, - } -} diff --git a/src/renderer/utils/musicSdk/wy/singer.js b/src/renderer/utils/musicSdk/wy/singer.js index d853b3eb..fc7f5949 100644 --- a/src/renderer/utils/musicSdk/wy/singer.js +++ b/src/renderer/utils/musicSdk/wy/singer.js @@ -99,6 +99,7 @@ export default { const types = [] const _types = {} + let size item.privilege.chargeInfoList.forEach(i => { switch (i.rate) { case 128000: @@ -116,7 +117,7 @@ export default { case 999000: size = item.sqMusic ? sizeFormate(item.sqMusic.size) : null types.push({ type: 'flac', size }) - _typesflac = { + _types.flac = { size, } case 1999000: