This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
extract.py
41 lines (33 loc) · 1.49 KB
/
extract.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
# This is the extraction script for Nintendo Switch translation files, written by bandithedoge for the switch-pl project. It saves about 10-20 minutes of otherwise incredibly tedious work involving manually moving 20+ files to a bunch of different directories.
import os
import re
import libyaz0
key_file = "~/.switch/prod.keys"
hactool = "hactool -k " + key_file + " --disablekeywarns "
folders = {
"nca": "nca/",
"nsp": "nsp/",
"romfs": "romfs/",
"msbt": "msbt/",
"message": "romfs/message/EUen/"
}
for folder in folders:
if not os.path.exists(folders[folder]):
os.makedirs(folders[folder])
nsp_command = hactool + "--intype=pfs0 --pfs0dir=" + folders["nca"] + " -x "
nca_command = hactool + "--romfsdir=" + folders["romfs"] + " "
for title in os.listdir(folders["nsp"]):
print("\nExtracting " + title)
os.system(nsp_command + folders["nsp"] + title + "/00")
for nca in os.listdir(folders["nca"]):
print("\n Extracting " + nca)
os.system(nca_command + folders["nca"] + nca)
for msbt in os.listdir(folders["message"]):
if msbt.endswith(".szs") or msbt.endswith(".msbt"):
msbt_name = re.sub("\.szs$", "", msbt)
with open(folders["message"] + msbt, "rb") as input, open(folders["msbt"] + msbt_name, "wb") as output:
if msbt.endswith(".szs"):
decompressed = libyaz0.decompress(input.read())
else:
decompressed = input.read()
output.write(decompressed)