-
Notifications
You must be signed in to change notification settings - Fork 1
/
DBDAudioRenamer.py
272 lines (238 loc) · 8.41 KB
/
DBDAudioRenamer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
import os
import time
import shutil
import webbrowser
import subprocess
from datetime import datetime
from colorama import Fore
from utils.ui import UI, Style
from utils.config import config
from utils.clear import clear
# Set Directories
DIR_BNK = "Files/BNK"
DIR_WEM = "Files/WEM"
DIR_XML = "Files/XML"
DIR_OUTPUT = "Files/Output"
# Menu Welcome
def display_welcome_menu():
clear.screen()
UI.logo()
print("| Welcome to my tool used to extract, rename audio files and much more! What do you want to do?"),
while(True):
welcome_option = UI.menu(
"Choose an option:", [
("1", "Latest features"),
("2", "Start"),
("0", "Exit")
]
)
if welcome_option == 1:
open_browser()
elif welcome_option == 2:
display_main_menu()
elif welcome_option == 0:
exit_program()
elif welcome_option is None:
input("Invalid option. Please try again.")
display_welcome_menu()
# My Github (Updates)
def open_browser():
print("| The browser will open the latest patch notes for the tool!")
print("| Once you review them, press ENTER to start!")
patch_notes_url = f"https://github.com/{config.made}/{config.name}/releases"
webbrowser.open(patch_notes_url)
input()
display_main_menu()
# Main Menu
def display_main_menu():
clear.screen()
UI.logo()
while(True):
main_option = UI.menu(
"Choose an option:", [
("1", "Extract files"),
("2", "Rename audio files"),
("3", "Convert audio files"),
("4", "Clean unnecessary files"),
("0", "Exit")
]
)
if main_option == 1:
display_extract_menu()
elif main_option == 2:
rename_audio()
elif main_option == 3:
display_convert_menu()
elif main_option == 4:
display_clean_menu()
elif main_option == 0:
exit_program()
elif main_option is None:
input("Invalid option. Please try again.")
display_main_menu()
# Menu Extract
def display_extract_menu():
clear.screen()
UI.logo()
while True:
extract_option = UI.menu(
"Choose an option:", [
("1", "Audio files from .BNK"),
("2", "Return"),
("0", "Exit")
]
)
if extract_option == 1:
extract_bnk()
elif extract_option == 2:
display_main_menu()
elif extract_option == 0:
exit_program()
elif extract_option is None:
input("Invalid option. Please try again.")
display_extract_menu()
# Extract audio files from BNK
def extract_bnk():
print("| Audio files from BNK will be extracted. Press ENTER to start!")
input()
bnk_files = os.listdir(DIR_BNK)
for bnk_file in bnk_files:
if bnk_file.endswith(".bnk"):
print(f"Extracting audio from: {bnk_file}")
os.system(f"Tools\\bnkextr.exe \"{os.path.join(DIR_BNK, bnk_file)}\" /nodir >nul")
# Move the file only if a file with the same name does not exist in the destination directory
wem_file = os.path.join(DIR_WEM, bnk_file.replace(".bnk", ".wem"))
if not os.path.exists(wem_file):
os.system(f"move \"{os.path.join(DIR_BNK, '*.wem')}\" \"{DIR_WEM}\" >nul")
else:
print(f"Skipping file {bnk_file} as a .wem file with the same name already exists in the destination directory.")
else:
print("No .BNK files found in the directory.")
print("Done!")
input()
display_extract_menu()
# Rename audio files with a script
def rename_audio():
subprocess.run(["python", "Tools/scripts/renamer_parse.py"])
print()
print(f"Done! Audio files were renamed in {DIR_OUTPUT} folder.")
input()
display_main_menu()
# Menu convert audio files (OGG and more...)
def display_convert_menu():
clear.screen()
UI.logo()
while(True):
convert_option = UI.menu(
"Choose an option:", [
("1", "WEM to OGG - Normal"),
("2", "OGG to OGG - ReVorb"),
("3", "Return"),
("0", "Exit")
]
)
if convert_option == 1:
convert_wem_to_ogg()
elif convert_option == 2:
convert_ogg_with_revorb()
elif convert_option == 3:
display_main_menu()
elif convert_option == 0:
exit_program()
elif convert_option is None:
input("Invalid option. Please try again.")
display_convert_menu()
# Convert WEM audio files to OGG
def convert_wem_to_ogg():
print("| You will convert all WEM audio files to OGG. Press ENTER to start!")
input()
for root, _, files in os.walk(DIR_OUTPUT):
for file in files:
if file.endswith(".wem"):
wem_file = os.path.join(root, file)
print(f"Converting file: {file} to: OGG")
os.system(f"ww2ogg\ww2ogg.exe \"{wem_file}\" --pcb ww2ogg\packed_codebooks_aoTuV_603.bin >nul")
print()
print(f"Done! Audio files were converted in {DIR_OUTPUT} folder.")
input()
display_convert_menu()
# Convert OGG audio to OGG ReVorb
def convert_ogg_with_revorb():
print("| You will convert all OGG audio files to readable OGG. Press ENTER to start!")
input()
for root, _, files in os.walk(DIR_OUTPUT):
for file in files:
if file.endswith(".ogg"):
ogg_file = os.path.join(root, file)
print(f"Converting file: {file} to: OGG ReVorb")
os.system(f"Tools\\revorb.exe \"{ogg_file}\" >nul")
print()
print(f"Done! Audio files were converted in {DIR_OUTPUT} folder.")
input()
display_convert_menu()
# Menu clean files
def display_clean_menu():
clear.screen()
UI.logo()
while(True):
clean_option = UI.menu(
"Choose an option:", [
("1", "Show files to deleted"),
("2", "Clean files .WEM"),
("3", "Return"),
("0", "Exit")
]
)
if clean_option == 1:
show_unnecessary_files()
elif clean_option == 2:
clean_unnecessary_files()
elif clean_option == 3:
display_main_menu()
elif clean_option == 0:
exit_program()
elif clean_option is None:
input("Invalid option. Please try again.")
display_clean_menu()
# Show unnecessary files (WEM)
def show_unnecessary_files():
print("| Showing files to be deleted! Press ENTER to start!")
input()
files_found = False # Variable to track if files were found
for root, _, files in os.walk(DIR_OUTPUT):
for file in files:
if file.endswith(".wem"):
file_path = os.path.join(root, file)
creation_time = os.path.getctime(file_path)
formatted_time = datetime.fromtimestamp(creation_time).strftime("%d/%m/%Y")
print(f"{formatted_time} {os.path.splitext(file)[0]}{os.path.splitext(file)[1]}")
files_found = True # At least one file found
if not files_found:
print("No WEM files found.")
input()
else:
print()
input("Waiting!")
display_clean_menu()
# Clean unnecessary files (WEM)
def clean_unnecessary_files():
files_found = False # Variable to track if files were found
for root, _, files in os.walk(DIR_OUTPUT):
for file in files:
if file.endswith(".wem"):
file_path = os.path.join(root, file)
os.remove(file_path)
files_found = True # At least one file found
if files_found:
print("Done!")
else:
print("No WEM files found.")
input()
display_clean_menu()
# Close
def exit_program():
print("Exiting the tool")
input()
exit()
if __name__ == "__main__":
display_welcome_menu()