BLACKED
This commit is contained in:
parent
03e51318b0
commit
b6c3c6a454
10 changed files with 819 additions and 654 deletions
69
adx/adx.py
69
adx/adx.py
|
|
@ -5,43 +5,46 @@ import traceback
|
|||
|
||||
from .adx_parser import adx_file
|
||||
|
||||
|
||||
def extract_loop_data_from_dir(dir_in, fout):
|
||||
if fout is None:
|
||||
fout = "BgmLoop.json"
|
||||
files = glob.glob(os.path.join(dir_in, "**/*.adx"), recursive=True)
|
||||
if len(files) == 0:
|
||||
raise FileNotFoundError("No valid files found in directory: " + dir_in)
|
||||
extract_loop_data_from_files(files, fout)
|
||||
if fout is None:
|
||||
fout = "BgmLoop.json"
|
||||
files = glob.glob(os.path.join(dir_in, "**/*.adx"), recursive=True)
|
||||
if len(files) == 0:
|
||||
raise FileNotFoundError("No valid files found in directory: " + dir_in)
|
||||
extract_loop_data_from_files(files, fout)
|
||||
|
||||
|
||||
def extract_loop_data_from_files(files_in, fout):
|
||||
if not files_in:
|
||||
raise FileNotFoundError("No input files found")
|
||||
collect = {}
|
||||
for x in files_in:
|
||||
res = extract_loop_data_from_file(x)
|
||||
if res is not None:
|
||||
collect[os.path.splitext(os.path.basename(x))[0]] = res
|
||||
with open(fout, 'w') as out:
|
||||
json.dump(collect, out, ensure_ascii=False, indent="\t", sort_keys=True)
|
||||
if not files_in:
|
||||
raise FileNotFoundError("No input files found")
|
||||
collect = {}
|
||||
for x in files_in:
|
||||
res = extract_loop_data_from_file(x)
|
||||
if res is not None:
|
||||
collect[os.path.splitext(os.path.basename(x))[0]] = res
|
||||
with open(fout, "w") as out:
|
||||
json.dump(collect, out, ensure_ascii=False, indent="\t", sort_keys=True)
|
||||
|
||||
|
||||
def extract_loop_data_from_file(file_in, fout=None):
|
||||
if not file_in.endswith(".adx"):
|
||||
raise ValueError("Input file not .adx")
|
||||
if not file_in.endswith(".adx"):
|
||||
raise ValueError("Input file not .adx")
|
||||
|
||||
try:
|
||||
with open(file_in, 'rb') as x:
|
||||
data = x.read(64)
|
||||
ADX = adx_file(data)
|
||||
if ADX.l_exists and ADX.is_valid:
|
||||
res = ADX.parse_loop_data()
|
||||
else:
|
||||
res = None
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
print("Error processing file: " + file_in)
|
||||
return None
|
||||
try:
|
||||
with open(file_in, "rb") as x:
|
||||
data = x.read(64)
|
||||
ADX = adx_file(data)
|
||||
if ADX.l_exists and ADX.is_valid:
|
||||
res = ADX.parse_loop_data()
|
||||
else:
|
||||
res = None
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
print("Error processing file: " + file_in)
|
||||
return None
|
||||
|
||||
if fout is not None and res is not None:
|
||||
with open(fout, 'w') as out:
|
||||
json.dump(res, out, ensure_ascii=False, indent="\t", sort_keys=True)
|
||||
return res
|
||||
if fout is not None and res is not None:
|
||||
with open(fout, "w") as out:
|
||||
json.dump(res, out, ensure_ascii=False, indent="\t", sort_keys=True)
|
||||
return res
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue