2021-03-19 15:01:16 +00:00
|
|
|
import { spawnSync } from "child_process";
|
2021-02-20 03:14:48 +00:00
|
|
|
import { tmpdir } from "os";
|
2021-03-07 16:10:41 +00:00
|
|
|
import { mkdtempSync, rmSync, mkdirSync } from "fs";
|
2021-06-05 11:21:04 +00:00
|
|
|
import { join, resolve } from "path";
|
2021-03-07 16:10:41 +00:00
|
|
|
import { extract_video, extract_audio } from "./extract_media.mjs";
|
2021-03-06 21:48:01 +00:00
|
|
|
import { extract_voice } from "./extract_voice.mjs";
|
2021-06-05 11:21:04 +00:00
|
|
|
import { extract_lapks } from "./extract_lapks.mjs";
|
2021-03-07 16:10:41 +00:00
|
|
|
import yargs from "yargs";
|
|
|
|
import { hideBin } from "yargs/helpers";
|
2021-06-05 14:01:05 +00:00
|
|
|
import {extract_site_images} from "./extract_site_images.mjs";
|
2021-02-20 03:14:48 +00:00
|
|
|
|
2021-03-07 16:10:41 +00:00
|
|
|
const argv = yargs(hideBin(process.argv))
|
|
|
|
.option("tempdir", {
|
|
|
|
type: "string",
|
|
|
|
description: "Path to a temporary directory",
|
|
|
|
default: mkdtempSync(join(tmpdir(), "extractor-")),
|
|
|
|
})
|
|
|
|
.option("no_index", {
|
|
|
|
type: "boolean",
|
|
|
|
description:
|
|
|
|
"Don't generate an index file for each disc, the index files MUST exist already",
|
|
|
|
})
|
|
|
|
.option("no_video", {
|
|
|
|
type: "boolean",
|
|
|
|
description: "Don't extract video",
|
|
|
|
})
|
|
|
|
.option("no_audio", {
|
|
|
|
type: "boolean",
|
|
|
|
description: "Don't extract audio",
|
|
|
|
})
|
|
|
|
.option("no_voice", {
|
|
|
|
type: "boolean",
|
|
|
|
description: "Don't extract voice.bin",
|
|
|
|
})
|
|
|
|
.option("no_delete", {
|
|
|
|
type: "boolean",
|
|
|
|
description:
|
2021-03-19 15:01:16 +00:00
|
|
|
"Don't delete any temporary files or directories, useful when using --tempdir (WARNING: uses 6+ GB of space)",
|
2021-03-07 16:10:41 +00:00
|
|
|
})
|
2021-06-05 11:21:04 +00:00
|
|
|
.option("no_lapks", {
|
2021-03-07 16:10:41 +00:00
|
|
|
type: "boolean",
|
2021-06-05 11:21:04 +00:00
|
|
|
description: "Don't extract lapks.bin",
|
2021-06-05 14:01:05 +00:00
|
|
|
})
|
|
|
|
.option("no_site_images", {
|
|
|
|
type: "boolean",
|
|
|
|
description: "Don't extract sitea.bin or siteb.bin",
|
2021-03-07 16:10:41 +00:00
|
|
|
}).argv;
|
|
|
|
|
|
|
|
mkdirSync(argv.tempdir, { recursive: true });
|
2021-02-20 03:14:48 +00:00
|
|
|
|
2021-06-05 11:21:04 +00:00
|
|
|
const jpsxdec_jar = resolve(join("jpsxdec", "jpsxdec.jar"));
|
2021-02-20 03:14:48 +00:00
|
|
|
|
|
|
|
// generate disc indexes
|
2021-03-07 16:10:41 +00:00
|
|
|
if (!argv.no_index) {
|
2021-03-19 15:01:16 +00:00
|
|
|
for (const disc of ["disc1", "disc2"]) {
|
|
|
|
spawnSync(
|
|
|
|
"java",
|
|
|
|
[
|
|
|
|
"-jar",
|
|
|
|
jpsxdec_jar,
|
|
|
|
"-f",
|
|
|
|
join("discs", disc + ".bin"),
|
|
|
|
"-x",
|
|
|
|
join(argv.tempdir, disc + ".idx"),
|
|
|
|
],
|
|
|
|
{ stdio: "inherit" }
|
|
|
|
);
|
|
|
|
}
|
2021-03-07 16:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!argv.no_video) {
|
2021-03-19 15:01:16 +00:00
|
|
|
extract_video(argv.tempdir, jpsxdec_jar, argv.no_delete);
|
2021-03-07 16:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!argv.no_audio) {
|
2021-03-19 15:01:16 +00:00
|
|
|
extract_audio(argv.tempdir, jpsxdec_jar, argv.no_delete);
|
2021-03-07 16:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!argv.no_voice) {
|
2021-03-19 15:01:16 +00:00
|
|
|
extract_voice(argv.tempdir, jpsxdec_jar);
|
2021-03-07 16:10:41 +00:00
|
|
|
}
|
|
|
|
|
2021-06-05 11:21:04 +00:00
|
|
|
if (!argv.no_lapks) {
|
|
|
|
extract_lapks(argv.tempdir, jpsxdec_jar);
|
|
|
|
}
|
|
|
|
|
2021-06-05 14:01:05 +00:00
|
|
|
if (!argv.no_site_images) {
|
|
|
|
extract_site_images(argv.tempdir, jpsxdec_jar);
|
|
|
|
}
|
|
|
|
|
2021-03-07 16:10:41 +00:00
|
|
|
if (!argv.no_delete) {
|
|
|
|
rmSync(argv.tempdir, { recursive: true });
|
|
|
|
}
|