1
0
mirror of synced 2024-11-27 22:40:49 +01:00

Move main() from main.py into __init__.py

This commit is contained in:
Viv 2023-06-04 12:31:42 -04:00
parent 90f3d7902f
commit 2bfa3e8d31
2 changed files with 40 additions and 48 deletions

View File

@ -0,0 +1,40 @@
import argparse
import os
from tja2fumen.parsers import parseTJA
from tja2fumen.writers import writeFumen
from tja2fumen.converters import convertTJAToFumen
from tja2fumen.constants import COURSE_IDS
def main():
parser = argparse.ArgumentParser(
description="tja2fumen"
)
parser.add_argument(
"file.tja",
help="Path to a Taiko no Tatsujin TJA file.",
)
args = parser.parse_args()
fnameTJA = getattr(args, "file.tja")
try:
inputFile = open(fnameTJA, "r", encoding="utf-8-sig")
parsedSongsTJA = parseTJA(inputFile)
except UnicodeDecodeError:
inputFile = open(fnameTJA, "r", encoding="shift-jis")
parsedSongsTJA = parseTJA(inputFile)
for course, song in parsedSongsTJA.items():
convertedTJA = convertTJAToFumen(song)
outputName = os.path.splitext(fnameTJA)[0]
if len(parsedSongsTJA) == 1:
outputName += ".bin"
else:
outputName += f"_{COURSE_IDS[course]}.bin"
outputFile = open(outputName, "wb")
writeFumen(outputFile, convertedTJA)
if __name__ == "__main__":
main()

View File

@ -1,48 +0,0 @@
import argparse
import os
from tja2fumen.parsers import parseTJA
from tja2fumen.writers import writeFumen
from tja2fumen.converters import convertTJAToFumen
from tja2fumen.constants import COURSE_IDS
tja2fumen_version = "v0.1"
def main(fnameTJA):
convertedTJAs = {}
try:
inputFile = open(fnameTJA, "r", encoding="utf-8-sig")
parsedSongsTJA = parseTJA(inputFile)
except UnicodeDecodeError:
inputFile = open(fnameTJA, "r", encoding="shift-jis")
parsedSongsTJA = parseTJA(inputFile)
for course, song in parsedSongsTJA.items():
convertedTJA = convertTJAToFumen(song)
convertedTJAs[course] = convertedTJA
return convertedTJAs
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="tja2fumen"
)
parser.add_argument(
"file.tja",
help="Path to a Taiko no Tatsujin TJA file.",
)
args = parser.parse_args()
fnameTJA = getattr(args, "file.tja")
fumen, convertedTJAs = main(fnameTJA=fnameTJA)
for course, song in convertedTJAs.items():
outputName = os.path.splitext(fnameTJA)[0]
if len(convertedTJAs) == 1:
outputName += ".bin"
else:
outputName += f"_{COURSE_IDS[course]}.bin"
outputFile = open(outputName, "wb")
writeFumen(outputFile, song)