自定义源新增支持local源的musicUrl、pic、lyric的获取操作

This commit is contained in:
lyswhut
2024-01-30 19:25:01 +08:00
parent 7893814da4
commit 1cd93344dd
7 changed files with 186 additions and 15 deletions
+25
View File
@@ -6,8 +6,11 @@ import { getLocalFilePath } from '@renderer/utils/music'
import {
buildLyricInfo,
getCachedLyricInfo,
getOnlineOtherSourceLyricByLocal,
getOnlineOtherSourceLyricInfo,
getOnlineOtherSourceMusicUrl,
getOnlineOtherSourceMusicUrlByLocal,
getOnlineOtherSourcePicByLocal,
getOnlineOtherSourcePicUrl,
getOtherSource,
} from './utils'
@@ -72,6 +75,14 @@ export const getMusicUrl = async({ musicInfo, isRefresh, onToggleSource = () =>
const path = await getLocalFilePath(musicInfo)
if (path) return encodePath(path)
}
try {
return await getOnlineOtherSourceMusicUrlByLocal(musicInfo, isRefresh).then(({ url, quality, isFromCache }) => {
if (!isFromCache) void saveMusicUrl(musicInfo, quality, url)
return url
})
} catch {}
onToggleSource()
const otherSource = await getOtherSourceByLocal(musicInfo)
if (!otherSource.length) throw new Error('source not found')
@@ -97,6 +108,12 @@ export const getPicUrl = async({ musicInfo, listId, isRefresh, onToggleSource =
if (musicInfo.meta.picUrl) return musicInfo.meta.picUrl
}
try {
return await getOnlineOtherSourcePicByLocal(musicInfo).then(({ url }) => {
return url
})
} catch {}
onToggleSource()
const otherSource = await getOtherSourceByLocal(musicInfo)
if (!otherSource.length) throw new Error('source not found')
@@ -126,6 +143,14 @@ export const getLyricInfo = async({ musicInfo, isRefresh, onToggleSource = () =>
if (lyricInfo?.lyric) return buildLyricInfo(lyricInfo)
}
try {
// eslint-disable-next-line @typescript-eslint/promise-function-async
return await getOnlineOtherSourceLyricByLocal(musicInfo, isRefresh).then(({ lyricInfo, isFromCache }) => {
if (!isFromCache) void saveLyric(musicInfo, lyricInfo)
return buildLyricInfo(lyricInfo)
})
} catch {}
onToggleSource()
const otherSource = await getOtherSourceByLocal(musicInfo)
if (!otherSource.length) throw new Error('source not found')