fix: LRC parser support
This commit is contained in:
parent
26bb6b5bdf
commit
7947b46af5
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "aquavox",
|
"name": "aquavox",
|
||||||
"version": "2.0.1",
|
"version": "2.0.2",
|
||||||
"private": false,
|
"private": false,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
import userAdjustingProgress from '$lib/state/userAdjustingProgress';
|
import userAdjustingProgress from '$lib/state/userAdjustingProgress';
|
||||||
import createLyricsSearcher from '$lib/lyrics/lyricSearcher';
|
import createLyricsSearcher from '$lib/lyrics/lyricSearcher';
|
||||||
import progressBarRaw from '$lib/state/progressBarRaw';
|
import progressBarRaw from '$lib/state/progressBarRaw';
|
||||||
import type { LrcJsonData } from '$lib/lyrics/parser';
|
import type { LrcJsonData } from '$lib/lyrics/LRCparser';
|
||||||
import progressBarSlideValue from '$lib/state/progressBarSlideValue';
|
|
||||||
import nextUpdate from '$lib/state/nextUpdate';
|
import nextUpdate from '$lib/state/nextUpdate';
|
||||||
import truncate from '$lib/utils/truncate';
|
import truncate from '$lib/utils/truncate';
|
||||||
|
|
||||||
|
20
src/lib/lyrics/LRCtoAMLL.ts
Normal file
20
src/lib/lyrics/LRCtoAMLL.ts
Normal file
@ -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
|
||||||
|
};
|
||||||
|
}
|
@ -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
|
|
||||||
});
|
|
@ -2,7 +2,7 @@
|
|||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores';
|
||||||
import FileList from '$lib/components/import/fileList.svelte';
|
import FileList from '$lib/components/import/fileList.svelte';
|
||||||
import FileSelector from '$lib/components/import/fileSelector.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 { fileListState } from '$lib/state/fileList.state';
|
||||||
import { useAtom } from 'jotai-svelte';
|
import { useAtom } from 'jotai-svelte';
|
||||||
const fileList = useAtom(fileListState);
|
const fileList = useAtom(fileListState);
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
import { fileListState, finalFileListState } from '$lib/state/fileList.state';
|
import { fileListState, finalFileListState } from '$lib/state/fileList.state';
|
||||||
import { localImportFailed, localImportSuccess } from '$lib/state/localImportStatus.state';
|
import { localImportFailed, localImportSuccess } from '$lib/state/localImportStatus.state';
|
||||||
import { useAtom } from 'jotai-svelte';
|
import { useAtom } from 'jotai-svelte';
|
||||||
import localforage from '$lib/utils/storage.js';
|
import localforage from '$lib/utils/storage';
|
||||||
import { v1 as uuidv1 } from 'uuid';
|
import { v1 as uuidv1 } from 'uuid';
|
||||||
const fileList = useAtom(fileListState);
|
const fileList = useAtom(fileListState);
|
||||||
const finalFiles = useAtom(finalFileListState);
|
const finalFiles = useAtom(finalFileListState);
|
||||||
|
@ -11,12 +11,13 @@
|
|||||||
import type { IAudioMetadata } from 'music-metadata-browser';
|
import type { IAudioMetadata } from 'music-metadata-browser';
|
||||||
import { onDestroy, onMount } from 'svelte';
|
import { onDestroy, onMount } from 'svelte';
|
||||||
import progressBarRaw from '$lib/state/progressBarRaw';
|
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 type { LyricLine, LyricLineMouseEvent, LyricPlayer } from '@applemusic-like-lyrics/core';
|
||||||
import NewLyrics from '$lib/components/newLyrics.svelte';
|
import NewLyrics from '$lib/components/newLyrics.svelte';
|
||||||
import { LyricPlayer as CoreLyricPlayer } from '@applemusic-like-lyrics/core';
|
import { LyricPlayer as CoreLyricPlayer } from '@applemusic-like-lyrics/core';
|
||||||
import { parseLrc } from '@applemusic-like-lyrics/lyric';
|
import lrcParser from '$lib/lyrics/LRCparser';
|
||||||
import { mapLyric } from '$lib/lyrics/mapLyric';
|
import mapLRCtoAMLL from '$lib/lyrics/LRCtoAMLL';
|
||||||
|
//import { parseLrc } from '@applemusic-like-lyrics/lyric';
|
||||||
|
|
||||||
const audioId = $page.params.id;
|
const audioId = $page.params.id;
|
||||||
let audioPlayer: HTMLAudioElement | null = null;
|
let audioPlayer: HTMLAudioElement | null = null;
|
||||||
@ -100,32 +101,20 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
localforage.getItem(`${audioId}-lyric`, function (err, file) {
|
localforage.getItem(`${audioId}-lyric`, function (err, file) {
|
||||||
if (file) {
|
if (!file) return;
|
||||||
const f = file as File;
|
const f = file as File;
|
||||||
f.text().then((lr) => {
|
f.text().then((lr) => {
|
||||||
if (f.name.endsWith('.ttml')) {
|
if (f.name.endsWith('.ttml')) {
|
||||||
lyricLines = parseTTML(lr).lyricLines;
|
lyricLines = parseTTML(lr).lyricLines;
|
||||||
hasLyrics = true;
|
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
|
|
||||||
}
|
}
|
||||||
],
|
else if (f.name.endsWith('.lrc')) {
|
||||||
startTime: line.words[0]?.startTime ?? 0,
|
const parsed = lrcParser(lr);
|
||||||
endTime: lines[i + 1]?.words?.[0]?.startTime ?? Infinity,
|
if (parsed.scripts == undefined) return;
|
||||||
translatedLyric: '',
|
lyricLines = lrcParser(lr).scripts!.map(mapLRCtoAMLL);
|
||||||
romanLyric: '',
|
|
||||||
isBG: false,
|
|
||||||
isDuet: false
|
|
||||||
}));
|
|
||||||
hasLyrics = true;
|
hasLyrics = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +224,7 @@
|
|||||||
playing={!paused}
|
playing={!paused}
|
||||||
{onLyricLineClick}
|
{onLyricLineClick}
|
||||||
alignPosition={0.3}
|
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
|
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"
|
text-left no-scrollbar overflow-y-auto z-[1] font-semibold mix-blend-plus-lighter"
|
||||||
/>
|
/>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { parseLRC } from '$lib/lyrics/parser';
|
import { parseLRC } from '$lib/lyrics/LRCparser';
|
||||||
|
|
||||||
describe('LRC parser test', () => {
|
describe('LRC parser test', () => {
|
||||||
const test01Buffer = fs.readFileSync('./src/test/resources/test-01.lrc');
|
const test01Buffer = fs.readFileSync('./src/test/resources/test-01.lrc');
|
||||||
|
Loading…
Reference in New Issue
Block a user