mirror of
https://github.com/Escartem/AnimeWwise.git
synced 2026-06-10 03:28:21 +08:00
name mapping (WIP) + some debug utils
This commit is contained in:
131
extract.py
131
extract.py
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
import zipfile
|
import zipfile
|
||||||
import filecmp
|
import filecmp
|
||||||
@@ -13,10 +14,21 @@ cwd = os.getcwd()
|
|||||||
path = lambda path: os.path.join(cwd, path)
|
path = lambda path: os.path.join(cwd, 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)
|
||||||
spinner = Halo(text="spinner", spinner={'interval': 100, 'frames': ['◜', '◠', '◝', '◞', '◡', '◟']}, placement="right")
|
spinner = Halo(text="spinner", spinner={'interval': 100, 'frames': ['◜', '◠', '◝', '◞', '◡', '◟']}, placement="right")
|
||||||
|
skips = "000111111" # used for debugging
|
||||||
|
|
||||||
|
# 1 - original extract
|
||||||
|
# 2 - patch
|
||||||
|
# 3 - patch extract
|
||||||
|
# 4 - filter files
|
||||||
|
# 5 - wem to wav
|
||||||
|
# 6 - wav to mp3
|
||||||
|
# 7 - map names
|
||||||
|
# 8 - clean up
|
||||||
|
# 9 - temp clean up
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Initial cleanup
|
# Initial cleanup
|
||||||
if os.path.exists("temp"):
|
if os.path.exists("temp") and skips[8] != "1":
|
||||||
shutil.rmtree("temp")
|
shutil.rmtree("temp")
|
||||||
|
|
||||||
if os.path.exists("output") and len(os.listdir("output")) > 0:
|
if os.path.exists("output") and len(os.listdir("output")) > 0:
|
||||||
@@ -48,14 +60,15 @@ def main():
|
|||||||
filename = f"{file.split('.')[0]}.hdiff.pck"
|
filename = f"{file.split('.')[0]}.hdiff.pck"
|
||||||
print(f"--- {filename} ({iteration}/{len(files)}) ---")
|
print(f"--- {filename} ({iteration}/{len(files)}) ---")
|
||||||
|
|
||||||
alone, steps, curr = False, 7, 1
|
alone, steps, curr = False, 8, 1
|
||||||
if file in alone_files:
|
if file in alone_files:
|
||||||
alone, steps = True, 4
|
alone, steps = True, 5
|
||||||
|
|
||||||
######################################
|
######################################
|
||||||
### 1 - Extract original .pck file ###
|
### 1 - Extract original .pck file ###
|
||||||
######################################
|
######################################
|
||||||
|
|
||||||
|
if skips[0] != "1":
|
||||||
# update files
|
# update files
|
||||||
if os.path.exists("temp"):
|
if os.path.exists("temp"):
|
||||||
shutil.rmtree("temp")
|
shutil.rmtree("temp")
|
||||||
@@ -80,6 +93,7 @@ def main():
|
|||||||
### 2 - Patch the .pck with .hdiff ###
|
### 2 - Patch the .pck with .hdiff ###
|
||||||
######################################
|
######################################
|
||||||
|
|
||||||
|
if skips[1] != "1":
|
||||||
if not alone:
|
if not alone:
|
||||||
curr += 1
|
curr += 1
|
||||||
|
|
||||||
@@ -107,6 +121,7 @@ def main():
|
|||||||
### 3 - Extract patched .pck file ###
|
### 3 - Extract patched .pck file ###
|
||||||
#####################################
|
#####################################
|
||||||
|
|
||||||
|
if skips[2] != "1":
|
||||||
if not alone:
|
if not alone:
|
||||||
curr += 1
|
curr += 1
|
||||||
|
|
||||||
@@ -126,6 +141,7 @@ def main():
|
|||||||
### 4 - Search new/changed files ###
|
### 4 - Search new/changed files ###
|
||||||
####################################
|
####################################
|
||||||
|
|
||||||
|
if skips[3] != "1":
|
||||||
if not alone:
|
if not alone:
|
||||||
curr += 1
|
curr += 1
|
||||||
|
|
||||||
@@ -155,6 +171,7 @@ def main():
|
|||||||
### 5 - Convert .wem files to .wav ###
|
### 5 - Convert .wem files to .wav ###
|
||||||
######################################
|
######################################
|
||||||
|
|
||||||
|
if skips[4] != "1":
|
||||||
curr += 1
|
curr += 1
|
||||||
|
|
||||||
# updates folders and progress bar
|
# updates folders and progress bar
|
||||||
@@ -181,6 +198,7 @@ def main():
|
|||||||
### 6 - Convert .wav files to .mp3 ###
|
### 6 - Convert .wav files to .mp3 ###
|
||||||
######################################
|
######################################
|
||||||
|
|
||||||
|
if skips[5] != "1":
|
||||||
curr += 1
|
curr += 1
|
||||||
|
|
||||||
# updates folders and progress bar
|
# updates folders and progress bar
|
||||||
@@ -210,10 +228,76 @@ def main():
|
|||||||
# cleanup
|
# cleanup
|
||||||
shutil.rmtree("temp/wav")
|
shutil.rmtree("temp/wav")
|
||||||
|
|
||||||
|
# update files list
|
||||||
|
all_files = [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]
|
||||||
|
|
||||||
|
# todo: something is wrong here with extraction of hdiff, it's missing files and not extracting everything ?
|
||||||
|
# print(all_files)
|
||||||
|
# print(new_files)
|
||||||
|
# print(changed_files)
|
||||||
|
|
||||||
|
#########################
|
||||||
|
### 7 - Map filenames ###
|
||||||
|
#########################
|
||||||
|
|
||||||
|
if skips[6] != "1":
|
||||||
|
curr += 1
|
||||||
|
|
||||||
|
# update spinner
|
||||||
|
spinner.text = f"[{curr}/{steps}] Mapping names"
|
||||||
|
spinner.start()
|
||||||
|
|
||||||
|
languages = ["english", "japanese", "chinese", "korean"]
|
||||||
|
mapFiles = [f"{path('mapping/mapping')}{f.capitalize()}.json" for f in languages]
|
||||||
|
namesTable = []
|
||||||
|
|
||||||
|
for language in mapFiles:
|
||||||
|
with open(language, "r") as f:
|
||||||
|
namesTable.append(json.loads(f.read()))
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
lang = None
|
||||||
|
for file in all_files:
|
||||||
|
for language in namesTable:
|
||||||
|
if lang is None or namesTable.index(language) == lang:
|
||||||
|
file_name = file.split(".")[0]
|
||||||
|
base_path = "temp/map"
|
||||||
|
if not alone:
|
||||||
|
if file in new_files:
|
||||||
|
base_path = "temp/map/new_files"
|
||||||
|
elif file in changed_files:
|
||||||
|
base_path = "temp/map/changed_files"
|
||||||
|
|
||||||
|
if file_name in language:
|
||||||
|
# lang detected, stick to it
|
||||||
|
lang = namesTable.index(language)
|
||||||
|
|
||||||
|
dir_path = path(f"{base_path}/{language[file_name]['path']}/{language[file_name]['name']}.mp3")
|
||||||
|
os.makedirs(os.path.dirname(dir_path), exist_ok=True)
|
||||||
|
shutil.copy(path(f"temp/mp3/{file}"), dir_path)
|
||||||
|
else:
|
||||||
|
shutil.copy(path(f"temp/mp3/{file}"), path(f"{base_path}/unmapped/{file}"))
|
||||||
|
|
||||||
|
# stop spinner
|
||||||
|
spinner.stop()
|
||||||
|
print(f"[{curr}/{steps}] Mapping names")
|
||||||
|
|
||||||
######################################################
|
######################################################
|
||||||
### 7 - Clean everything and move result to output ###
|
### 8 - Clean everything and move result to output ###
|
||||||
######################################################
|
######################################################
|
||||||
|
|
||||||
|
if skips[7] != "1":
|
||||||
curr += 1
|
curr += 1
|
||||||
|
|
||||||
# update spinner
|
# update spinner
|
||||||
@@ -222,48 +306,19 @@ def main():
|
|||||||
|
|
||||||
filename = filename.split('.')[0]
|
filename = filename.split('.')[0]
|
||||||
|
|
||||||
if not alone:
|
os.rename("temp/map", f"temp/{filename}")
|
||||||
# update files list
|
shutil.move(f"temp/{filename}", f"output/{filename}")
|
||||||
new_files = [f"{f.split('.')[0]}.mp3" for f in new_files]
|
|
||||||
changed_files = [f"{f.split('.')[0]}.mp3" for f in changed_files]
|
|
||||||
|
|
||||||
# prepare folders
|
|
||||||
os.makedirs(path(f"output/{filename}"), exist_ok=True)
|
|
||||||
if len(new_files) > 0:
|
|
||||||
os.makedirs(path("temp/new_files"), exist_ok=True)
|
|
||||||
if len(changed_files) > 0:
|
|
||||||
os.makedirs(path("temp/changed_files"), exist_ok=True)
|
|
||||||
|
|
||||||
# split files into corresponding folder
|
|
||||||
for file in new_files:
|
|
||||||
shutil.move(f"temp/mp3/{file}", f"temp/new_files/{file}")
|
|
||||||
|
|
||||||
for file in changed_files:
|
|
||||||
shutil.move(f"temp/mp3/{file}", f"temp/changed_files/{file}")
|
|
||||||
|
|
||||||
# move them to output
|
|
||||||
final_path = f"output/{filename}"
|
|
||||||
if len(new_files) > 0:
|
|
||||||
shutil.move("temp/new_files", f"{final_path}/new_files")
|
|
||||||
if len(changed_files) > 0:
|
|
||||||
shutil.move("temp/changed_files", f"{final_path}/changed_files")
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
shutil.rmtree("temp/mp3")
|
|
||||||
else:
|
|
||||||
# for no hdiff files
|
|
||||||
os.makedirs(path(f"output/{filename} (no hdiff)"), exist_ok=True)
|
|
||||||
shutil.move("temp/mp3", f"output/{filename} (no hdiff)")
|
|
||||||
|
|
||||||
|
|
||||||
|
# todo: final cleanup, will get deleted anyway after so idk yet
|
||||||
spinner.stop()
|
spinner.stop()
|
||||||
print(f"[{curr}/{steps}] Cleaning up")
|
print(f"[{curr}/{steps}] Cleaning up")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("An error occured while processing this file ! Skipping to the next one, details of the error bellow :")
|
print("An error occured while processing this file ! Skipping to the next one, details of the error bellow :")
|
||||||
print(f"Line {sys.exc_info()[-1].tb_lineno}, {e}")
|
print(f"Line {sys.exc_info()[-1].tb_lineno}, {e}")
|
||||||
|
|
||||||
# all files processed
|
# all files processed
|
||||||
if os.path.exists("temp"):
|
if os.path.exists("temp") and skips[8] != "1":
|
||||||
shutil.rmtree("temp")
|
shutil.rmtree("temp")
|
||||||
print("Done extracting everything !")
|
print("Done extracting everything !")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user