/** Starcraft "노래 맞추기" map songs (data/seed/sta_songs.json, docs/07). Years there are unreliable: used only to fill gaps. */ import type { Database } from 'bun:sqlite'; import { Catalog, Job } from './catalog'; interface StaSong { id: number; title: string; artist: string; year?: number; found_in: string[]; } export async function importSta(db: Database, seedPath: string) { const data = (await Bun.file(seedPath).json()) as { songs: StaSong[] }; const job = new Job(db, 'import-sta', data.songs.length); const catalog = new Catalog(db); const thisYear = new Date().getFullYear(); let created = 0; for (const [i, s] of data.songs.entries()) { const [, isNew] = catalog.upsert({ title: s.title.trim(), artists: [{ name: s.artist.trim() }], // 26 songs say "2026" (map maker's date, not the release): only take years before this year. year: s.year && s.year < thisYear ? s.year : null, genres: ['kpop'], source: 'sta', ref: String(s.id), }); if (isNew) created++; if (i % 100 === 0) job.progress(i); } job.progress(data.songs.length); job.log(`sta done: ${data.songs.length} songs, new ${created} (rest merged into existing songs)`); job.finish('done'); return { total: data.songs.length, created }; }