Files
HolodoriCalc/scripts/enrich-chart-singers.mjs
T

29 lines
1.6 KiB
JavaScript

import { readHolodoriDbTable } from './holodoridb-source.mjs';
import { readFile, writeFile } from 'node:fs/promises';
import path from 'node:path';
const projectRoot = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/(?=[A-Za-z]:)/, '')), '..');
const catalogPath = path.join(projectRoot, 'src/lib/data/exact-chart-catalog.json');
const musicRows = readHolodoriDbTable('kor', 'Music.json');
const musicById = new Map(musicRows.map((row) => [row.data?.id ?? row.id, row.data ?? row]));
const singerMetadataOverrides = {
m0334: { singerType: 'solo', singerCharacterIds: ['chr-04001'] }
};
const compactSingerType = (value) => typeof value === 'string' ? value.split('_').at(-1)?.toLowerCase() ?? null : null;
const catalog = JSON.parse(await readFile(catalogPath, 'utf8'));
for (const entry of catalog.charts) {
const music = musicById.get(entry.songId);
const singerOverride = singerMetadataOverrides[entry.songId];
entry.singerType = singerOverride?.singerType ?? compactSingerType(music?.musicSingerType);
entry.singerCharacterIds = singerOverride?.singerCharacterIds ?? music?.characterIds ?? [];
const chartPath = path.join(projectRoot, 'static', entry.path.replace(/^\//, '').replace(/^data[\\/]charts[\\/]/, 'data/charts/'));
const chart = JSON.parse(await readFile(chartPath, 'utf8'));
chart.singerType = entry.singerType;
chart.singerCharacterIds = entry.singerCharacterIds;
await writeFile(chartPath, JSON.stringify(chart), 'utf8');
}
await writeFile(catalogPath, `${JSON.stringify(catalog, null, 2)}\n`, 'utf8');
console.log(`${catalog.charts.length}개 채보에 가창자 정보를 추가했습니다.`);