mirror of
https://github.com/Escartem/AnimeWwise.git
synced 2026-06-05 07:50:23 +08:00
ability to extract to wem and wav
This commit is contained in:
5
app.py
5
app.py
@@ -119,7 +119,7 @@ class AnimeWwise(QMainWindow):
|
|||||||
def progressBarSlot(self, progress):
|
def progressBarSlot(self, progress):
|
||||||
if progress[0] == "total":
|
if progress[0] == "total":
|
||||||
self.totalProgress.setValue(progress[1])
|
self.totalProgress.setValue(progress[1])
|
||||||
elif progress[0] == "task":
|
elif progress[0] == "file":
|
||||||
self.fileProgress.setValue(progress[1])
|
self.fileProgress.setValue(progress[1])
|
||||||
|
|
||||||
@pyqtSlot(dict)
|
@pyqtSlot(dict)
|
||||||
@@ -144,6 +144,7 @@ class AnimeWwise(QMainWindow):
|
|||||||
self.tabs.setTabEnabled(2, True)
|
self.tabs.setTabEnabled(2, True)
|
||||||
self.tabs.setCurrentIndex(2)
|
self.tabs.setCurrentIndex(2)
|
||||||
print("Finished extracting everything !")
|
print("Finished extracting everything !")
|
||||||
|
os.startfile(self.folders["output"])
|
||||||
|
|
||||||
# page 1 - config
|
# page 1 - config
|
||||||
def loadFiles(self):
|
def loadFiles(self):
|
||||||
@@ -239,7 +240,7 @@ class AnimeWwise(QMainWindow):
|
|||||||
|
|
||||||
# yet another block of threading bs
|
# yet another block of threading bs
|
||||||
self.backgroundThread = QThread()
|
self.backgroundThread = QThread()
|
||||||
self.backgroundWorker = BackgroundWorker("extract", self.extract, {"input": self.folders["input"], "files": checked_items, "format": "wem", "output": self.folders["output"]})
|
self.backgroundWorker = BackgroundWorker("extract", self.extract, {"input": self.folders["input"], "files": checked_items, "format": self.outputFormat.currentText()[:3], "output": self.folders["output"]})
|
||||||
self.backgroundWorker.moveToThread(self.backgroundThread)
|
self.backgroundWorker.moveToThread(self.backgroundThread)
|
||||||
self.backgroundThread.started.connect(self.backgroundWorker.run)
|
self.backgroundThread.started.connect(self.backgroundWorker.run)
|
||||||
self.backgroundWorker.finished.connect(self.handleFinished)
|
self.backgroundWorker.finished.connect(self.handleFinished)
|
||||||
|
|||||||
63
extract.py
63
extract.py
@@ -368,27 +368,82 @@ class WwiseExtract:
|
|||||||
|
|
||||||
### extracting files ###
|
### extracting files ###
|
||||||
|
|
||||||
def extract_files(self, _input, files, output, format, progress):
|
def extract_files(self, _input, files, output, _format, progress):
|
||||||
|
temp_dir = tempfile.TemporaryDirectory()
|
||||||
|
|
||||||
|
# wem
|
||||||
|
if _format == "wem":
|
||||||
|
output_folder = output
|
||||||
|
else:
|
||||||
|
output_folder = os.path.join(temp_dir.name, "wem")
|
||||||
|
|
||||||
|
self.extract_wem(_input, files, output_folder, progress)
|
||||||
|
|
||||||
|
if _format == "wem":
|
||||||
|
temp_dir.cleanup()
|
||||||
|
return
|
||||||
|
|
||||||
|
# wav
|
||||||
|
new_input = output_folder
|
||||||
|
files = [os.path.join("/".join(file["path"]), file["name"]) for file in files]
|
||||||
|
|
||||||
|
if _format == "wav":
|
||||||
|
output_folder = output
|
||||||
|
else:
|
||||||
|
output_folder = os.path.join(temp_dir.name, "wav")
|
||||||
|
|
||||||
|
self.extract_wav(new_input, files, output_folder, progress)
|
||||||
|
|
||||||
|
if _format == "wav":
|
||||||
|
temp_dir.cleanup()
|
||||||
|
return
|
||||||
|
|
||||||
|
new_input = output_folder
|
||||||
|
# TODO: add mp3 and ogg
|
||||||
|
|
||||||
|
def extract_wem(self, _input, files, output, progress):
|
||||||
|
print(": Extracting audio as wem")
|
||||||
all_sources = list(set([e["source"] for e in files]))
|
all_sources = list(set([e["source"] for e in files]))
|
||||||
|
|
||||||
for source in all_sources:
|
for source in all_sources:
|
||||||
self.allocator.load_file(os.path.join(_input, source))
|
self.allocator.load_file(os.path.join(_input, source))
|
||||||
|
|
||||||
pos = 0
|
pos = 0
|
||||||
for file in files:
|
for file in files:
|
||||||
pos += 1
|
pos += 1
|
||||||
progress(["total", pos * 100 // len(files)])
|
progress(["file", pos * 100 // len(files)])
|
||||||
|
|
||||||
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 = os.path.join("/".join(file["path"]), file["name"])
|
||||||
fullpath = os.path.join(output, filepath)
|
fullpath = os.path.join(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:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
self.allocator.free_mem()
|
self.allocator.free_mem()
|
||||||
os.startfile(output)
|
|
||||||
|
def extract_wav(self, _input, files, output, progress):
|
||||||
|
print(": Converting audio to wav")
|
||||||
|
pos = 0
|
||||||
|
for file in files:
|
||||||
|
pos += 1
|
||||||
|
progress(["file", pos * 100 // len(files)])
|
||||||
|
|
||||||
|
filename = f'{os.path.basename(file).split(".")[0]}.wav'
|
||||||
|
filepath = os.path.join(output, os.path.dirname(file), filename)
|
||||||
|
os.makedirs(os.path.dirname(filepath), exist_ok=True)
|
||||||
|
|
||||||
|
args = [
|
||||||
|
path("tools/vgmstream/vgmstream-cli.exe"),
|
||||||
|
"-o",
|
||||||
|
filepath,
|
||||||
|
os.path.join(_input, file)
|
||||||
|
]
|
||||||
|
|
||||||
|
call(args)
|
||||||
|
|
||||||
### other ###
|
### other ###
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user