|
def get_all_files_in_directory(directory, ext=''):
|
|
import os
|
|
import re
|
|
custom_sort_key_re = re.compile('([0-9]+)')
|
|
|
|
def custom_sort_key(s):
|
|
|
|
return [int(x) if x.isdigit() else x for x in custom_sort_key_re.split(s)]
|
|
|
|
all_files = []
|
|
for root, dirs, files in os.walk(directory):
|
|
for file in files:
|
|
if file.endswith(ext):
|
|
file_path = os.path.join(root, file)
|
|
all_files.append(file_path)
|
|
return sorted(all_files, key=custom_sort_key)
|
|
|
|
|
|
def clearT():
|
|
import unicodedata
|
|
from opencc import OpenCC
|
|
|
|
def full2half(input_str):
|
|
return ''.join([unicodedata.normalize('NFKC', char) for char in input_str])
|
|
|
|
cc = OpenCC('t2s')
|
|
|
|
def _clearT(s):
|
|
s = cc.convert(full2half(s))
|
|
return s.strip().strip(r'\n').replace('\n', '\\n')
|
|
|
|
return _clearT
|
|
|
|
|
|
clearT = clearT()
|
|
|
|
|
|
def startsWithAny(s: str, keys):
|
|
for x in keys:
|
|
if s.startswith(x):
|
|
return x
|
|
else:
|
|
return False
|
|
|
|
|
|
def endsWithAny(s: str, keys):
|
|
for x in keys:
|
|
if s.endswith(x):
|
|
return x
|
|
else:
|
|
return False
|
|
|
|
|
|
def startsWithAlnum(s: str, _chrs):
|
|
retn = ''
|
|
for char in s:
|
|
if (char.isalnum()) or (char in _chrs):
|
|
retn += char
|
|
else:
|
|
break
|
|
return retn
|
|
|
|
|
|
def startsWithCmd(s: str, _chrs=None):
|
|
if _chrs is None:
|
|
_chrs = {'_', '@'}
|
|
cmd = startsWithAlnum(s, _chrs)
|
|
if cmd:
|
|
return s.startswith(cmd + ' ')
|
|
else:
|
|
return False
|
|
|
|
|
|
import re
|
|
|
|
reg_removeWait = re.compile(r'\[.+?]')
|
|
|
|
|
|
def removeWait(_line):
|
|
_tmp = reg_removeWait.sub('', _line)
|
|
if _tmp:
|
|
return _tmp
|
|
else:
|
|
return _line
|
|
|
|
|
|
def getCmdArgs(_cmd):
|
|
_args = ['']
|
|
_i = -1
|
|
_inQuota = ''
|
|
while _i < len(_cmd) - 1:
|
|
_i += 1
|
|
char = _cmd[_i]
|
|
if _inQuota:
|
|
_args[-1] += char
|
|
if char == _inQuota:
|
|
_inQuota = ''
|
|
elif char == '\\':
|
|
_i += 1
|
|
char = _cmd[_i]
|
|
_args[-1] += char
|
|
else:
|
|
pass
|
|
else:
|
|
if char == ' ':
|
|
_args.append('')
|
|
while _i < len(_cmd) - 1:
|
|
_i += 1
|
|
char = _cmd[_i]
|
|
if char != ' ':
|
|
_i -= 1
|
|
break
|
|
continue
|
|
elif char in {'"', "'"}:
|
|
_inQuota = char
|
|
else:
|
|
pass
|
|
_args[-1] += char
|
|
continue
|
|
return _args
|
|
|
|
|
|
def args2map(_args):
|
|
retn = {}
|
|
for _i in range(1, len(_args)):
|
|
_arg = _args[_i]
|
|
if '=' not in _arg:
|
|
if '=' in _arg:
|
|
_arg = _arg.replace('=', '=')
|
|
else:
|
|
continue
|
|
_idx = _arg.index('=')
|
|
_k = _arg[:_idx]
|
|
if '"' in _k or "'" in _k:
|
|
continue
|
|
_v = _arg[_idx + 1:]
|
|
if _v.startswith('"') or _v.startswith("'"):
|
|
_v = _v[1:len(_v) - 1]
|
|
retn[_k] = _v
|
|
return retn
|
|
|
|
|
|
|
|
|
|
a = get_all_files_in_directory(r'E:\tmp\富婆妹_\script', ext='.ast')
|
|
b = r'E:\tmp\富婆妹_\text'
|
|
|
|
|
|
|
|
sc = {}
|
|
|
|
_n = {
|
|
"旁白": "旁白",
|
|
"妃愛": "妃爱",
|
|
"智宏": "智宏",
|
|
"あすみ": "明日海",
|
|
"女性店員": "女性店员",
|
|
"里": "里",
|
|
"華乃": "华乃",
|
|
"詩桜": "诗樱",
|
|
"天梨": "天梨",
|
|
"鳴門": "鸣门",
|
|
"妄想パパ": "妄想爸爸",
|
|
"広夢": "广梦",
|
|
"偉い人": "伟大的人",
|
|
"莉々子": "莉莉子",
|
|
"資正": "资正",
|
|
"女子生徒A": "女子生徒A",
|
|
"女子生徒B": "女子生徒B",
|
|
"男子生徒A": "男子生徒A",
|
|
"男子生徒B": "男子生徒B",
|
|
"宅配員": "宅配员",
|
|
"店員A": "店员A",
|
|
"店員B": "店员B",
|
|
"マンションの住人A": "公寓的住户A",
|
|
"他校の女子生徒A": "其他学校女生A",
|
|
"他校の女子生徒B": "其他学校女生B",
|
|
"他校の男子生徒A": "其他学校男生A",
|
|
"他校の男子生徒B": "其他学校男生B",
|
|
"他校の女子生徒C": "其他学校女生C",
|
|
"妃愛のマネージャー": "妃爱的经纪人",
|
|
"サッカー部部長": "足球部部长",
|
|
"黒髪美人": "黒发美人",
|
|
"華道部部長": "花道部部长",
|
|
"華道部女子A": "花道部女子A",
|
|
"華道部女子B": "花道部女子B",
|
|
"3年生ギャルA": "3年生女生A",
|
|
"3年生ギャルB": "3年生女生B",
|
|
"2年生ギャルA": "2年生女生A",
|
|
"誰?": "?",
|
|
"客A": "客A",
|
|
"客B": "客B",
|
|
"カメコA": "カメコA",
|
|
"女将": "女将",
|
|
"リーダー": "领导",
|
|
"おばあちゃん": "奶奶",
|
|
"地元の消防団員": "本地消防员",
|
|
"釣り船屋": "钓鱼码头",
|
|
"陽キャA": "阳光A",
|
|
"陽キャB": "阳光B",
|
|
"白ギャル": "白辣妹",
|
|
"黒ギャル": "黒辣妹",
|
|
"男子生徒C": "男学生C",
|
|
"男子生徒D": "男学生D",
|
|
"イベント客": "客户",
|
|
"おばば": "大婶",
|
|
"1年生女子A": "1年级女生A",
|
|
"1年生女子B": "1年级女生B",
|
|
"1年生女子C": "1年级女生C",
|
|
"悠羽": "悠羽",
|
|
"願ギマル": "祈愿",
|
|
"3年生男子A": "3年级男生A",
|
|
"3年生男子B": "3年级男生B",
|
|
"3年生男子C": "3年级男生C",
|
|
"3年生男子D": "3年级男生D",
|
|
"選挙管理委員会": "选举管理委员会",
|
|
"おじいちゃん": "爷爷",
|
|
"地元の人A": "本地人A",
|
|
"地元の人B": "本地人B",
|
|
"地元の人C": "本地人C",
|
|
"看護師": "护士"
|
|
}
|
|
|
|
reg_ast = re.compile(r'^\[\d+]=\{')
|
|
reg_n = re.compile(r'^name=\{name="(.+?)"}?,')
|
|
reg_d = re.compile(r'^"(.+?)",')
|
|
|
|
for path in a:
|
|
name = path[path.rindex('\\'):]
|
|
name = name[:3]
|
|
if name not in sc:
|
|
sc[name] = []
|
|
print(name)
|
|
|
|
|
|
with open(path, 'r', encoding='utf-8') as f:
|
|
data = list(filter(lambda x: x,
|
|
(x.rstrip() for x in f.readlines())))
|
|
|
|
|
|
w_i = -1
|
|
while w_i < len(data) - 1:
|
|
w_i += 1
|
|
line: str = data[w_i]
|
|
|
|
tmp = reg_ast.match(line)
|
|
if tmp is None:
|
|
continue
|
|
n = '旁白'
|
|
while w_i < len(data) - 1:
|
|
w_i += 1
|
|
line: str = data[w_i]
|
|
tmp = reg_ast.match(line)
|
|
if tmp is not None:
|
|
w_i -= 1
|
|
break
|
|
tmp = reg_n.findall(line)
|
|
if tmp:
|
|
n = tmp[0]
|
|
continue
|
|
tmp = reg_d.findall(line)
|
|
if tmp:
|
|
d = tmp[0]
|
|
continue
|
|
|
|
if n in _n:
|
|
n = _n[n]
|
|
else:
|
|
_n[n] = clearT(n.strip('【】')).replace('/', '&')
|
|
print(line)
|
|
|
|
d = clearT(d)
|
|
if d:
|
|
sc[name].append(n + ':' + d)
|
|
|
|
|
|
|
|
for k, v in sc.items():
|
|
if v:
|
|
with open(b + f'\\{k}.txt', 'w', encoding='utf-8') as f:
|
|
f.write('\n'.join(v))
|
|
|
|
|
|
import json
|
|
|
|
tmp = json.dumps(_n, ensure_ascii=False, indent=4)
|
|
|