mirror of
https://github.com/Escartem/AnimeWwise.git
synced 2026-06-04 23:40:25 +08:00
some refactoring
This commit is contained in:
28
extract.py
28
extract.py
@@ -8,7 +8,7 @@ from allocator import Allocator
|
|||||||
from filereader import FileReader
|
from filereader import FileReader
|
||||||
|
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
path = lambda path: os.path.join(cwd, path)
|
path = lambda base, path: os.path.join(base, path)
|
||||||
call = lambda args: subprocess.call(args, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
|
call = lambda args: subprocess.call(args, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
# TODO: handle hdiff, helper :
|
# TODO: handle hdiff, helper :
|
||||||
@@ -25,7 +25,7 @@ class WwiseExtract:
|
|||||||
def load_folder(self, _map, path):
|
def load_folder(self, _map, path):
|
||||||
self.mapper = None
|
self.mapper = None
|
||||||
if _map is not None:
|
if _map is not None:
|
||||||
self.mapper = Mapper(os.path.join(os.getcwd(), f"maps/{_map}"))
|
self.mapper = Mapper(path(cwd, f"maps/{_map}"))
|
||||||
self.file_structure = {"folders": {}, "files": []}
|
self.file_structure = {"folders": {}, "files": []}
|
||||||
|
|
||||||
files = [f for f in os.listdir(path) if f.endswith(".pck")]
|
files = [f for f in os.listdir(path) if f.endswith(".pck")]
|
||||||
@@ -99,7 +99,7 @@ class WwiseExtract:
|
|||||||
if _format == "wem":
|
if _format == "wem":
|
||||||
output_folder = output
|
output_folder = output
|
||||||
else:
|
else:
|
||||||
output_folder = os.path.join(temp_dir.name, "wem")
|
output_folder = path(temp_dir.name, "wem")
|
||||||
|
|
||||||
self.extract_wem(_input, files, output_folder)
|
self.extract_wem(_input, files, output_folder)
|
||||||
|
|
||||||
@@ -109,12 +109,12 @@ class WwiseExtract:
|
|||||||
|
|
||||||
# wav
|
# wav
|
||||||
new_input = output_folder
|
new_input = output_folder
|
||||||
files = [os.path.join("/".join(file["path"]), file["name"]) for file in files]
|
files = [path("/".join(file["path"]), file["name"]) for file in files]
|
||||||
|
|
||||||
if _format == "wav":
|
if _format == "wav":
|
||||||
output_folder = output
|
output_folder = output
|
||||||
else:
|
else:
|
||||||
output_folder = os.path.join(temp_dir.name, "wav")
|
output_folder = path(temp_dir.name, "wav")
|
||||||
|
|
||||||
self.extract_wav(new_input, files, output_folder)
|
self.extract_wav(new_input, files, output_folder)
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ class WwiseExtract:
|
|||||||
return
|
return
|
||||||
|
|
||||||
# mp3 & ogg
|
# mp3 & ogg
|
||||||
files = [os.path.join(os.path.dirname(file), f'{os.path.basename(file).split(".")[0]}.wav') for file in files]
|
files = [path(os.path.dirname(file), f'{os.path.basename(file).split(".")[0]}.wav') for file in files]
|
||||||
new_input = output_folder
|
new_input = output_folder
|
||||||
output_folder = output
|
output_folder = output
|
||||||
|
|
||||||
@@ -146,8 +146,8 @@ class WwiseExtract:
|
|||||||
|
|
||||||
data = self.allocator.read_at(file["source"], file["offset"], file["size"])
|
data = self.allocator.read_at(file["source"], file["offset"], file["size"])
|
||||||
|
|
||||||
filepath = os.path.join("/".join(file["path"]), file["name"])
|
filepath = path("/".join(file["path"]), file["name"])
|
||||||
fullpath = os.path.join(output, filepath)
|
fullpath = path(output, filepath)
|
||||||
os.makedirs(os.path.dirname(fullpath), exist_ok=True)
|
os.makedirs(os.path.dirname(fullpath), exist_ok=True)
|
||||||
|
|
||||||
with open(fullpath, "wb") as f:
|
with open(fullpath, "wb") as f:
|
||||||
@@ -164,14 +164,14 @@ class WwiseExtract:
|
|||||||
self.update_progress(pos, len(files), 2)
|
self.update_progress(pos, len(files), 2)
|
||||||
|
|
||||||
filename = f'{os.path.basename(file).split(".")[0]}.wav'
|
filename = f'{os.path.basename(file).split(".")[0]}.wav'
|
||||||
filepath = os.path.join(output, os.path.dirname(file), filename)
|
filepath = path(output, os.path.dirname(file), filename)
|
||||||
os.makedirs(os.path.dirname(filepath), exist_ok=True)
|
os.makedirs(os.path.dirname(filepath), exist_ok=True)
|
||||||
|
|
||||||
args = [
|
args = [
|
||||||
path("tools/vgmstream/vgmstream-cli.exe"),
|
path(cwd, "tools/vgmstream/vgmstream-cli.exe"),
|
||||||
"-o",
|
"-o",
|
||||||
filepath,
|
filepath,
|
||||||
os.path.join(_input, file)
|
path(_input, file)
|
||||||
]
|
]
|
||||||
|
|
||||||
call(args)
|
call(args)
|
||||||
@@ -192,13 +192,13 @@ class WwiseExtract:
|
|||||||
self.update_progress(pos, len(files), 3)
|
self.update_progress(pos, len(files), 3)
|
||||||
|
|
||||||
filename = f'{os.path.basename(file).split(".")[0]}.{_format}'
|
filename = f'{os.path.basename(file).split(".")[0]}.{_format}'
|
||||||
filepath = os.path.join(output, os.path.dirname(file), filename)
|
filepath = path(output, os.path.dirname(file), filename)
|
||||||
os.makedirs(os.path.dirname(filepath), exist_ok=True)
|
os.makedirs(os.path.dirname(filepath), exist_ok=True)
|
||||||
|
|
||||||
args = [
|
args = [
|
||||||
path("tools/ffmpeg/ffmpeg.exe"),
|
path(cwd, "tools/ffmpeg/ffmpeg.exe"),
|
||||||
"-i",
|
"-i",
|
||||||
os.path.join(_input, file),
|
path(_input, file),
|
||||||
"-acodec",
|
"-acodec",
|
||||||
encoder,
|
encoder,
|
||||||
"-b:a",
|
"-b:a",
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user