-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataset_Maker.py
40 lines (32 loc) · 1.63 KB
/
Dataset_Maker.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
import os, glob, re, json, sys, shutil
sys.path.append(".")
def process_folder(path, output_dir_path, searching_folder):
if os.path.isdir(path):
files = os.listdir(path)
json_files = [file for file in files if file.endswith('.json')]
for json_file in json_files:
process_file(os.path.join(path, json_file), output_dir_path, searching_folder)
print(f'processed {json_file}')
else:
print(f'{path} is not a directory')
def process_file(path, output_dir_path, searching_folder):
with open(path, 'r', encoding = 'utf-8') as f:
data = json.load(f)
for item in data:
output_dir_name = item['Name']
output_path = os.path.join(output_dir_path, output_dir_name)
os.makedirs(output_path, exist_ok = True)
searching_file_path = searching_folder + '\\' + item['File'].replace('/', '\\')
print(searching_file_path)
if os.path.exists(searching_file_path):
output_path = os.path.join(output_dir_path, item['Name'], item['File'].replace('/', '_'))
shutil.copy(searching_file_path, output_path)
lab_file_path = output_path.split('.')[0] + ".lab"
with open(lab_file_path, 'w', encoding = 'utf-8') as lab_file:
text = item['Text']
lab_file.write(text)
if __name__ == "__main__":
script_folder = r"D:\projects\python\Dataset_Maker_for_Galgames\[KEY]时廻者_LOOPERS\scripts_json"
search_folder = r"D:\temp\voice"
output_folder = "datasets"
process_folder(script_folder, output_folder, search_folder)