From f75eeb07bea77f5d94971ccc173bfe318e92da73 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Thu, 14 Dec 2023 20:43:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=9C=AC=E5=9C=B0=E9=9F=B3?= =?UTF-8?q?=E4=B9=90=E5=9C=A8=E7=BA=BF=E4=BF=A1=E6=81=AF=E7=9A=84=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 1 + src/renderer/core/music/local.ts | 56 ++++++++++++++++++++++++++-- src/renderer/core/player/action.ts | 4 +- src/renderer/utils/musicSdk/index.js | 3 ++ 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index a33b8ae4..e238edab 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -20,6 +20,7 @@ - 优化列表全选机制,修复列表未获得焦点时仍然可以全选的问题 - 优化搜索框交互逻辑,防止鼠标操作时意外搜索候选列表的内容 - 添加对wy源某些歌曲有问题的歌词进行修复 +- 改进本地音乐在线信息的匹配机制 ### 修复 diff --git a/src/renderer/core/music/local.ts b/src/renderer/core/music/local.ts index fde798e9..7eb9eac7 100644 --- a/src/renderer/core/music/local.ts +++ b/src/renderer/core/music/local.ts @@ -13,6 +13,56 @@ import { } from './utils' +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 isRefresh: boolean @@ -23,7 +73,7 @@ export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () => if (path) return encodePath(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) @@ -48,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) { @@ -78,7 +128,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 }) => { diff --git a/src/renderer/core/player/action.ts b/src/renderer/core/player/action.ts index 31f0b319..cca565c0 100644 --- a/src/renderer/core/player/action.ts +++ b/src/renderer/core/player/action.ts @@ -150,7 +150,7 @@ const handleRestorePlay = async(restorePlayInfo: LX.Player.SavedPlayInfo) => { if (musicInfo.id != playMusicInfo.musicInfo?.id) return setMusicInfo({ pic: url }) window.app_event.picUpdated() - }) + }).catch(_ => _) void getLyricInfo({ musicInfo }).then((lyricInfo) => { if (musicInfo.id != playMusicInfo.musicInfo?.id) return @@ -200,7 +200,7 @@ const handlePlay = () => { if (musicInfo.id != playMusicInfo.musicInfo?.id) return setMusicInfo({ pic: url }) window.app_event.picUpdated() - }) + }).catch(_ => _) void getLyricInfo({ musicInfo }).then((lyricInfo) => { if (musicInfo.id != playMusicInfo.musicInfo?.id) return diff --git a/src/renderer/utils/musicSdk/index.js b/src/renderer/utils/musicSdk/index.js index 5eff2026..ae841c02 100644 --- a/src/renderer/utils/musicSdk/index.js +++ b/src/renderer/utils/musicSdk/index.js @@ -116,6 +116,9 @@ export default { ) { return item } + if (!singer) { + if (item.lowerCaseName == lowerCaseName && (interval ? item.interval == interval : true)) return item + } } return null }).catch(_ => null))