From 99ee3e9bb551df9ea6bf8ff88eeb101b86605e5e Mon Sep 17 00:00:00 2001 From: zkldi Date: Mon, 24 May 2021 11:07:04 +0100 Subject: [PATCH] Migrate BMS Songs-Charts Fixes #9 --- server/.gitignore | 3 + server/scripts/parse-beatoraja-mdb/main.ts | 85 ++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 server/scripts/parse-beatoraja-mdb/main.ts diff --git a/server/.gitignore b/server/.gitignore index 780c3b553..ba2034bf4 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -13,3 +13,6 @@ coverage scripts/arc-db-sync/charts.json scripts/arc-db-sync/songs.json scripts/validate-database-errs/* + +scripts/parse-beatoraja-mdb/* +!scripts/parse-beatoraja-mdb/main.ts \ No newline at end of file diff --git a/server/scripts/parse-beatoraja-mdb/main.ts b/server/scripts/parse-beatoraja-mdb/main.ts new file mode 100644 index 000000000..61c50cade --- /dev/null +++ b/server/scripts/parse-beatoraja-mdb/main.ts @@ -0,0 +1,85 @@ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +/* eslint-disable no-console */ +/* eslint-disable @typescript-eslint/no-var-requires */ + +// @ts-nocheck +// yeah, this script is old and wrote in JS. what of it. +const sqlDB = require("better-sqlite3")("songdata.db"); +const fs = require("fs"); + +console.log("Connecting to database..."); +console.time("DB CONNECT TIME"); +const crypto = require("crypto"); + +const ktchiSongs = []; +const ktchiCharts = []; + +const stmt = sqlDB.prepare("SELECT * FROM song"); + +let freeSongID = 1; + +const DIFFICULTY_LOOKUP = ["CUSTOM", "BEGINNER", "NORMAL", "HYPER", "ANOTHER", "CUSTOM"]; + +const PLAYTYPE_LOOKUP = { + 7: "7K", + 14: "14K", + 5: "5K", + 10: "10K", +}; + +for (const song of stmt.iterate()) { + const playtype = PLAYTYPE_LOOKUP[song.mode.toString()]; + + const songID = freeSongID; + const chartID = crypto.randomBytes(20).toString("hex"); + + let difficulty = DIFFICULTY_LOOKUP[song.difficulty]; + + freeSongID++; + + if (!difficulty) { + console.log(song.difficulty); + difficulty = "CUSTOM"; // fuck it and fuck you, you bitch. + } + + const ktchiChart = { + songID, + chartID: chartID, + rgcID: null, + data: { + notecount: song.notes, + hashMD5: song.md5, + hashSHA256: song.sha256, + }, + level: "?", + levelNum: 0, + difficulty, + playtype, + isPrimary: true, + versions: [], + }; + + const ktchiSong = { + id: songID, + title: song.title, + artist: song.artist, + firstVersion: null, + data: { + subtitle: song.subtitle ?? null, + subartist: song.subartist ?? null, + genre: song.genre ?? null, + }, + "search-titles": [], + "alt-titles": [], + }; + + ktchiSongs.push(ktchiSong); + ktchiCharts.push(ktchiChart); +} + +console.log("done"); + +fs.writeFileSync("songs.json", JSON.stringify(ktchiSongs)); +fs.writeFileSync("charts.json", JSON.stringify(ktchiCharts)); + +console.log("postwrite");