-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall-music.ts
More file actions
69 lines (60 loc) · 2.16 KB
/
all-music.ts
File metadata and controls
69 lines (60 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
Ongeki All-music Generator
Run this with Bun, with all options (including A000) in a folder named `option`
It will spit out `all-music.json`
Jackets are not included
*/
import { XMLParser } from "fast-xml-parser";
import ora from "ora";
import fs from "fs";
const options = fs.readdirSync("option");
interface Song {
name: string,
ver: string,
composer: string,
genre?: string,
lunatic: boolean,
notes: {
lv: number
}[]
}
let allMusic: Record<string, Song> = {};
function getXmlContents(file: string) {
if (!fs.existsSync(file))
return;
if (!fs.statSync(file).isFile())
return;
const data = fs.readFileSync(file).toString();
const parser = new XMLParser();
return parser.parse(data);
}
for (const option of options) {
const spinner = ora(`Processing ${option}`).start();
if (fs.existsSync(`option/${option}/music`)) {
for (const songFolder of fs.readdirSync(`option/${option}/music`)
.filter(v => fs.statSync(`option/${option}/music/${v}`).isDirectory())
) {
let xmlData = getXmlContents(`option/${option}/music/${songFolder}/Music.xml`);
if (!xmlData) continue;
allMusic[
xmlData.MusicData.Name.id
] = {
name: xmlData.MusicData.Name.str,
ver: xmlData.MusicData.VersionID.id,
composer: xmlData.MusicData.ArtistName.str,
genre: xmlData.MusicData.Genre?.str ?? null,
lunatic: xmlData.MusicData.IsLunatic,
notes: (() => {
const levels = xmlData.MusicData.FumenData.FumenData
.filter(v => (parseInt(v.FumenConstIntegerPart) + (parseInt(v.FumenConstFractionalPart ?? "0") / 100)) >= 1)
.map(v => ({
lv: parseInt(v.FumenConstIntegerPart) + (parseInt(v.FumenConstFractionalPart ?? "0") / 100)
}));
return levels.length > 0 ? levels : [{lv: 0}];
})()
}
}
}
spinner.stop();
}
fs.writeFileSync(`all-music.json`, JSON.stringify(allMusic));