2019-12-08 22:43:49 +01:00
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
|
|
|
|
from bemani.format import ARC
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
|
|
|
parser = argparse.ArgumentParser(description="A utility to extract ARC files.")
|
|
|
|
parser.add_argument(
|
|
|
|
"file",
|
|
|
|
help="ARC file to extract.",
|
|
|
|
type=str,
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-d",
|
|
|
|
"--directory",
|
|
|
|
help="Directory to extract to. Defaults to current directory.",
|
2022-10-15 20:56:30 +02:00
|
|
|
default=".",
|
2019-12-08 22:43:49 +01:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-l",
|
|
|
|
"--list-only",
|
|
|
|
action="store_true",
|
|
|
|
help="Print files but do not extract them.",
|
|
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
root = args.directory
|
2022-10-15 20:56:30 +02:00
|
|
|
if root[-1] != "/":
|
|
|
|
root = root + "/"
|
2019-12-08 22:43:49 +01:00
|
|
|
root = os.path.realpath(root)
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
rfp = open(args.file, "rb")
|
2022-03-18 05:32:04 +01:00
|
|
|
data = rfp.read()
|
|
|
|
rfp.close()
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
arc = ARC(data)
|
|
|
|
for fn in arc.filenames:
|
|
|
|
if args.list_only:
|
|
|
|
print(fn)
|
|
|
|
else:
|
2022-10-15 20:56:30 +02:00
|
|
|
print(f"Extracting {fn} to disk...")
|
2019-12-08 22:43:49 +01:00
|
|
|
realfn = os.path.join(root, fn)
|
|
|
|
dirof = os.path.dirname(realfn)
|
|
|
|
os.makedirs(dirof, exist_ok=True)
|
2022-10-15 20:56:30 +02:00
|
|
|
with open(realfn, "wb") as wfp:
|
2022-03-18 05:32:04 +01:00
|
|
|
wfp.write(arc.read_file(fn))
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
if __name__ == "__main__":
|
2019-12-08 22:43:49 +01:00
|
|
|
main()
|