From cdfb6cc21f2ed6b526e60e45c014f1748342ef1c Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Sat, 3 Apr 2021 05:27:09 +0000 Subject: [PATCH] Allow loading/parsing AFP/BSI files extracted from IFS files. --- bemani/utils/afputils.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/bemani/utils/afputils.py b/bemani/utils/afputils.py index 80e7457..550a34d 100644 --- a/bemani/utils/afputils.py +++ b/bemani/utils/afputils.py @@ -8,7 +8,7 @@ import textwrap from PIL import Image, ImageDraw # type: ignore from typing import Any, Dict -from bemani.format.afp import AFPFile +from bemani.format.afp import AFPFile, SWF def main() -> int: @@ -100,6 +100,24 @@ def main() -> int: help="Display verbuse debugging output", ) + parse_parser = subparsers.add_parser('parse', help='Parse a raw AFP/BSI file pair from an IFS container') + parse_parser.add_argument( + "afp", + metavar="AFPFILE", + help="The AFP file to parse", + ) + parse_parser.add_argument( + "bsi", + metavar="BSIFILE", + help="The BSI file to parse", + ) + parse_parser.add_argument( + "-v", + "--verbose", + action="store_true", + help="Display verbuse debugging output", + ) + args = parser.parse_args() if args.action == "extract": @@ -313,6 +331,16 @@ def main() -> int: # Now, print it print(json.dumps(afpfile.as_dict(), sort_keys=True, indent=4)) + if args.action == "parse": + # First, load the AFP and BSI files + with open(args.afp, "rb") as bafp: + with open(args.bsi, "rb") as bbsi: + swf = SWF("", bafp.read(), bbsi.read()) + + # Now, print it + swf.parse(verbose=args.verbose) + print(json.dumps(swf.as_dict(), sort_keys=True, indent=4)) + return 0