优化本地歌曲换源匹配机制
This commit is contained in:
parent
9d8fe4be06
commit
45fc8c77b6
@ -8,6 +8,7 @@
|
||||
- 不再丢弃kg源逐行歌词(@helloplhm-qwq)
|
||||
- 支持kw源排行榜显示大小(revert @Folltoshe #1460)
|
||||
- 托盘菜单添加多语言支持(#1802)
|
||||
- 优化本地歌曲换源匹配机制
|
||||
|
||||
### 修复
|
||||
|
||||
|
||||
@ -16,26 +16,26 @@ import {
|
||||
} from './utils'
|
||||
|
||||
|
||||
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[] = []
|
||||
result = await getOtherSource(musicInfo)
|
||||
if (result.length) return result
|
||||
if (result.length) try { return await handler(result) } catch {}
|
||||
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
|
||||
}, true)
|
||||
if (result.length) try { return await handler(result) } catch {}
|
||||
result = await getOtherSource({
|
||||
...musicInfo,
|
||||
name: singer,
|
||||
singer: name,
|
||||
})
|
||||
if (result.length) return result
|
||||
}, true)
|
||||
if (result.length) try { return await handler(result) } catch {}
|
||||
}
|
||||
let fileName = musicInfo.meta.filePath.split('/').at(-1)
|
||||
let fileName = musicInfo.meta.filePath.split(/\/|\\/).at(-1)
|
||||
if (fileName) {
|
||||
fileName = fileName.substring(0, fileName.lastIndexOf('.'))
|
||||
if (fileName != musicInfo.name) {
|
||||
@ -45,25 +45,25 @@ const getOtherSourceByLocal = async(musicInfo: LX.Music.MusicInfoLocal) => {
|
||||
...musicInfo,
|
||||
name,
|
||||
singer,
|
||||
})
|
||||
if (result.length) return result
|
||||
}, true)
|
||||
if (result.length) try { return await handler(result) } catch {}
|
||||
result = await getOtherSource({
|
||||
...musicInfo,
|
||||
name: singer,
|
||||
singer: name,
|
||||
})
|
||||
}, true)
|
||||
} else {
|
||||
result = await getOtherSource({
|
||||
...musicInfo,
|
||||
name: fileName,
|
||||
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 = () => {} }: {
|
||||
@ -84,8 +84,7 @@ export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () =>
|
||||
} catch {}
|
||||
|
||||
onToggleSource()
|
||||
const otherSource = await getOtherSourceByLocal(musicInfo)
|
||||
if (!otherSource.length) throw new Error('source not found')
|
||||
return getOtherSourceByLocal(musicInfo, async(otherSource) => {
|
||||
return getOnlineOtherSourceMusicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, quality: targetQuality, musicInfo: targetMusicInfo, isFromCache }) => {
|
||||
// saveLyric(musicInfo, data.lyricInfo)
|
||||
if (!isFromCache) void saveMusicUrl(targetMusicInfo, targetQuality, url)
|
||||
@ -93,6 +92,7 @@ export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () =>
|
||||
// TODO: save url ?
|
||||
return url
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const getPicUrl = async({ musicInfo, listId, isRefresh, onToggleSource = () => {} }: {
|
||||
@ -115,8 +115,7 @@ export const getPicUrl = async({ musicInfo, listId, isRefresh, onToggleSource =
|
||||
} catch {}
|
||||
|
||||
onToggleSource()
|
||||
const otherSource = await getOtherSourceByLocal(musicInfo)
|
||||
if (!otherSource.length) throw new Error('source not found')
|
||||
return getOtherSourceByLocal(musicInfo, async(otherSource) => {
|
||||
return getOnlineOtherSourcePicUrl({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(({ url, musicInfo: targetMusicInfo, isFromCache }) => {
|
||||
if (listId) {
|
||||
musicInfo.meta.picUrl = url
|
||||
@ -125,6 +124,7 @@ export const getPicUrl = async({ musicInfo, listId, isRefresh, onToggleSource =
|
||||
|
||||
return url
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const getLyricInfo = async({ musicInfo, isRefresh, onToggleSource = () => {} }: {
|
||||
@ -152,10 +152,8 @@ export const getLyricInfo = async({ musicInfo, isRefresh, onToggleSource = () =>
|
||||
} catch {}
|
||||
|
||||
onToggleSource()
|
||||
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 }) => {
|
||||
return getOtherSourceByLocal(musicInfo, async(otherSource) => {
|
||||
return getOnlineOtherSourceLyricInfo({ musicInfos: [...otherSource], onToggleSource, isRefresh }).then(async({ lyricInfo, musicInfo: targetMusicInfo, isFromCache }) => {
|
||||
void saveLyric(musicInfo, lyricInfo)
|
||||
|
||||
if (isFromCache) return buildLyricInfo(lyricInfo)
|
||||
@ -163,4 +161,5 @@ export const getLyricInfo = async({ musicInfo, isRefresh, onToggleSource = () =>
|
||||
|
||||
return buildLyricInfo(lyricInfo)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@ -57,6 +57,7 @@ const parseLyric = str => {
|
||||
|
||||
export default {
|
||||
getIntv(interval) {
|
||||
if (!interval) return 0
|
||||
let intvArr = interval.split(':')
|
||||
let intv = 0
|
||||
let unit = 1
|
||||
|
||||
@ -72,6 +72,7 @@ export default {
|
||||
return arr.join('、')
|
||||
},
|
||||
getIntv(interval) {
|
||||
if (!interval) return 0
|
||||
let intvArr = interval.split(':')
|
||||
let intv = 0
|
||||
let unit = 1
|
||||
|
||||
@ -100,6 +100,7 @@ const parseTools = {
|
||||
return str.replace(/^[\S\s]*?LyricContent="/, '').replace(/"\/>[\S\s]*?$/, '')
|
||||
},
|
||||
getIntv(interval) {
|
||||
if (!interval) return 0
|
||||
if (!interval.includes('.')) interval += '.0'
|
||||
let arr = interval.split(/:|\./)
|
||||
while (arr.length < 3) arr.unshift('0')
|
||||
|
||||
@ -126,6 +126,7 @@ const parseTools = {
|
||||
})
|
||||
},
|
||||
getIntv(interval) {
|
||||
if (!interval) return 0
|
||||
if (!interval.includes('.')) interval += '.0'
|
||||
let arr = interval.split(/:|\./)
|
||||
while (arr.length < 3) arr.unshift('0')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user