diff --git a/package.json b/package.json index c62e9e8..db47cc3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aquavox", - "version": "2.0.1", + "version": "2.0.2", "private": false, "scripts": { "dev": "vite dev", diff --git a/src/lib/components/lyrics.svelte b/src/lib/components/lyrics.svelte index 707bf21..eef572d 100644 --- a/src/lib/components/lyrics.svelte +++ b/src/lib/components/lyrics.svelte @@ -2,8 +2,7 @@ import userAdjustingProgress from '$lib/state/userAdjustingProgress'; import createLyricsSearcher from '$lib/lyrics/lyricSearcher'; import progressBarRaw from '$lib/state/progressBarRaw'; - import type { LrcJsonData } from '$lib/lyrics/parser'; - import progressBarSlideValue from '$lib/state/progressBarSlideValue'; + import type { LrcJsonData } from '$lib/lyrics/LRCparser'; import nextUpdate from '$lib/state/nextUpdate'; import truncate from '$lib/utils/truncate'; diff --git a/src/lib/lyrics/parser.ts b/src/lib/lyrics/LRCparser.ts similarity index 100% rename from src/lib/lyrics/parser.ts rename to src/lib/lyrics/LRCparser.ts diff --git a/src/lib/lyrics/LRCtoAMLL.ts b/src/lib/lyrics/LRCtoAMLL.ts new file mode 100644 index 0000000..7407bd9 --- /dev/null +++ b/src/lib/lyrics/LRCtoAMLL.ts @@ -0,0 +1,20 @@ +import type { LyricLine } from '@applemusic-like-lyrics/core'; +import type { ScriptItem } from '$lib/lyrics/LRCparser'; + +export default function mapLRCtoAMLL(line: ScriptItem, i: number, lines: ScriptItem[]): LyricLine { + return { + words: [ + { + word: line.text, + startTime: line.start * 1000, + endTime: line.end * 1000 + } + ], + startTime: line.start * 1000, + endTime: line.end * 1000, + translatedLyric: line.translation ?? "", + romanLyric: '', + isBG: false, + isDuet: false + }; +} diff --git a/src/lib/lyrics/mapLyric.ts b/src/lib/lyrics/mapLyric.ts deleted file mode 100644 index 13f96b2..0000000 --- a/src/lib/lyrics/mapLyric.ts +++ /dev/null @@ -1,18 +0,0 @@ -import type { LyricLine } from "@applemusic-like-lyrics/core"; -import { - type LyricLine as RawLyricLine, - parseLrc, - parseYrc, - parseLys, - parseQrc, -} from "@applemusic-like-lyrics/lyric"; - -export const mapLyric = (line: RawLyricLine, i: number, lines: RawLyricLine[]): LyricLine => ({ - words: line.words, - startTime: line.words[0]?.startTime ?? 0, - endTime: line.words[line.words.length - 1]?.endTime ?? Infinity, - translatedLyric: '', - romanLyric: '', - isBG: false, - isDuet: false -}); diff --git a/src/routes/import/[id]/lyric/+page.svelte b/src/routes/import/[id]/lyric/+page.svelte index 671d785..29c9904 100644 --- a/src/routes/import/[id]/lyric/+page.svelte +++ b/src/routes/import/[id]/lyric/+page.svelte @@ -2,7 +2,7 @@ import { page } from '$app/stores'; import FileList from '$lib/components/import/fileList.svelte'; import FileSelector from '$lib/components/import/fileSelector.svelte'; - import localforage from '$lib/utils/storage.js'; + import localforage from '$lib/utils/storage'; import { fileListState } from '$lib/state/fileList.state'; import { useAtom } from 'jotai-svelte'; const fileList = useAtom(fileListState); diff --git a/src/routes/import/local/+page.svelte b/src/routes/import/local/+page.svelte index f986f13..9b1b510 100644 --- a/src/routes/import/local/+page.svelte +++ b/src/routes/import/local/+page.svelte @@ -4,7 +4,7 @@ import { fileListState, finalFileListState } from '$lib/state/fileList.state'; import { localImportFailed, localImportSuccess } from '$lib/state/localImportStatus.state'; import { useAtom } from 'jotai-svelte'; - import localforage from '$lib/utils/storage.js'; + import localforage from '$lib/utils/storage'; import { v1 as uuidv1 } from 'uuid'; const fileList = useAtom(fileListState); const finalFiles = useAtom(finalFileListState); diff --git a/src/routes/play/[id]/+page.svelte b/src/routes/play/[id]/+page.svelte index d0b9166..c779a4a 100644 --- a/src/routes/play/[id]/+page.svelte +++ b/src/routes/play/[id]/+page.svelte @@ -11,12 +11,13 @@ import type { IAudioMetadata } from 'music-metadata-browser'; import { onDestroy, onMount } from 'svelte'; import progressBarRaw from '$lib/state/progressBarRaw'; - import { parseTTML, type TTMLLyric } from '$lib/ttml'; + import { parseTTML } from '$lib/ttml'; import type { LyricLine, LyricLineMouseEvent, LyricPlayer } from '@applemusic-like-lyrics/core'; import NewLyrics from '$lib/components/newLyrics.svelte'; import { LyricPlayer as CoreLyricPlayer } from '@applemusic-like-lyrics/core'; - import { parseLrc } from '@applemusic-like-lyrics/lyric'; - import { mapLyric } from '$lib/lyrics/mapLyric'; + import lrcParser from '$lib/lyrics/LRCparser'; + import mapLRCtoAMLL from '$lib/lyrics/LRCtoAMLL'; + //import { parseLrc } from '@applemusic-like-lyrics/lyric'; const audioId = $page.params.id; let audioPlayer: HTMLAudioElement | null = null; @@ -100,32 +101,20 @@ } }); localforage.getItem(`${audioId}-lyric`, function (err, file) { - if (file) { - const f = file as File; - f.text().then((lr) => { - if (f.name.endsWith('.ttml')) { - lyricLines = parseTTML(lr).lyricLines; - hasLyrics = true; - } else if (f.name.endsWith('.lrc')) { - lyricLines = parseLrc(lr).map((line, i, lines) => ({ - words: [ - { - word: line.words[0]?.word ?? '', - startTime: line.words[0]?.startTime ?? 0, - endTime: lines[i + 1]?.words?.[0]?.startTime ?? Infinity - } - ], - startTime: line.words[0]?.startTime ?? 0, - endTime: lines[i + 1]?.words?.[0]?.startTime ?? Infinity, - translatedLyric: '', - romanLyric: '', - isBG: false, - isDuet: false - })); - hasLyrics = true; - } - }); - } + if (!file) return; + const f = file as File; + f.text().then((lr) => { + if (f.name.endsWith('.ttml')) { + lyricLines = parseTTML(lr).lyricLines; + hasLyrics = true; + } + else if (f.name.endsWith('.lrc')) { + const parsed = lrcParser(lr); + if (parsed.scripts == undefined) return; + lyricLines = lrcParser(lr).scripts!.map(mapLRCtoAMLL); + hasLyrics = true; + } + }); }); } @@ -235,7 +224,7 @@ playing={!paused} {onLyricLineClick} alignPosition={0.3} - class="absolute top-[6.5rem] md:top-36 xl:top-0 w-screen xl:w-[52vw] px-6 md:px-12 lg:px-[7.5rem] xl:left-[45vw] + class="absolute top-[6.5rem] md:top-36 xl:top-0 w-screen xl:w-[52vw] md:px-6 lg:px-[7.5rem] xl:left-[45vw] xl:px-[3vw] h-[calc(100vh-17rem)] xl:h-screen font-sans text-left no-scrollbar overflow-y-auto z-[1] font-semibold mix-blend-plus-lighter" /> diff --git a/src/test/lrcParser.test.ts b/src/test/lrcParser.test.ts index f3193a2..bd22324 100644 --- a/src/test/lrcParser.test.ts +++ b/src/test/lrcParser.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; import fs from 'fs'; -import { parseLRC } from '$lib/lyrics/parser'; +import { parseLRC } from '$lib/lyrics/LRCparser'; describe('LRC parser test', () => { const test01Buffer = fs.readFileSync('./src/test/resources/test-01.lrc');