Commit 91a62fd6 authored by nanahira's avatar nanahira

rewrite for shiftjis

parent e3456226
const fs = require('fs');
const crypto = require('crypto');
//const sqlite3 = require('sqlite3').verbose();
//const iconv = require('iconv-lite');
const iconv = require('iconv-lite');
//const convert = require('encoding').convert
const fpath = process.argv[2];
var all_songs = [];
let all_songs = [];
const courseTypes = {
"0": "easy",
......@@ -17,102 +17,115 @@ const courseTypes = {
"edit": "ura"
}
function get_sql(song) {
return "INSERT INTO songs VALUES(" + song.song_id + ",'" + song.title + "',NULL," + (song.subtitle ? "'" + song.subtitle + "'" : "NULL") + ",NULL," + (song.difficulty.easy ? song.difficulty.easy : "NULL") + "," + (song.difficulty.normal ? song.difficulty.normal : "NULL") + "," + (song.difficulty.hard ? song.difficulty.hard : "NULL") + "," + (song.difficulty.oni ? song.difficulty.oni : "NULL") + "," + (song.difficulty.ura ? song.difficulty.ura : "NULL") + ",1," + song.category + ",'tja',-0.023,NULL," + (song.preview ? song.preview : "NULL") + ",NULL,NULL,'" + song.hash + "');";
}
//console.log("Reading: " + fpath);
const category_array = fs.readdirSync(fpath);
async function main() {
const category_array = await fs.promises.readdir(fpath);
for (var category_raw of category_array) {
const category = parseInt(category_raw);
if (isNaN(category))
continue;
const category_path = fpath + "/" + category;
//console.log("Reading: " + category_path);
const songs = fs.readdirSync(category_path);
for (var song_raw of songs) {
const song_id = parseInt(song_raw);
if (isNaN(song_id))
for (let category_raw of category_array) {
const category = parseInt(category_raw);
if (isNaN(category))
continue;
const tja_path = category_path + "/" + song_id + "/main.tja"
//console.log("Reading: " + tja_path);
const tja_buffer = fs.readFileSync(tja_path);
let md5 = crypto.createHash('md5');
md5.update(tja_buffer);
const tja_hash = md5.digest("base64").replace(/=/g, "");
const tja_text = tja_buffer.toString();
//var buf = Buffer.from(tja_base64, "base64");
//var encoded_buf = convert(buf, "UTF-8", "SHIFT-JIS");
//const tja_text = encoded_buf.toString('utf8');
const tja_lines = tja_text.split("\n");
var res = {
difficulty: {
easy: null,
normal: null,
hard: null,
oni: null,
ura: null,
},
song_id: song_id,
category: category,
preview: null,
branch: {
easy: false,
normal: false,
hard: false,
oni: false,
ura: false,
},
hash: tja_hash
}
var courseName = "oni";
for (var line of tja_lines) {
const line_ = line.trim();
if (line_.indexOf(":") > 0) {
//const line__ = convert(line_, "UTF-8", "SHIFT-JIS").toString('utf8');
const temp = line_.split(":");
const key = temp[0].toLowerCase();
const value = temp[1];
//console.log("Find value: " + key +" --> " + value);
switch (key) {
case "title":
res.title = value.replace("'","''");
break;
case "subtitle":
res.subtitle = value.replace("'","''");
break;
case "demostart":
res.preview = value;
case "course":
const diff = value.toLowerCase();
if(diff in courseTypes){
courseName = courseTypes[diff];
}else{
courseName = diff;
}
break;
case "level":
res.difficulty[courseName] = value;
break;
const category_path = fpath + "/" + category;
//console.log("Reading: " + category_path);
const songs = await fs.promises.readdir(category_path);
for (let song_raw of songs) {
const song_id = parseInt(song_raw);
if (isNaN(song_id))
continue;
const tja_path = category_path + "/" + song_id + "/main.tja"
//console.log("Reading: " + tja_path);
const tja_buffer = await fs.promises.readFile(tja_path);
let md5 = crypto.createHash('md5');
md5.update(tja_buffer);
const tja_hash = md5.digest("base64").replace(/=/g, "");
const tja_text = iconv.decode(tja_buffer, "shift-jis")
//let buf = Buffer.from(tja_base64, "base64");
//let encoded_buf = convert(buf, "UTF-8", "SHIFT-JIS");
//const tja_text = encoded_buf.toString('utf8');
const tja_lines = tja_text.split("\n");
let res = {
title: null,
title_lang: {
ja: null,
en: null,
cn: null,
tw: null,
ko: null
},
subtitle: null,
subtitle_lang: {
ja: null,
en: null,
cn: null,
tw: null,
ko: null
},
courses: {
easy: null,
normal: null,
hard: null,
oni: null,
ura: null,
},
id: song_id,
category_id: category,
type: "tja",
enabled: true,
preview: null,
branch: {
easy: false,
normal: false,
hard: false,
oni: false,
ura: false,
},
hash: tja_hash
}
let courseName = "oni";
for (let line of tja_lines) {
const line_ = line.trim();
if (line_.indexOf(":") > 0) {
//const line__ = convert(line_, "UTF-8", "SHIFT-JIS").toString('utf8');
const temp = line_.split(":");
const key = temp[0].toLowerCase();
const value = temp[1];
//console.log("Find value: " + key +" --> " + value);
switch (key) {
case "title":
res.title = value.replace("'","''");
break;
case "subtitle":
res.subtitle = value.replace("'","''");
break;
case "demostart":
res.preview = value;
case "course":
const diff = value.toLowerCase();
if(diff in courseTypes){
courseName = courseTypes[diff];
}else{
courseName = diff;
}
break;
case "level":
res.courses[courseName] = value;
break;
}
} else if (line_.startsWith("#BRANCHSTART")) {
res.branch[courseName] = true;
}
} else if (line_.startsWith("#BRANCHSTART")) {
res.branch[courseName] = true;
}
}
for (var diff of ["easy", "normal", "hard", "oni", "ura"]) {
if (res.difficulty[diff]) {
if (res.branch[diff]) {
res.difficulty[diff] = "'" + res.difficulty[diff] + " B'";
} else {
res.difficulty[diff] = "'" + res.difficulty[diff] + "'";
for (let diff of ["easy", "normal", "hard", "oni", "ura"]) {
if (res.courses[diff]) {
if (res.branch[diff]) {
res.courses[diff] = "'" + res.courses[diff] + " B'";
} else {
res.courses[diff] = "'" + res.courses[diff] + "'";
}
}
}
all_songs.push(res);
}
all_songs.push(res);
}
}
for (var song of all_songs) {
console.log(get_sql(song));
}
main();
......@@ -8,6 +8,19 @@
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
"integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ="
},
"iconv-lite": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.2.tgz",
"integrity": "sha512-2y91h5OpQlolefMPmUlivelittSWy0rP+oYVpn6A7GwVHNE8AWzoYOBNmlwks3LobaJxgHCYZAnyNo2GgpNRNQ==",
"requires": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
}
},
"safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
}
}
}
#!/bin/bash
find . -name *.tja | sed "s/.tja//g" | xargs -I {} bash -c 'export DIR_NAME=$RANDOM ; mkdir $DIR_NAME ; cp -rf {}.tja $DIR_NAME/main.tja ; cp -rf {}.ogg $DIR_NAME/main.ogg'
find . -name '*.tja' | sed "s/.tja//g" | xargs -I {} bash -c 'export DIR_NAME=$RANDOM ; mkdir $DIR_NAME ; cp -rf "{}.tja" $DIR_NAME/main.tja ; cp -rf "{}.ogg" $DIR_NAME/main.ogg'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment