fix: full-feature LRC parser by umechi migrated into main app
This commit is contained in:
parent
9e388b66ce
commit
8b541818c9
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "aquavox",
|
||||
"version": "1.12.14",
|
||||
"version": "1.12.15",
|
||||
"private": false,
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
|
@ -51,11 +51,13 @@ export interface LrcMetaData {
|
||||
|
||||
export interface ParsedLrc extends LrcMetaData {
|
||||
scripts?: ParserScriptItem[];
|
||||
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface LrcJsonData extends LrcMetaData {
|
||||
scripts?: ScriptItem[];
|
||||
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
@ -64,10 +66,10 @@ interface IDTag {
|
||||
}
|
||||
|
||||
function convertTimeToMs({
|
||||
mins,
|
||||
secs,
|
||||
decimals
|
||||
}: {
|
||||
mins,
|
||||
secs,
|
||||
decimals
|
||||
}: {
|
||||
mins?: number | string;
|
||||
secs?: number | string;
|
||||
decimals?: string;
|
||||
@ -102,6 +104,7 @@ const alpha = alt_sc(
|
||||
);
|
||||
|
||||
const alphaStr = apply(rep(alpha), (r) => r.join(''));
|
||||
|
||||
function spaces<K>(): Parser<K, Token<K>[]> {
|
||||
return rep_sc(str(' '));
|
||||
}
|
||||
@ -279,3 +282,24 @@ export function parseLRC(
|
||||
}
|
||||
}, {} as ParsedLrc);
|
||||
}
|
||||
|
||||
export default function lrcParser(lrc: string): LrcJsonData {
|
||||
const parsedLrc = parseLRC(lrc, { wordDiv: '', strict: true });
|
||||
if (parsedLrc.scripts === undefined) {
|
||||
return parsedLrc as LrcJsonData;
|
||||
}
|
||||
let finalLrc: LrcJsonData = parsedLrc as LrcJsonData;
|
||||
let lyrics: ScriptItem[] = [];
|
||||
let i = 0;
|
||||
while (i < parsedLrc.scripts.length - 1) {
|
||||
let lyricLine = parsedLrc.scripts[i] as ScriptItem;
|
||||
lyricLine.start/=1000;
|
||||
lyricLine.end = parsedLrc.scripts[i+1].start / 1000;
|
||||
if (parsedLrc.scripts[i+1].text.trim() === "") {
|
||||
i+=2;
|
||||
} else i++;
|
||||
lyrics.push(lyricLine);
|
||||
}
|
||||
finalLrc.scripts = lyrics;
|
||||
return finalLrc;
|
||||
}
|
@ -8,14 +8,14 @@
|
||||
import extractFileName from '$lib/extractFileName';
|
||||
import localforage from 'localforage';
|
||||
import { writable } from 'svelte/store';
|
||||
import lrcParser, { type LrcJsonData } from 'lrc-parser-ts';
|
||||
import lrcParser, { type LrcJsonData } from '$lib/lyrics/parser';
|
||||
import userAdjustingProgress from '$lib/state/userAdjustingProgress';
|
||||
import type { IAudioMetadata } from 'music-metadata-browser';
|
||||
import { onMount } from 'svelte';
|
||||
import progressBarRaw from '$lib/state/progressBarRaw';
|
||||
|
||||
const audioId = $page.params.id;
|
||||
let audioPlayer: HTMLAudioElement;
|
||||
let audioPlayer: HTMLAudioElement | null = null;
|
||||
let volume = 1;
|
||||
let name = '';
|
||||
let singer = '';
|
||||
@ -44,22 +44,26 @@
|
||||
]
|
||||
});
|
||||
ms.setActionHandler('play', function () {
|
||||
if (audioPlayer===null) return;
|
||||
audioPlayer.play();
|
||||
paused = false;
|
||||
});
|
||||
|
||||
ms.setActionHandler('pause', function () {
|
||||
if (audioPlayer===null) return;
|
||||
audioPlayer.pause();
|
||||
paused = true;
|
||||
});
|
||||
|
||||
ms.setActionHandler('seekbackward', function () {
|
||||
if (audioPlayer===null) return;
|
||||
if (audioPlayer.currentTime > 4) {
|
||||
audioPlayer.currentTime = 0;
|
||||
}
|
||||
});
|
||||
|
||||
ms.setActionHandler('previoustrack', function () {
|
||||
if (audioPlayer===null) return;
|
||||
if (audioPlayer.currentTime > 4) {
|
||||
audioPlayer.currentTime = 0;
|
||||
}
|
||||
@ -81,6 +85,7 @@
|
||||
prepared.push('cover');
|
||||
});
|
||||
localforage.getItem(`${audioId}-file`, function (err, file) {
|
||||
if (audioPlayer===null) return;
|
||||
if (file) {
|
||||
const f = file as File;
|
||||
audioFile = f;
|
||||
@ -105,6 +110,7 @@
|
||||
}
|
||||
|
||||
function playAudio() {
|
||||
if (audioPlayer===null) return;
|
||||
if (audioPlayer.duration) {
|
||||
duration = audioPlayer.duration;
|
||||
}
|
||||
@ -114,7 +120,7 @@
|
||||
}
|
||||
|
||||
$: {
|
||||
if (!launched) {
|
||||
if (!launched && audioPlayer) {
|
||||
const requirements = ['name', 'file', 'cover'];
|
||||
let flag = true;
|
||||
for (const r of requirements) {
|
||||
@ -152,6 +158,7 @@
|
||||
$: {
|
||||
clearInterval(mainInterval);
|
||||
mainInterval = setInterval(() => {
|
||||
if (audioPlayer===null) return;
|
||||
if ($userAdjustingProgress === false)
|
||||
currentProgress = audioPlayer.currentTime;
|
||||
progressBarRaw.set(audioPlayer.currentTime);
|
||||
@ -159,6 +166,7 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (audioPlayer===null) return;
|
||||
audioPlayer.volume = localStorage.getItem('volume') ? Number(localStorage.getItem('volume')) : 1;
|
||||
});
|
||||
|
||||
@ -175,7 +183,7 @@
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>{name} - Aquavox</title>
|
||||
<title>{name} - AquaVox</title>
|
||||
</svelte:head>
|
||||
|
||||
<Background coverId={audioId} />
|
||||
|
Loading…
Reference in New Issue
Block a user