Files
Epic-The-Musical-Timeline/src/shared/lrc.ts
T
Lucas WintherandClaude Opus 5.5 27b1d2fe26 feat(content): serve the mounted content folder under /content (spec 003)
Audio with range requests, library.json, Homer books; LRC parser. Content
stays out of git and the image.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-30 02:46:43 +01:00

21 lines
675 B
TypeScript

export interface LrcLine {
time: number;
text: string;
}
const STAMP = /\[(\d+):(\d{1,2}(?:\.\d+)?)\]/g;
/** Parses LRC timed lyrics: metadata tags and untimed lines are skipped, output is sorted by time. */
export function parseLrc(text: string): LrcLine[] {
const lines: LrcLine[] = [];
for (const raw of text.split(/\r?\n/)) {
const stamps = [...raw.matchAll(STAMP)];
if (stamps.length === 0) continue;
const lyric = raw.replace(STAMP, "").trim();
for (const [, min, sec] of stamps) {
lines.push({ time: Math.round((Number(min) * 60 + Number(sec)) * 1000) / 1000, text: lyric });
}
}
return lines.sort((a, b) => a.time - b.time);
}