Commit 91a62fd6 authored by nanahira's avatar nanahira

rewrite for shiftjis

parent e3456226
const fs = require('fs'); const fs = require('fs');
const crypto = require('crypto'); const crypto = require('crypto');
//const sqlite3 = require('sqlite3').verbose(); //const sqlite3 = require('sqlite3').verbose();
//const iconv = require('iconv-lite'); const iconv = require('iconv-lite');
//const convert = require('encoding').convert //const convert = require('encoding').convert
const fpath = process.argv[2]; const fpath = process.argv[2];
var all_songs = []; let all_songs = [];
const courseTypes = { const courseTypes = {
"0": "easy", "0": "easy",
...@@ -17,102 +17,115 @@ const courseTypes = { ...@@ -17,102 +17,115 @@ const courseTypes = {
"edit": "ura" "edit": "ura"
} }
function get_sql(song) { async function main() {
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 + "');"; const category_array = await fs.promises.readdir(fpath);
}
//console.log("Reading: " + fpath);
const category_array = fs.readdirSync(fpath);
for (var category_raw of category_array) { for (let category_raw of category_array) {
const category = parseInt(category_raw); const category = parseInt(category_raw);
if (isNaN(category)) 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))
continue; continue;
const tja_path = category_path + "/" + song_id + "/main.tja" const category_path = fpath + "/" + category;
//console.log("Reading: " + tja_path); //console.log("Reading: " + category_path);
const tja_buffer = fs.readFileSync(tja_path); const songs = await fs.promises.readdir(category_path);
let md5 = crypto.createHash('md5'); for (let song_raw of songs) {
md5.update(tja_buffer); const song_id = parseInt(song_raw);
const tja_hash = md5.digest("base64").replace(/=/g, ""); if (isNaN(song_id))
const tja_text = tja_buffer.toString(); continue;
//var buf = Buffer.from(tja_base64, "base64"); const tja_path = category_path + "/" + song_id + "/main.tja"
//var encoded_buf = convert(buf, "UTF-8", "SHIFT-JIS"); //console.log("Reading: " + tja_path);
//const tja_text = encoded_buf.toString('utf8'); const tja_buffer = await fs.promises.readFile(tja_path);
const tja_lines = tja_text.split("\n"); let md5 = crypto.createHash('md5');
var res = { md5.update(tja_buffer);
difficulty: { const tja_hash = md5.digest("base64").replace(/=/g, "");
easy: null, const tja_text = iconv.decode(tja_buffer, "shift-jis")
normal: null, //let buf = Buffer.from(tja_base64, "base64");
hard: null, //let encoded_buf = convert(buf, "UTF-8", "SHIFT-JIS");
oni: null, //const tja_text = encoded_buf.toString('utf8');
ura: null, const tja_lines = tja_text.split("\n");
}, let res = {
song_id: song_id, title: null,
category: category, title_lang: {
preview: null, ja: null,
branch: { en: null,
easy: false, cn: null,
normal: false, tw: null,
hard: false, ko: null
oni: false, },
ura: false, subtitle: null,
}, subtitle_lang: {
hash: tja_hash ja: null,
} en: null,
var courseName = "oni"; cn: null,
for (var line of tja_lines) { tw: null,
const line_ = line.trim(); ko: null
if (line_.indexOf(":") > 0) { },
//const line__ = convert(line_, "UTF-8", "SHIFT-JIS").toString('utf8'); courses: {
const temp = line_.split(":"); easy: null,
const key = temp[0].toLowerCase(); normal: null,
const value = temp[1]; hard: null,
//console.log("Find value: " + key +" --> " + value); oni: null,
switch (key) { ura: null,
case "title": },
res.title = value.replace("'","''"); id: song_id,
break; category_id: category,
case "subtitle": type: "tja",
res.subtitle = value.replace("'","''"); enabled: true,
break; preview: null,
case "demostart": branch: {
res.preview = value; easy: false,
case "course": normal: false,
const diff = value.toLowerCase(); hard: false,
if(diff in courseTypes){ oni: false,
courseName = courseTypes[diff]; ura: false,
}else{ },
courseName = diff; hash: tja_hash
} }
break; let courseName = "oni";
case "level": for (let line of tja_lines) {
res.difficulty[courseName] = value; const line_ = line.trim();
break; 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 (let diff of ["easy", "normal", "hard", "oni", "ura"]) {
for (var diff of ["easy", "normal", "hard", "oni", "ura"]) { if (res.courses[diff]) {
if (res.difficulty[diff]) { if (res.branch[diff]) {
if (res.branch[diff]) { res.courses[diff] = "'" + res.courses[diff] + " B'";
res.difficulty[diff] = "'" + res.difficulty[diff] + " B'"; } else {
} else { res.courses[diff] = "'" + res.courses[diff] + "'";
res.difficulty[diff] = "'" + res.difficulty[diff] + "'"; }
} }
} }
all_songs.push(res);
} }
all_songs.push(res);
} }
} }
for (var song of all_songs) { main();
console.log(get_sql(song));
}
...@@ -8,6 +8,19 @@ ...@@ -8,6 +8,19 @@
"version": "0.0.1-security", "version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
"integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ=" "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=="
} }
} }
} }
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
}, },
"homepage": "https://github.com/purerosefallen/taiko-db-writer#readme", "homepage": "https://github.com/purerosefallen/taiko-db-writer#readme",
"dependencies": { "dependencies": {
"fs": "0.0.1-security" "fs": "0.0.1-security",
"iconv-lite": "^0.6.2"
} }
} }
#!/bin/bash #!/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