mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-05-23 22:37:41 +08:00
优化本地歌曲换源匹配机制
This commit is contained in:
parent
e047590706
commit
3a048eeda2
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
- 不再丢弃kg源逐行歌词(@helloplhm-qwq)
|
- 不再丢弃kg源逐行歌词(@helloplhm-qwq)
|
||||||
- 支持kw源排行榜显示大小(revert @Folltoshe #1460)
|
- 支持kw源排行榜显示大小(revert @Folltoshe #1460)
|
||||||
|
- 优化本地歌曲换源匹配机制
|
||||||
|
|
||||||
### 修复
|
### 修复
|
||||||
|
|
||||||
|
@ -16,26 +16,26 @@ import { getLocalFilePath } from '@/utils/music'
|
|||||||
import { readLyric, readPic } from '@/utils/localMediaMetadata'
|
import { readLyric, readPic } from '@/utils/localMediaMetadata'
|
||||||
import { stat } from '@/utils/fs'
|
import { stat } from '@/utils/fs'
|
||||||
|
|
||||||
const getOtherSourceByLocal = async(musicInfo: LX.Music.MusicInfoLocal) => {
|
const getOtherSourceByLocal = async<T>(musicInfo: LX.Music.MusicInfoLocal, handler: (infos: LX.Music.MusicInfoOnline[]) => Promise<T>) => {
|
||||||
let result: LX.Music.MusicInfoOnline[] = []
|
let result: LX.Music.MusicInfoOnline[] = []
|
||||||
result = await getOtherSource(musicInfo)
|
result = await getOtherSource(musicInfo)
|
||||||
if (result.length) return result
|
if (result.length) try { return await handler(result) } catch {}
|
||||||
if (musicInfo.name.includes('-')) {
|
if (musicInfo.name.includes('-')) {
|
||||||
const [name, singer] = musicInfo.name.split('-').map(val => val.trim())
|
const [name, singer] = musicInfo.name.split('-').map(val => val.trim())
|
||||||
result = await getOtherSource({
|
result = await getOtherSource({
|
||||||
...musicInfo,
|
...musicInfo,
|
||||||
name,
|
name,
|
||||||
singer,
|
singer,
|
||||||
})
|
}, true)
|
||||||
if (result.length) return result
|
if (result.length) try { return await handler(result) } catch {}
|
||||||
result = await getOtherSource({
|
result = await getOtherSource({
|
||||||
...musicInfo,
|
...musicInfo,
|
||||||
name: singer,
|
name: singer,
|
||||||
singer: name,
|
singer: name,
|
||||||
})
|
}, true)
|
||||||
if (result.length) return result
|
if (result.length) try { return await handler(result) } catch {}
|
||||||
}
|
}
|
||||||
let fileName = (await stat(musicInfo.meta.filePath).catch(() => ({ name: null }))).name ?? musicInfo.meta.filePath.split('/').at(-1)
|
let fileName = (await stat(musicInfo.meta.filePath).catch(() => ({ name: null }))).name ?? musicInfo.meta.filePath.split(/\/|\\/).at(-1)
|
||||||
if (fileName) {
|
if (fileName) {
|
||||||
fileName = fileName.substring(0, fileName.lastIndexOf('.'))
|
fileName = fileName.substring(0, fileName.lastIndexOf('.'))
|
||||||
if (fileName != musicInfo.name) {
|
if (fileName != musicInfo.name) {
|
||||||
@ -45,25 +45,25 @@ const getOtherSourceByLocal = async(musicInfo: LX.Music.MusicInfoLocal) => {
|
|||||||
...musicInfo,
|
...musicInfo,
|
||||||
name,
|
name,
|
||||||
singer,
|
singer,
|
||||||
})
|
}, true)
|
||||||
if (result.length) return result
|
if (result.length) try { return await handler(result) } catch {}
|
||||||
result = await getOtherSource({
|
result = await getOtherSource({
|
||||||
...musicInfo,
|
...musicInfo,
|
||||||
name: singer,
|
name: singer,
|
||||||
singer: name,
|
singer: name,
|
||||||
})
|
}, true)
|
||||||
} else {
|
} else {
|
||||||
result = await getOtherSource({
|
result = await getOtherSource({
|
||||||
...musicInfo,
|
...musicInfo,
|
||||||
name: fileName,
|
name: fileName,
|
||||||
singer: '',
|
singer: '',
|
||||||
})
|
}, true)
|
||||||
}
|
}
|
||||||
if (result.length) return result
|
if (result.length) try { return await handler(result) } catch {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
throw new Error('source not found')
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () => {} }: {
|
export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () => {} }: {
|
||||||
@ -85,14 +85,14 @@ export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () =>
|
|||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
onToggleSource()
|
onToggleSource()
|
||||||
const otherSource = await getOtherSourceByLocal(musicInfo)
|
return getOtherSourceByLocal(musicInfo, async(otherSource) => {
|
||||||
if (!otherSource.length) throw new Error('source not found')
|
return getOnlineOtherSourceMusicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, quality: targetQuality, musicInfo: targetMusicInfo, isFromCache }) => {
|
||||||
return getOnlineOtherSourceMusicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, quality: targetQuality, musicInfo: targetMusicInfo, isFromCache }) => {
|
// saveLyric(musicInfo, data.lyricInfo)
|
||||||
// saveLyric(musicInfo, data.lyricInfo)
|
if (!isFromCache) void saveMusicUrl(targetMusicInfo, targetQuality, url)
|
||||||
if (!isFromCache) void saveMusicUrl(targetMusicInfo, targetQuality, url)
|
|
||||||
|
|
||||||
// TODO: save url ?
|
// TODO: save url ?
|
||||||
return url
|
return url
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,15 +120,15 @@ export const getPicUrl = async({ musicInfo, listId, isRefresh, skipFilePic, onTo
|
|||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
onToggleSource()
|
onToggleSource()
|
||||||
const otherSource = await getOtherSourceByLocal(musicInfo)
|
return getOtherSourceByLocal(musicInfo, async(otherSource) => {
|
||||||
if (!otherSource.length) throw new Error('source not found')
|
return getOnlineOtherSourcePicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, musicInfo: targetMusicInfo, isFromCache }) => {
|
||||||
return getOnlineOtherSourcePicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, musicInfo: targetMusicInfo, isFromCache }) => {
|
if (listId) {
|
||||||
if (listId) {
|
musicInfo.meta.picUrl = url
|
||||||
musicInfo.meta.picUrl = url
|
void updateListMusics([{ id: listId, musicInfo }])
|
||||||
void updateListMusics([{ id: listId, musicInfo }])
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return url
|
return url
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,15 +169,14 @@ export const getLyricInfo = async({ musicInfo, isRefresh, skipFileLyric, onToggl
|
|||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
onToggleSource()
|
onToggleSource()
|
||||||
const otherSource = await getOtherSourceByLocal(musicInfo)
|
return getOtherSourceByLocal(musicInfo, async(otherSource) => {
|
||||||
if (!otherSource.length) throw new Error('source not found')
|
return getOnlineOtherSourceLyricInfo({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(async({ lyricInfo, musicInfo: targetMusicInfo, isFromCache }) => {
|
||||||
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
void saveLyric(musicInfo, lyricInfo)
|
||||||
return getOnlineOtherSourceLyricInfo({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ lyricInfo, musicInfo: targetMusicInfo, isFromCache }) => {
|
|
||||||
void saveLyric(musicInfo, lyricInfo)
|
|
||||||
|
|
||||||
if (isFromCache) return buildLyricInfo(lyricInfo)
|
if (isFromCache) return buildLyricInfo(lyricInfo)
|
||||||
void saveLyric(targetMusicInfo, lyricInfo)
|
void saveLyric(targetMusicInfo, lyricInfo)
|
||||||
|
|
||||||
return buildLyricInfo(lyricInfo)
|
return buildLyricInfo(lyricInfo)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ const parseLyric = str => {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
getIntv(interval) {
|
getIntv(interval) {
|
||||||
|
if (!interval) return 0
|
||||||
let intvArr = interval.split(':')
|
let intvArr = interval.split(':')
|
||||||
let intv = 0
|
let intv = 0
|
||||||
let unit = 1
|
let unit = 1
|
||||||
|
@ -72,6 +72,7 @@ export default {
|
|||||||
return arr.join('、')
|
return arr.join('、')
|
||||||
},
|
},
|
||||||
getIntv(interval) {
|
getIntv(interval) {
|
||||||
|
if (!interval) return 0
|
||||||
let intvArr = interval.split(':')
|
let intvArr = interval.split(':')
|
||||||
let intv = 0
|
let intv = 0
|
||||||
let unit = 1
|
let unit = 1
|
||||||
|
@ -126,6 +126,7 @@ const parseTools = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
getIntv(interval) {
|
getIntv(interval) {
|
||||||
|
if (!interval) return 0
|
||||||
if (!interval.includes('.')) interval += '.0'
|
if (!interval.includes('.')) interval += '.0'
|
||||||
let arr = interval.split(/:|\./)
|
let arr = interval.split(/:|\./)
|
||||||
while (arr.length < 3) arr.unshift('0')
|
while (arr.length < 3) arr.unshift('0')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user