修复导入列表数据时的歌曲信息转换问题
parent
f3852b20ca
commit
9920e5ef99
|
@ -1,39 +1,46 @@
|
|||
// 业务工具方法
|
||||
|
||||
export const toNewMusicInfo = (oldMusicInfo: any): LX.Music.MusicInfoOnline => {
|
||||
export const toNewMusicInfo = (oldMusicInfo: any): LX.Music.MusicInfo => {
|
||||
const meta: Record<string, any> = {
|
||||
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<string, any> = {
|
||||
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
|
||||
|
|
|
@ -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(() => {
|
||||
|
|
|
@ -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<LX
|
|||
if (!isRefresh && cache.has(key)) return cache.get(key)
|
||||
|
||||
return musicSdk[source]?.leaderboard.getList(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))
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue