1
0
mirror of https://github.com/Escartem/AnimeWwise.git synced 2026-06-04 23:40:25 +08:00

add --ogg support

This commit is contained in:
Marcel
2024-01-20 19:50:52 +00:00
parent 9cdfc66426
commit 0b7abc36a7
2 changed files with 45 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
# AnimeWwise
Extract audio from .pck and .hdiff to mp3 including original filenames with this tool. It can in theory extract any pck or hdiff file from any game even though it was made for Genshin Impact. There are others tools that do the same but none of them were working so I just made my own.
Extract audio from .pck and .hdiff to mp3 or ogg including original filenames with this tool. It can in theory extract any pck or hdiff file from any game even though it was made for Genshin Impact. There are others tools that do the same but none of them were working so I just made my own.
⚠️ Only audio from genshin will be exported with original filenames, and the coverage is very low, don't except every file to have a name
@@ -10,7 +10,7 @@ Extract audio from .pck and .hdiff to mp3 including original filenames with this
2. Install dependencies -> `pip install -r requirements.txt`
3. Place all of your `.pck` files in the *audio* folder and `.pck.hdiff` in the *patch* folder
> ⚠️ If you want to extract an hdiff content, you must place the pck file with the *same name before patch* in the *audio* folder, pck's that do not have a corresponding hdiff file will be extracted normally, when they do have a corresponding hdiff file, *only the hdiff file content is extracted* and not the full pck
4. Start the program -> `python extract.py`
4. Start the program -> `python extract.py`. Parse `--ogg` to extract in ogg format instead of mp3
5. After finishing, everything will be in the *output* folder in the mp3 format (ogg may be added later)
---

View File

@@ -1,6 +1,5 @@
import os
import sys
import json
import mapper
import shutil
import filecmp
@@ -8,6 +7,7 @@ import wavescan
import subprocess
from halo import Halo
from progress.bar import PixelBar
import argparse
print("Setting up...")
@@ -29,6 +29,13 @@ skips = "000000000" # used for debugging
# 9 - temp clean up
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--ogg', action='store_true', help='Convert to .ogg instead of .mp3', default=False)
parse_args = parser.parse_args()
is_ogg = parse_args.ogg and True or False
print(is_ogg and "Converting to .ogg" or "Converting to .mp3")
# Initial cleanup
if os.path.exists("temp") and skips[8] != "1":
shutil.rmtree("temp")
@@ -46,7 +53,7 @@ def main():
hdiff_files = [f for f in os.listdir("audio") if f.endswith(".pck") and os.path.exists(f"patch/{f}.hdiff")]
alone_files = [f for f in os.listdir("audio") if f.endswith(".pck") and not os.path.exists(f"patch/{f}.hdiff")]
files = [*hdiff_files, *alone_files]
if len(files) == 0:
print("No files found !")
return
@@ -200,18 +207,24 @@ def main():
diff_length = wem_length - len(all_files)
if diff_length > 0:
print(f": Failed to extract {diff_length} files out of {wem_length} (probably no extractable content)")
print(
f": Failed to extract {diff_length} files out of {wem_length} (probably no extractable content)"
)
######################################
### 6 - Convert .wav files to .mp3 ###
######################################
#############################################
### 6 - Convert .wav files to .mp3 or ogg ###
#############################################
if skips[5] != "1":
curr += 1
# updates folders and progress bar
os.makedirs(path("temp/mp3"), exist_ok=True)
bar = PixelBar(f"[{curr}/{steps}] Converting to mp3 ", max=len(all_files), suffix='%(percent).1f%% - %(eta)ds left')
os.makedirs(path("temp/ogg" if is_ogg else "temp/mp3"), exist_ok=True)
bar = PixelBar(
f"[{curr}/{steps}] Converting to {'ogg' if is_ogg else 'mp3'} ",
max=len(all_files),
suffix="%(percent).1f%% - %(eta)ds left",
)
# update file list
all_files = [f"{f.split('.')[0]}.wav" for f in all_files]
@@ -223,10 +236,14 @@ def main():
"-i",
path(f"temp/wav/{file}"),
"-acodec",
"libmp3lame",
"libvorbis" if is_ogg else "libmp3lame",
"-b:a",
"192k",
path(f"temp/mp3/{file.split('.')[0]}.mp3"),
path(
f"temp/ogg/{file.split('.')[0]}.ogg"
if is_ogg
else f"temp/mp3/{file.split('.')[0]}.mp3"
),
]
call(args)
@@ -237,10 +254,20 @@ def main():
shutil.rmtree("temp/wav")
# update files list
all_files = [f"{f.split('.')[0]}.mp3" for f in all_files]
all_files = [
f"{f.split('.')[0]}.ogg" if is_ogg else f"{f.split('.')[0]}.mp3"
for f in all_files
]
if not alone:
new_files = [f"{f.split('.')[0]}.mp3" for f in new_files]
changed_files = [f"{f.split('.')[0]}.mp3" for f in changed_files]
new_files = [
f"{f.split('.')[0]}.ogg" if is_ogg else f"{f.split('.')[0]}.mp3"
for f in new_files
]
changed_files = [
f"{f.split('.')[0]}.ogg" if is_ogg else f"{f.split('.')[0]}.mp3"
for f in changed_files
]
#########################
### 7 - Map filenames ###
@@ -279,11 +306,11 @@ def main():
lang = key_data[1]
print(f"\n: {lang} detected")
dir_path = path(f"{base_path}/{key_data[0]}.mp3")
dir_path = path(f"{base_path}/{key_data[0]}.{('ogg' if is_ogg else 'mp3')}")
os.makedirs(os.path.dirname(dir_path), exist_ok=True)
shutil.copy(path(f"temp/mp3/{file}"), dir_path)
shutil.copy(path(f"temp/{'ogg' if is_ogg else 'mp3'}/{file}"), dir_path)
else:
shutil.copy(path(f"temp/mp3/{file}"), path(f"{base_path}/unmapped/{file}"))
shutil.copy(path(f"temp/{'ogg' if is_ogg else 'mp3'}/{file}"), path(f"{base_path}/unmapped/{file}"))
# stop spinner
spinner.stop()