Repository Public
1import "./_env";2import { sql } from "../src/lib/db";3import { lyricsEnabled, queueLyrics } from "../src/server/lyrics";45/**6 * Queues lyrics transcription from the node's shell.7 * tsx scripts/lyrics.ts --missing every track that has no lyrics yet8 * tsx scripts/lyrics.ts --album "Thriller" one album (title contains)9 * options: --lang fr|en|es|it|de|pt (default: detect) --overwrite (also replace hand-corrected lyrics) --wait10 */11async function main() {12 const a = process.argv.slice(2);13 const val = (k: string) => { const i = a.indexOf(k); return i >= 0 ? a[i + 1] : null; };14 if (!lyricsEnabled()) throw new Error("Lyrics are not configured (LYRICS and LYRICS_PYTHON in .env)");15 const album = val("--album");16 if (!album && !a.includes("--missing")) throw new Error("Usage: tsx scripts/lyrics.ts --missing | --album <title> [--lang fr] [--overwrite] [--wait]");17 const rows = album18 ? await sql<{ id: string }[]>`SELECT t.id FROM tracks t JOIN albums al ON al.id = t.album_id WHERE al.title ILIKE ${"%" + album + "%"}`19 : await sql<{ id: string }[]>`SELECT t.id FROM tracks t WHERE NOT EXISTS (SELECT 1 FROM lyrics l WHERE l.track_id = t.id)`;20 const ids = rows.map((r) => r.id);21 const n = ids.length ? await queueLyrics(ids, val("--lang"), a.includes("--overwrite")) : 0;22 console.log(`${n} track(s) queued (${ids.length - n} skipped)`);23 if (a.includes("--wait") && n) {24 for (;;) {25 const st = await sql<{ state: string; n: number }[]>`SELECT state, count(*)::int AS n FROM lyrics WHERE track_id = ANY(${ids}::uuid[]) GROUP BY state`;26 if (!st.some((s) => s.state === "queued" || s.state === "working")) { console.log(st.map((s) => `${s.state}: ${s.n}`).join(", ")); break; }27 await new Promise((r) => setTimeout(r, 2000));28 }29 }30 await sql.end();31}32main().catch((e) => { console.error(e.message); process.exit(1); });33