mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-07-03 04:32:10 +08:00
改进本地音乐在线信息的匹配机制
This commit is contained in:
parent
330237fbe7
commit
f1d8c9509d
@ -15,6 +15,7 @@
|
||||
- 文件选择器允许选择外置存储设备上的路径(/storage)
|
||||
- 图片显示改用第三方的图片组件,支持gif类型的图片显示,尝试解决某些设备上图片过多导致的应用崩溃问题
|
||||
- 歌曲评论内容过长时自动折叠,需手动展开
|
||||
- 改进本地音乐在线信息的匹配机制
|
||||
|
||||
### 修复
|
||||
|
||||
|
@ -12,6 +12,55 @@ import {
|
||||
import { getLocalFilePath } from '@/utils/music'
|
||||
import { readLyric, readPic } from '@/utils/localMediaMetadata'
|
||||
|
||||
const getOtherSourceByLocal = async(musicInfo: LX.Music.MusicInfoLocal) => {
|
||||
let result: LX.Music.MusicInfoOnline[] = []
|
||||
result = await getOtherSource(musicInfo)
|
||||
if (result.length) return result
|
||||
if (musicInfo.name.includes('-')) {
|
||||
const [name, singer] = musicInfo.name.split('-').map(val => val.trim())
|
||||
result = await getOtherSource({
|
||||
...musicInfo,
|
||||
name,
|
||||
singer,
|
||||
})
|
||||
if (result.length) return result
|
||||
result = await getOtherSource({
|
||||
...musicInfo,
|
||||
name: singer,
|
||||
singer: name,
|
||||
})
|
||||
if (result.length) return result
|
||||
}
|
||||
let fileName = musicInfo.meta.filePath.split('/').at(-1)
|
||||
if (fileName) {
|
||||
fileName = fileName.substring(0, fileName.lastIndexOf('.'))
|
||||
if (fileName != musicInfo.name) {
|
||||
if (fileName.includes('-')) {
|
||||
const [name, singer] = fileName.split('-').map(val => val.trim())
|
||||
result = await getOtherSource({
|
||||
...musicInfo,
|
||||
name,
|
||||
singer,
|
||||
})
|
||||
if (result.length) return result
|
||||
result = await getOtherSource({
|
||||
...musicInfo,
|
||||
name: singer,
|
||||
singer: name,
|
||||
})
|
||||
} else {
|
||||
result = await getOtherSource({
|
||||
...musicInfo,
|
||||
name: fileName,
|
||||
singer: '',
|
||||
})
|
||||
}
|
||||
if (result.length) return result
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () => {} }: {
|
||||
musicInfo: LX.Music.MusicInfoLocal
|
||||
@ -24,7 +73,7 @@ export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () =>
|
||||
if (path) return path
|
||||
}
|
||||
onToggleSource()
|
||||
const otherSource = await getOtherSource(musicInfo)
|
||||
const otherSource = await getOtherSourceByLocal(musicInfo)
|
||||
if (!otherSource.length) throw new Error('source not found')
|
||||
return getOnlineOtherSourceMusicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, quality: targetQuality, musicInfo: targetMusicInfo, isFromCache }) => {
|
||||
// saveLyric(musicInfo, data.lyricInfo)
|
||||
@ -49,7 +98,7 @@ export const getPicUrl = async({ musicInfo, listId, isRefresh, onToggleSource =
|
||||
}
|
||||
|
||||
onToggleSource()
|
||||
const otherSource = await getOtherSource(musicInfo)
|
||||
const otherSource = await getOtherSourceByLocal(musicInfo)
|
||||
if (!otherSource.length) throw new Error('source not found')
|
||||
return getOnlineOtherSourcePicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, musicInfo: targetMusicInfo, isFromCache }) => {
|
||||
if (listId) {
|
||||
@ -86,7 +135,7 @@ export const getLyricInfo = async({ musicInfo, isRefresh, onToggleSource = () =>
|
||||
}
|
||||
|
||||
onToggleSource()
|
||||
const otherSource = await getOtherSource(musicInfo)
|
||||
const otherSource = await getOtherSourceByLocal(musicInfo)
|
||||
if (!otherSource.length) throw new Error('source not found')
|
||||
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
||||
return getOnlineOtherSourceLyricInfo({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ lyricInfo, musicInfo: targetMusicInfo, isFromCache }) => {
|
||||
|
@ -116,6 +116,9 @@ export const findMusic = async(musicInfo) => {
|
||||
) {
|
||||
return item
|
||||
}
|
||||
if (!singer) {
|
||||
if (item.lowerCaseName == lowerCaseName && (interval ? item.interval == interval : true)) return item
|
||||
}
|
||||
}
|
||||
return null
|
||||
}).catch(_ => null))
|
||||
|
Loading…
x
Reference in New Issue
Block a user