From 0b7abc36a758bb53cf491b24b605ff4a14fb0503 Mon Sep 17 00:00:00 2001 From: Marcel <65048232+dromzeh@users.noreply.github.com> Date: Sat, 20 Jan 2024 19:50:52 +0000 Subject: [PATCH 1/6] add --ogg support --- README.md | 4 ++-- extract.py | 59 +++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 02eb416..b15bb28 100644 --- a/README.md +++ b/README.md @@ -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) --- diff --git a/extract.py b/extract.py index 62d4cce..3dbec4d 100644 --- a/extract.py +++ b/extract.py @@ -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() From ffc6236dcad2fa73f07082a5dbd9243e436f8386 Mon Sep 17 00:00:00 2001 From: Marcel <65048232+dromzeh@users.noreply.github.com> Date: Sat, 20 Jan 2024 20:53:56 +0000 Subject: [PATCH 2/6] update readme with ogg support --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b15bb28..b867626 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ # AnimeWwise -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. +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 # Usage 1. Get the repo by [downloading it](https://github.com/Escartem/WwiseExtract/archive/refs/heads/master.zip) or cloning it (`git clone https://github.com/Escartem/WwiseExtract`) -> ℹ️ This project uses ffmpeg version *3.4.2* which is the latest under 50Mb. But it is also slower, if you want to slightly improve extraction speed, consider updating the ffmpeg binary to a [newer version](https://github.com/BtbN/FFmpeg-Builds/releases) +> ℹ️ This project uses ffmpeg version *3.4.2* which is the latest under 50MB. But it is also slower, if you want to slightly improve extraction speed, consider updating the ffmpeg binary to a [newer version](https://github.com/BtbN/FFmpeg-Builds/releases) 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`. 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) +4. Start the program -> `python extract.py`. Use the `--ogg` argument to extract in `.ogg` format instead of `.mp3` +5. After finishing, everything will be in the *output* folder in your chosen format --- From 6bb091f3150a0ea000a706e457c20ad67697a6c3 Mon Sep 17 00:00:00 2001 From: Marcel <65048232+dromzeh@users.noreply.github.com> Date: Sun, 21 Jan 2024 16:44:27 +0000 Subject: [PATCH 3/6] refactor to audio_format var --- extract.py | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/extract.py b/extract.py index 3dbec4d..836d3c8 100644 --- a/extract.py +++ b/extract.py @@ -34,7 +34,9 @@ def main(): 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") + + audio_format = 'ogg' if is_ogg else 'mp3' + print(f'Format: {audio_format}') # Initial cleanup if os.path.exists("temp") and skips[8] != "1": @@ -219,9 +221,9 @@ def main(): curr += 1 # updates folders and progress bar - os.makedirs(path("temp/ogg" if is_ogg else "temp/mp3"), exist_ok=True) + os.makedirs(path(f"temp/{audio_format}"), exist_ok=True) bar = PixelBar( - f"[{curr}/{steps}] Converting to {'ogg' if is_ogg else 'mp3'} ", + f"[{curr}/{steps}] Converting to {audio_format} ", max=len(all_files), suffix="%(percent).1f%% - %(eta)ds left", ) @@ -239,11 +241,7 @@ def main(): "libvorbis" if is_ogg else "libmp3lame", "-b:a", "192k", - path( - f"temp/ogg/{file.split('.')[0]}.ogg" - if is_ogg - else f"temp/mp3/{file.split('.')[0]}.mp3" - ), + path(f"temp/{audio_format}/{file.split('.')[0]}.{audio_format}"), ] call(args) @@ -254,20 +252,11 @@ def main(): shutil.rmtree("temp/wav") # update files list - all_files = [ - f"{f.split('.')[0]}.ogg" if is_ogg else f"{f.split('.')[0]}.mp3" - for f in all_files - ] + all_files = [f"{f.split('.')[0]}.{audio_format}" for f in all_files] if not alone: - 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 - ] + new_files = [f"{f.split('.')[0]}.{audio_format}" for f in new_files] + changed_files = [f"{f.split('.')[0]}.{audio_format}" for f in changed_files] ######################### ### 7 - Map filenames ### @@ -280,13 +269,10 @@ def main(): spinner.text = f"[{curr}/{steps}] Mapping names" spinner.start() - if alone: - os.makedirs(path(f"temp/map/unmapped"), exist_ok=True) - else: - if len(new_files) > 0: - os.makedirs(path(f"temp/map/new_files/unmapped"), exist_ok=True) - if len(changed_files) > 0: - os.makedirs(path(f"temp/map/changed_files/unmapped"), exist_ok=True) + os.makedirs(path(f"temp/map/unmapped"), exist_ok=True) + if not alone: + os.makedirs(path(f"temp/map/new_files/unmapped"), exist_ok=True) + os.makedirs(path(f"temp/map/changed_files/unmapped"), exist_ok=True) lang = None @@ -306,11 +292,11 @@ def main(): lang = key_data[1] print(f"\n: {lang} detected") - dir_path = path(f"{base_path}/{key_data[0]}.{('ogg' if is_ogg else 'mp3')}") + dir_path = path(f"{base_path}/{key_data[0]}.{audio_format}") os.makedirs(os.path.dirname(dir_path), exist_ok=True) - shutil.copy(path(f"temp/{'ogg' if is_ogg else 'mp3'}/{file}"), dir_path) + shutil.copy(path(f"temp/{audio_format}/{file}"), dir_path) else: - shutil.copy(path(f"temp/{'ogg' if is_ogg else 'mp3'}/{file}"), path(f"{base_path}/unmapped/{file}")) + shutil.copy(path(f"temp/{audio_format}/{file}"), path(f"{base_path}/unmapped/{file}")) # stop spinner spinner.stop() From a8f18f16a41001974441b66901212d03d4655c49 Mon Sep 17 00:00:00 2001 From: Escartem Date: Tue, 23 Jan 2024 11:27:02 +0100 Subject: [PATCH 4/6] use format arg instead --- extract.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/extract.py b/extract.py index 836d3c8..14adcf8 100644 --- a/extract.py +++ b/extract.py @@ -30,12 +30,14 @@ skips = "000000000" # used for debugging 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() + parser.add_argument("--format", nargs="?", type=str, default="mp3", help="Output audio format, can be either mp3 or ogg") + args = parser.parse_args() - is_ogg = parse_args.ogg and True or False + formats = ["mp3", "ogg"] + audio_format = "mp3" + if args.format in formats: + audio_format = args.format - audio_format = 'ogg' if is_ogg else 'mp3' print(f'Format: {audio_format}') # Initial cleanup @@ -209,9 +211,7 @@ 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 or ogg ### @@ -238,7 +238,7 @@ def main(): "-i", path(f"temp/wav/{file}"), "-acodec", - "libvorbis" if is_ogg else "libmp3lame", + "libvorbis" if audio_format == "ogg" else "libmp3lame", "-b:a", "192k", path(f"temp/{audio_format}/{file.split('.')[0]}.{audio_format}"), From 6258891ace518c3a3bfe1068351a951f0f42a68f Mon Sep 17 00:00:00 2001 From: Marcel <65048232+dromzeh@users.noreply.github.com> Date: Wed, 24 Jan 2024 05:48:28 +0000 Subject: [PATCH 5/6] update readme to reflect new CLI usage --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b867626..773685c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Extract audio from `.pck` and `.hdiff` to `.mp3` or `.ogg` including original fi 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`. Use the `--ogg` argument to extract in `.ogg` format instead of `.mp3` +4. Start the program -> `python extract.py`. Pass in `--format [args]` to change the audio output format, default is `mp3`, other possible value is `ogg`. 5. After finishing, everything will be in the *output* folder in your chosen format --- From a12587994799b1a893af998bb48f7b9e821a3d78 Mon Sep 17 00:00:00 2001 From: Marcel <65048232+dromzeh@users.noreply.github.com> Date: Wed, 24 Jan 2024 05:52:59 +0000 Subject: [PATCH 6/6] reword format usage --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 773685c..ce22550 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Extract audio from `.pck` and `.hdiff` to `.mp3` or `.ogg` including original fi 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`. Pass in `--format [args]` to change the audio output format, default is `mp3`, other possible value is `ogg`. +4. Start the program -> `python extract.py`. Pass in `--format [ogg|mp3]` to change the audio output format - if not specified, it will default to mp3. 5. After finishing, everything will be in the *output* folder in your chosen format ---