diff --git a/src/lib/client.ts b/src/lib/client.ts index 4191e66..f72ab60 100644 --- a/src/lib/client.ts +++ b/src/lib/client.ts @@ -1,4 +1,4 @@ -import type { ResultDocument, UserData } from "../shared/types"; +import type { ResultDocument, UserData } from "./types"; export async function post(endpoint: string, data: any) { diff --git a/src/shared/ext.ts b/src/lib/ext.ts similarity index 100% rename from src/shared/ext.ts rename to src/lib/ext.ts diff --git a/src/lib/server/db.ts b/src/lib/server/db.ts index a588f35..a63bd41 100644 --- a/src/lib/server/db.ts +++ b/src/lib/server/db.ts @@ -1,5 +1,5 @@ import { MongoClient } from "mongodb" -import type { UserDocument, ResultDocument } from "../../shared/types" +import type { UserDocument, ResultDocument } from "../types" export const mongo = new MongoClient(process.env.MONGO_URL || "mongodb://cat:meow@localhost:27017/") mongo.connect() diff --git a/src/lib/server/result.ts b/src/lib/server/result.ts index 426feef..2633183 100644 --- a/src/lib/server/result.ts +++ b/src/lib/server/result.ts @@ -1,4 +1,4 @@ -import type { ResultDocument } from "../../shared/types" +import type { ResultDocument } from "../types" import { dbs } from "./db" import { ObjectId } from "mongodb" diff --git a/src/lib/server/songs.ts b/src/lib/server/songs.ts index db4f1aa..20a8361 100644 --- a/src/lib/server/songs.ts +++ b/src/lib/server/songs.ts @@ -1,11 +1,11 @@ import * as ne from '@neteasecloudmusicapienhanced/api' import { aiParseLyrics } from './tools/lyrics' -import type { NeteaseSong, UserDocument } from '../../shared/types' +import type { NeteaseSong, UserDocument } from '../types' import { dbs } from './db' import { franc } from 'franc' import { error } from '@sveltejs/kit' import type { ObjectId } from 'mongodb' -import '../../shared/ext' +import '../ext' import { promises as fs } from 'fs' import path from 'path' @@ -168,6 +168,30 @@ export const prepareSong = async (songId: number) => { const taskAudio = addTask('从网易云获取音乐') await getSongUrl(songId) taskAudio.progress = 1 + + // 4. Source Separation + const taskSeparation = addTask('AI 人声分离') + const vocalsPath = path.join(CACHE_DIR, `${songId}/vocals.mp3`) + + let retries = 0 + // Wait up to 10 minutes (separation can be slow on CPU) + while (retries < 600) { + try { + await fs.access(vocalsPath) + taskSeparation.progress = 1 + break + } catch { + // File doesn't exist yet + await new Promise(r => setTimeout(r, 1000)) + retries++ + // Update progress to show it's alive + if (retries % 5 === 0) taskSeparation.progress = Math.min(0.99, retries / 600) + } + } + + if (taskSeparation.progress < 1) { + addTask('警告: AI 人声分离超时,请检查后台脚本').progress = -1 + } state.status = 'done' diff --git a/src/lib/server/tools/lyrics.ts b/src/lib/server/tools/lyrics.ts index 58863a9..09f4fb6 100644 --- a/src/lib/server/tools/lyrics.ts +++ b/src/lib/server/tools/lyrics.ts @@ -1,5 +1,5 @@ import { OpenRouter } from '@openrouter/sdk' -import type { LyricLine, LyricSegment } from '../../../shared/types' +import type { LyricLine, LyricSegment } from '../../types' import { isKana, isKanji } from 'wanakana' // Please put OPENROUTER_API_KEY in your environment variables. diff --git a/src/lib/server/user.ts b/src/lib/server/user.ts index c0754d1..af24f83 100644 --- a/src/lib/server/user.ts +++ b/src/lib/server/user.ts @@ -1,5 +1,5 @@ import { dbs } from "./db" -import { type UserDocument, type UserData } from "../../shared/types.ts"; +import { type UserDocument, type UserData } from "$lib/types.ts"; import { error } from "@sveltejs/kit"; const users = dbs.users diff --git a/src/shared/types.ts b/src/lib/types.ts similarity index 100% rename from src/shared/types.ts rename to src/lib/types.ts diff --git a/src/components/Button.svelte b/src/lib/ui/Button.svelte similarity index 100% rename from src/components/Button.svelte rename to src/lib/ui/Button.svelte diff --git a/src/components/IconButton.svelte b/src/lib/ui/IconButton.svelte similarity index 100% rename from src/components/IconButton.svelte rename to src/lib/ui/IconButton.svelte diff --git a/src/components/TitleHeader.svelte b/src/lib/ui/TitleHeader.svelte similarity index 100% rename from src/components/TitleHeader.svelte rename to src/lib/ui/TitleHeader.svelte diff --git a/src/components/appbar/AppBar.svelte b/src/lib/ui/appbar/AppBar.svelte similarity index 100% rename from src/components/appbar/AppBar.svelte rename to src/lib/ui/appbar/AppBar.svelte diff --git a/src/components/listitem/ImageListItem.svelte b/src/lib/ui/listitem/ImageListItem.svelte similarity index 100% rename from src/components/listitem/ImageListItem.svelte rename to src/lib/ui/listitem/ImageListItem.svelte diff --git a/src/components/listitem/SongInfo.svelte b/src/lib/ui/listitem/SongInfo.svelte similarity index 82% rename from src/components/listitem/SongInfo.svelte rename to src/lib/ui/listitem/SongInfo.svelte index 9ac8360..829434e 100644 --- a/src/components/listitem/SongInfo.svelte +++ b/src/lib/ui/listitem/SongInfo.svelte @@ -1,6 +1,6 @@