-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_text.py
More file actions
76 lines (62 loc) · 3.44 KB
/
extract_text.py
File metadata and controls
76 lines (62 loc) · 3.44 KB
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
import os
def extract_quoted_text(line):
# Find the indices of the first and second quotation marks
first_quote_index = line.find('"')
second_quote_index = line.find('"', first_quote_index + 1)
if first_quote_index != -1 and second_quote_index != -1:
# Extract the text between the first and second quotation marks
return line[first_quote_index + 1:second_quote_index]
else:
return "" # Return empty string if no quoted text found
def find_path(file_path):
i = file_path.rfind(os.sep)
return file_path[:i]
def make_txt(file_path):
i = file_path.rfind(".")
return file_path[:i] + ".txt"
def combine_files(folder_path, output_folder, nojson=True):
# Iterate through all files and subdirectories in the specified folder
for root, _, files in os.walk(folder_path):
for file in files:
#print(root, file)
# Construct the full path to each file
file_path = os.path.join(root, file)
if (".aif" not in file_path and
".mid" not in file_path and
".pcm" not in file_path and
".gba" not in file_path and
".png" not in file_path and
".bin" not in file_path and
".json" not in file_path and nojson):
try:
# Open each file and read its content
with open(file_path, 'r', encoding='utf-8') as input_file:
#content = input_file.read()
content = [line.strip().lstrip('\t') for line in input_file.readlines()]
content = [f"{i + 1}: {line}" for i, line in enumerate(content) if
line and
"\"" in line and
line.strip() and
"INCBIN_U" not in line
and not line.startswith((".incbin", ".section", ".include", '#include', '@', "//"))
]
#content = [ line for line in content]
#content = [line for line in content if ]
# Write the content to the output file
if len(content) > 0:
try:
myfile_path = file_path[len(folder_path)+1:]
output_path = make_txt(os.path.join(output_folder, myfile_path))
if not os.path.exists(find_path(output_path)):
os.makedirs(find_path(output_path))
with open(output_path, 'w', encoding='utf-8') as output:
content = "\n".join(content)
output.write(content)
except Exception as e:
print(f"Error writing file {file_path}: {e}")
except Exception as e:
print(f"Error reading file {file_path}: {e}")
# I am pretty sure we only need the data/ and src/ folders, but you can extract also just extract everything
# 1. Download the Pokemon Emerald Decompilation Project
# 2. Replace the filepaths below
combine_files("..\\pokeemerald", "..\\pokeemerald-latin")