ported update_bgm to python

This commit is contained in:
argoneus 2020-04-23 21:44:50 +02:00 committed by Gitea
parent 560e00764b
commit ddca11509b
2 changed files with 53 additions and 15 deletions

View file

@ -74,7 +74,7 @@ class adx_file(object):
self.encrypted = self.get_val(CRYPT_OFF, CRYPT_LEN)
self.d_offset = self.get_val(DATA_OFF_OFF, DATA_OFF_LEN)
if self.d_offset < DATA_OFF_MIN:
return None
return
self.l_exists = 1
# now load things for math
self.sam_rate = self.get_val(SRATE_OFF, SRATE_LEN)
@ -106,13 +106,11 @@ class adx_file(object):
return None
if self.l_start > self.sam_count or self.l_end > self.sam_count:
raise ValueError("Invalid Loop Data")
return None
if self.l_style not in LOOP_TYPE_SUP:
raise NotImplementedError(
"Loop Style {} Not Implemented".format(str(self.l_style))
)
return None
ret = {}
ret = dict()
ret["duration"] = self.sam_count / self.sam_rate
ret["loop_start"] = {}
ret["loop_start"]["seconds"] = self.l_start / self.sam_rate
@ -123,7 +121,5 @@ class adx_file(object):
ret["loop_end"] = {}
ret["loop_end"]["seconds"] = self.l_end / self.sam_rate
ret["loop_end"]["samples_native"] = self.l_end
ret["loop_end"]["samples_48k"] = dumb_round(
self.l_end / self.sam_rate * 48000
)
ret["loop_end"]["samples_48k"] = dumb_round(self.l_end / self.sam_rate * 48000)
return ret

View file

@ -7,6 +7,8 @@ from contextlib import contextmanager
from distutils.dir_util import copy_tree
from glob import glob
from adx import extract_loop_data_from_dir
OPERATING_SYSTEM = os.name
@ -35,10 +37,7 @@ def process_se(cache_dir, extract_dir, update_dir):
run_program(acb_files, cmd=acb_cmd)
hca_files = [
file
for file in glob(
"{}/{}*/**/*.hca".format(from_dir, acb_prefix), recursive=True
)
file for file in glob("{}/**/*.hca".format(from_dir), recursive=True)
]
run_program(hca_files, cmd="clHCA")
@ -85,10 +84,53 @@ def process_bgm(cache_dir, extract_dir, update_dir):
os.path.join(cache_dir, "Android/Asset/Sound/Bgm"),
os.path.join(extract_dir, "Bgm"),
)
subprocess.run(os.path.join("TODO", "update_bgm.zsh"), shell=True, cwd=extract_dir)
copy_tree(
os.path.join(extract_dir, "bgm_extracted"), os.path.join(update_dir, "Bgm")
)
from_dir = "Bgm"
to_dir = "Bgm_Extracted"
loop_file = "loop.json"
pool = get_pool()
with change_cwd(extract_dir):
os.makedirs(to_dir, exist_ok=True)
to_del = glob("{}/**/*.adx".format(from_dir), recursive=True)
for file in to_del:
os.remove(file)
acb_files = [file for file in glob("{}/*.acb".format(from_dir))]
acb_cmd = get_dotnet_cmd("acb_extract.exe")
run_program(acb_files, cmd=acb_cmd)
adx_files = [
file for file in glob("{}/**/*.adx".format(from_dir), recursive=True)
]
partial_ffmpeg_cmd = functools.partial(run_program, cmd="ffmpeg")
wav_cmds = [
[
"-i",
os.path.abspath(file),
"-acodec",
"libopus",
"-ab",
"192k",
"-af",
"aresample=48000",
os.path.abspath(
"{}/{}.opus".format(
to_dir, os.path.splitext(os.path.basename(file))[0],
)
),
"-n",
]
for file in adx_files
]
pool.map(partial_ffmpeg_cmd, wav_cmds)
extract_loop_data_from_dir(from_dir, loop_file)
shutil.copy2(loop_file, os.path.join(to_dir, "BgmLoop.json"))
copy_tree(os.path.join(extract_dir, to_dir), os.path.join(update_dir, "Bgm"))
def process_voice(cache_dir, extract_dir, update_dir):