diff --git a/tja2fumen/tja2fumen.py b/tja2fumen/tja2fumen.py index ceacd99..5d8076f 100644 --- a/tja2fumen/tja2fumen.py +++ b/tja2fumen/tja2fumen.py @@ -6,31 +6,39 @@ from utils import checkMismatchedBytes tja2fumen_version = "v0.1" -if __name__ == "__main__": - # arguments = parser.parse_args() - arguments = { - "input_fumen": "test-data/ia6cho_m.bin", # NB: Contains only oni chart - "input_tja": "test-data/Rokuchounen to Ichiya Monogatari.tja", # NB: Contains 5 charts - } - # Parse fumen - inputFile = open(arguments["input_fumen"], "rb") - parsedSongFumen = readFumen(inputFile) +def main(fnameFumen=None, fnameTJA=None, validate=False): + if fnameFumen: + # Parse fumen + inputFile = open(fnameFumen, "rb") + parsedSongFumen = readFumen(inputFile) - # Steps to validate the `writeFumen` function to make sure it reproduces correct output - validate = False - if validate: - outputName = inputFile.name.split('.')[0] + "_rebuilt.bin" + # Steps to validate the `writeFumen` function to make sure it reproduces correct output + if validate: + outputName = inputFile.name.split('.')[0] + "_rebuilt.bin" + outputFile = open(outputName, "wb") + writeFumen(outputFile, parsedSongFumen) + # Read output file back in to validate that the rewritten song is a perfect match + print(False if checkMismatchedBytes(inputFile.name, outputFile.name) else True) + else: + parsedSongFumen = None + + if fnameTJA: + # Parse tja + inputFile = open(fnameTJA, "r", encoding="utf-8-sig") + parsedSongsTJA = parseTJA(inputFile) + + # Try converting the Oni TJA chart to match the Oni fumen + convertedTJA = convertTJAToFumen(parsedSongFumen, parsedSongsTJA['Oni']) + outputName = inputFile.name.split('.')[0] + ".bin" outputFile = open(outputName, "wb") - writeFumen(outputFile, parsedSongFumen) - # Read output file back in to validate that the rewritten song is a perfect match - print(False if checkMismatchedBytes(inputFile.name, outputFile.name) else True) + writeFumen(outputFile, convertedTJA) + else: + convertedTJA = None - # Parse tja - inputFile = open(arguments["input_tja"], "r", encoding="utf-8-sig") - parsedSongsTJA = parseTJA(inputFile) + return parsedSongFumen, convertedTJA - # Try converting the Oni TJA chart to match the Oni fumen - convertedTJA = convertTJAToFumen(parsedSongFumen, parsedSongsTJA['Oni']) - outputName = inputFile.name.split('.')[0] + ".bin" - outputFile = open(outputName, "wb") - writeFumen(outputFile, convertedTJA) + +if __name__ == "__main__": + fnameFumen = "test-data/ia6cho_m.bin" # NB: Contains only oni chart + fnameTJA = "test-data/Rokuchounen to Ichiya Monogatari.tja" # NB: Contains 5 charts + fumen, tja = main(fnameFumen, fnameTJA)