diff --git a/src/lib/server/songs.ts b/src/lib/server/songs.ts index 6096224..5c79631 100644 --- a/src/lib/server/songs.ts +++ b/src/lib/server/songs.ts @@ -104,7 +104,16 @@ export const getSongUrl = async (id: number | string) => { const level = 'exhigh' const filePath = path.join(CACHE_DIR, `${id}/${level}.mp3`) const publicUrl = `/audio/${id}/${level}.mp3` - if (await fs.exists(filePath)) return publicUrl + const vocalsPath = path.join(CACHE_DIR, `${id}/vocals.opus`) + const instrumentalPath = path.join(CACHE_DIR, `${id}/instrumental.opus`) + + if (await fs.exists(filePath)) { + return { + url: publicUrl, + vocalsUrl: (await fs.exists(vocalsPath)) ? `/audio/${id}/vocals.opus` : null, + instrumentalUrl: (await fs.exists(instrumentalPath)) ? `/audio/${id}/instrumental.opus` : null + } + } // Check netease api status if (await checkNetease() === null) throw error(500, '服务器的网易云账号坏掉了 :(') @@ -125,7 +134,7 @@ export const getSongUrl = async (id: number | string) => { await fs.writeFile(filePath, Buffer.from(buffer)) console.log(`Song ${id} cached to ${filePath}`) - return publicUrl + return { url: publicUrl } } // ///////////////////////////////////////////////////////////////////////////// diff --git a/src/routes/song/[id]/play/+page.svelte b/src/routes/song/[id]/play/+page.svelte index 6ebc949..d29ed6a 100644 --- a/src/routes/song/[id]/play/+page.svelte +++ b/src/routes/song/[id]/play/+page.svelte @@ -80,7 +80,7 @@ hiddenInput.addEventListener('blur', onBlur) if (data.audioUrl) { - musicControl = new MusicControl(data.audioUrl) + musicControl = new MusicControl(data.audioUrl.url) musicControl.setLyrics(deduplicatedLyrics) musicControl.start() }