From 9920e5ef990328f3156f22a64d29963aeb8832fc Mon Sep 17 00:00:00 2001 From: lyswhut Date: Fri, 18 Nov 2022 09:58:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AF=BC=E5=85=A5=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=95=B0=E6=8D=AE=E6=97=B6=E7=9A=84=E6=AD=8C=E6=9B=B2?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E8=BD=AC=E6=8D=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/utils/tools.ts | 106 +++++++++++++---------- src/renderer/core/music/utils.ts | 2 +- src/renderer/store/leaderboard/action.ts | 4 +- src/renderer/store/songList/action.ts | 4 +- 4 files changed, 66 insertions(+), 50 deletions(-) diff --git a/src/common/utils/tools.ts b/src/common/utils/tools.ts index 29b41c4a..2c642b63 100644 --- a/src/common/utils/tools.ts +++ b/src/common/utils/tools.ts @@ -1,39 +1,46 @@ // 业务工具方法 -export const toNewMusicInfo = (oldMusicInfo: any): LX.Music.MusicInfoOnline => { +export const toNewMusicInfo = (oldMusicInfo: any): LX.Music.MusicInfo => { const meta: Record = { songId: oldMusicInfo.songmid, // 歌曲ID,mg源为copyrightId,local为文件路径 albumName: oldMusicInfo.albumName, // 歌曲专辑名称 - albumId: oldMusicInfo.albumId, picUrl: oldMusicInfo.img, // 歌曲图片链接 - qualitys: oldMusicInfo.types, - _qualitys: oldMusicInfo._types, - } - if (meta._qualitys.flac32bit && !meta._qualitys.flac24bit) { - meta._qualitys.flac24bit = meta._qualitys.flac32bit - delete meta._qualitys.flac32bit - - meta.qualitys = (meta.qualitys as any[]).map(quality => { - if (quality.type == 'flac32bit') quality.type = 'flac24bit' - return quality - }) } - switch (oldMusicInfo.source) { - case 'kg': - meta.hash = oldMusicInfo.hash - break - case 'tx': - meta.strMediaMid = oldMusicInfo.strMediaMid - meta.albumMid = oldMusicInfo.albumMid - break - case 'mg': - meta.copyrightId = oldMusicInfo.copyrightId - meta.lrcUrl = oldMusicInfo.lrcUrl - meta.mrcUrl = oldMusicInfo.mrcUrl - meta.trcUrl = oldMusicInfo.trcUrl - break + if (oldMusicInfo.source == 'local') { + meta.filePath = oldMusicInfo.filePath ?? oldMusicInfo.songmid ?? '' + meta.ext = oldMusicInfo.ext ?? /\.(\w+)$/.exec(meta.filePath)?.[1] ?? '' + } else { + meta.qualitys = oldMusicInfo.types + meta._qualitys = oldMusicInfo._types + meta.albumId = oldMusicInfo.albumId + if (meta._qualitys.flac32bit && !meta._qualitys.flac24bit) { + meta._qualitys.flac24bit = meta._qualitys.flac32bit + delete meta._qualitys.flac32bit + + meta.qualitys = (meta.qualitys as any[]).map(quality => { + if (quality.type == 'flac32bit') quality.type = 'flac24bit' + return quality + }) + } + + switch (oldMusicInfo.source) { + case 'kg': + meta.hash = oldMusicInfo.hash + break + case 'tx': + meta.strMediaMid = oldMusicInfo.strMediaMid + meta.albumMid = oldMusicInfo.albumMid + break + case 'mg': + meta.copyrightId = oldMusicInfo.copyrightId + meta.lrcUrl = oldMusicInfo.lrcUrl + meta.mrcUrl = oldMusicInfo.mrcUrl + meta.trcUrl = oldMusicInfo.trcUrl + break + } } + return { id: `${oldMusicInfo.source as string}_${oldMusicInfo.songmid as string}`, name: oldMusicInfo.name, @@ -44,34 +51,43 @@ export const toNewMusicInfo = (oldMusicInfo: any): LX.Music.MusicInfoOnline => { } } -export const toOldMusicInfo = (minfo: LX.Music.MusicInfoOnline) => { +export const toOldMusicInfo = (minfo: LX.Music.MusicInfo) => { const oInfo: Record = { name: minfo.name, singer: minfo.singer, source: minfo.source, songmid: minfo.meta.songId, - albumId: minfo.meta.albumId ?? '', interval: minfo.interval, albumName: minfo.meta.albumName, img: minfo.meta.picUrl ?? '', - types: minfo.meta.qualitys ?? [], - _types: minfo.meta._qualitys ?? {}, typeUrl: {}, } - switch (minfo.source) { - case 'kg': - oInfo.hash = minfo.meta.hash - break - case 'tx': - oInfo.strMediaMid = minfo.meta.strMediaMid - oInfo.albumMid = minfo.meta.albumMid - break - case 'mg': - oInfo.copyrightId = minfo.meta.copyrightId - oInfo.lrcUrl = minfo.meta.lrcUrl - oInfo.mrcUrl = minfo.meta.mrcUrl - oInfo.trcUrl = minfo.meta.trcUrl - break + if (minfo.source == 'local') { + oInfo.filePath = minfo.meta.filePath + oInfo.ext = minfo.meta.ext + oInfo.albumId = '' + oInfo.types = [] + oInfo._types = {} + } else { + oInfo.albumId = minfo.meta.albumId + oInfo.types = minfo.meta.qualitys + oInfo._types = minfo.meta._qualitys + + switch (minfo.source) { + case 'kg': + oInfo.hash = minfo.meta.hash + break + case 'tx': + oInfo.strMediaMid = minfo.meta.strMediaMid + oInfo.albumMid = minfo.meta.albumMid + break + case 'mg': + oInfo.copyrightId = minfo.meta.copyrightId + oInfo.lrcUrl = minfo.meta.lrcUrl + oInfo.mrcUrl = minfo.meta.mrcUrl + oInfo.trcUrl = minfo.meta.trcUrl + break + } } return oInfo diff --git a/src/renderer/core/music/utils.ts b/src/renderer/core/music/utils.ts index 3a632676..31e92b4f 100644 --- a/src/renderer/core/music/utils.ts +++ b/src/renderer/core/music/utils.ts @@ -49,7 +49,7 @@ export const getOtherSource = async(musicInfo: LX.Music.MusicInfo | LX.Download. if (getOtherSourcePromises.has(key)) return getOtherSourcePromises.get(key) const promise = musicSdk.findMusic(searchMusicInfo).then((otherSource) => { - const sources: LX.Music.MusicInfoOnline[] = otherSource.map(toNewMusicInfo) + const sources: LX.Music.MusicInfoOnline[] = otherSource.map(toNewMusicInfo) as LX.Music.MusicInfoOnline[] if (sources.length) void saveOtherSourceFromStore(musicInfo.id, sources) return sources }).finally(() => { diff --git a/src/renderer/store/leaderboard/action.ts b/src/renderer/store/leaderboard/action.ts index fb359fd7..a91623b5 100644 --- a/src/renderer/store/leaderboard/action.ts +++ b/src/renderer/store/leaderboard/action.ts @@ -53,7 +53,7 @@ export const getListDetail = async(id: string, page: number, isRefresh = false): const [source, bangId] = id.split('__') as [LX.OnlineSource, string] return musicSdk[source]?.leaderboard?.getList(bangId, page).then((result: ListDetailInfo) => { - result.list = markRawList(deduplicationList(result.list.map(m => toNewMusicInfo(m)))) + result.list = markRawList(deduplicationList(result.list.map(m => toNewMusicInfo(m)) as LX.Music.MusicInfoOnline[])) cache.set(key, result) return result }) @@ -75,7 +75,7 @@ export const getListDetailAll = async(id: string, isRefresh = false): Promise { - result.list = markRawList(deduplicationList(result.list.map(m => toNewMusicInfo(m)))) + result.list = markRawList(deduplicationList(result.list.map(m => toNewMusicInfo(m)) as LX.Music.MusicInfoOnline[])) cache.set(key, result) return result }) ?? Promise.reject(new Error('source not found' + source)) diff --git a/src/renderer/store/songList/action.ts b/src/renderer/store/songList/action.ts index 88800621..53184bc2 100644 --- a/src/renderer/store/songList/action.ts +++ b/src/renderer/store/songList/action.ts @@ -129,7 +129,7 @@ export const getListDetail = async(id: string, source: LX.OnlineSource, page: nu if (!isRefresh && cache.has(key)) return cache.get(key) return musicSdk[source]?.songList.getListDetail(id, page).then((result: ListDetailInfo) => { - result.list = markRawList(deduplicationList(result.list.map(m => toNewMusicInfo(m)))) + result.list = markRawList(deduplicationList(result.list.map(m => toNewMusicInfo(m)) as LX.Music.MusicInfoOnline[])) cache.set(key, result) return result }) @@ -151,7 +151,7 @@ export const getListDetailAll = async(id: string, source: LX.OnlineSource, isRef return cache.has(key) ? Promise.resolve(cache.get(key)) : musicSdk[source]?.songList.getListDetail(id, page).then((result: ListDetailInfo) => { - result.list = markRawList(deduplicationList(result.list.map(m => toNewMusicInfo(m)))) + result.list = markRawList(deduplicationList(result.list.map(m => toNewMusicInfo(m)) as LX.Music.MusicInfoOnline[])) cache.set(key, result) return result }) ?? Promise.reject(new Error('source not found' + source))