-
Notifications
You must be signed in to change notification settings - Fork 2
/
4_Sorting.py
128 lines (109 loc) · 3.95 KB
/
4_Sorting.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
import json
import re
import os
import argparse
from tqdm import tqdm
from pathlib import Path
from glob import glob
from shutil import copy, move
from pathlib import Path
parser = argparse.ArgumentParser()
parser.add_argument('-src','--source', type=str, help='未整理数据集目录', default="./Data/named")
parser.add_argument('-ver','--version', type=str, help='版本', required=True)
parser.add_argument('-dst','--destination', type=str, help='目标路径', default="./Data/sorted")
parser.add_argument('-lang','--language', type=str, help='语言(可选CHS/EN/JP/KR)', required=True)
parser.add_argument('-m','--mode', type=str, help='模式(复制(cp)/移动(mv))', default="cp")
args = parser.parse_args()
source = str(args.source)
dest = str(args.destination)
language = str(args.language).upper()
ver = str(args.version)
mode = str(args.mode)
player = '旅行者|旅人|Traveler|여행자'
def is_in(full_path, regx):
if re.findall(regx, full_path):
return True
else:
return False
def is_file(full_path):
if os.path.exists(full_path):
return True
else:
return False
def get_support_ver():
indexs = glob('./Indexs/*')
support_vers = []
for vers in indexs:
version = os.path.basename(vers)
support_vers.append(version)
versions = '|'.join(support_vers)
return versions
def get_support_lang(version):
if is_in(version, get_support_ver()):
support_langs = []
indexs = glob(f'./Indexs/{version}/*')
for langs in indexs:
lang_code = os.path.basename(langs).replace(
"_output.json", "").replace(".json", "")
support_langs.append(lang_code)
return support_langs
else:
print("不支持的版本")
exit()
def get_path_by_lang(lang):
langcodes = get_support_lang(ver)
path = ['中文 - Chinese', '英语 - English', '日语 - Japanese', '韩语 - Korean']
try:
i = langcodes.index(lang)
dest_path = path[i]
lang_code = lang
except:
print("不支持的语言")
exit()
return lang_code, dest_path
langcode, dest_lang = get_path_by_lang(language)
def ren_player(player, lang):
langcodes = get_support_lang(ver)
player_boy_names = ['空', 'Aether', '空', '아이테르']
player_girl_names = ['荧', 'Lumine', '蛍', '루미네']
p_name = player
if p_name == "PlayerBoy" or p_name == "PlayerGirl":
if p_name == "PlayerBoy":
i = langcodes.index(lang)
p_name = player_boy_names[i]
if p_name == "PlayerGirl":
i = langcodes.index(lang)
p_name = player_girl_names[i]
else:
p_name = player
return p_name
indexfile = Path(f'./Indexs/{ver}/{langcode}.json').read_text(encoding="utf-8")
data = json.loads(indexfile)
for k in tqdm(data.keys()):
try:
text = data.get(k).get('voiceContent')
char_name = data.get(k).get('talkName')
avatar_name = data.get(k).get('avatarName')
if char_name is not None:
if is_in(char_name, player) == True:
char_name = ren_player(avatar_name, langcode)
path = data.get(k).get('sourceFileName')
path = path.replace(".wem", ".wav")
wav_source = f"{source}/{dest_lang}/{path}"
wav_file = os.path.basename(path)
if char_name is not None:
vo_dest_dir = f"{dest}/{dest_lang}/{char_name}"
vo_wav_path = f"{vo_dest_dir}/{wav_file}"
if is_file(wav_source) == True:
if not os.path.exists(vo_dest_dir):
Path(f"{vo_dest_dir}").mkdir(parents=True)
dest_path = vo_wav_path
if mode.upper() == 'CP':
copy(wav_source, dest_path)
elif mode.upper() == 'MV':
move(wav_source, dest_path)
else:
print("模式错误,请选择cp/mv")
exit()
except:
pass