|
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').replace('\r', '')
|
|
|
|
return _clearT
|
|
|
|
|
|
clearT = clearT()
|
|
|
|
|
|
|
|
a = get_all_files_in_directory(r'E:\tmp\白日梦的构想图_\scn', ext='.txt.json')
|
|
b = r'E:\tmp\白日梦的构想图_\txt'
|
|
|
|
|
|
|
|
sc = {}
|
|
|
|
_n = {
|
|
"母亲": "母亲",
|
|
"海斗": "海斗",
|
|
"????": "?",
|
|
"沙齐": "沙齐",
|
|
"工头": "工头",
|
|
"出云": "出云",
|
|
"游马": "游马",
|
|
"世凪": "世凪",
|
|
"母": "母",
|
|
"李": "李",
|
|
"海斗(影像)": "海斗/影像",
|
|
"入麻": "入麻",
|
|
"奥莉薇娅": "奥莉薇娅",
|
|
"辅助装置": "辅助装置",
|
|
"眠羊": "眠羊",
|
|
"梓姫": "梓姫",
|
|
"父亲": "父亲",
|
|
"斯宾瑟": "斯宾瑟",
|
|
"琪琪": "琪琪",
|
|
"凛": "凛",
|
|
"游马研研究员": "游马研研究员",
|
|
"???": "?",
|
|
"康奈": "康奈",
|
|
"祥子": "祥子",
|
|
"有岛": "有岛",
|
|
"上层研究员": "上层研究员",
|
|
"里樱": "里樱",
|
|
"?": "?",
|
|
"渡边": "渡边",
|
|
"女学生": "女学生",
|
|
"男学生": "男学生",
|
|
"字节组长": "字节组长",
|
|
"品尝大妈": "品尝大妈",
|
|
"无毛的叔叔": "无毛的叔叔",
|
|
"鱼店老板": "鱼店老板",
|
|
"??": "?",
|
|
"熟客1": "熟客1",
|
|
"威尔": "威尔",
|
|
"熟客2": "熟客2",
|
|
"爱德": "爱德",
|
|
"罗布": "罗布",
|
|
"街人": "街人",
|
|
"看守1": "看守1",
|
|
"看守2": "看守2",
|
|
"团体顾客": "团体顾客",
|
|
"托马斯": "托马斯",
|
|
"琪琪&托马斯": "琪琪&托马斯",
|
|
"马洛": "马洛",
|
|
"布&爱德": "布&爱德",
|
|
"听众1": "听众1",
|
|
"听众2": "听众2",
|
|
"琪琪&托马斯&威尔": "琪琪&托马斯&威尔",
|
|
"赫米娅": "赫米娅",
|
|
"拉山德": "拉山德",
|
|
"帕克": "帕克",
|
|
"海伦": "海伦",
|
|
"一同": "一同",
|
|
"观客1": "观客1",
|
|
"观客2": "观客2",
|
|
"观客1&观客2": "观客1&观客2",
|
|
"哈姆雷特": "哈姆雷特",
|
|
"警官": "警官",
|
|
"警长": "警长",
|
|
"看守": "看守",
|
|
"伊丽莎白女王": "伊丽莎白女王",
|
|
"全员": "全员",
|
|
"安奈": "安奈",
|
|
"梓姬&康奈": "梓姬&康奈",
|
|
"男老师": "男老师",
|
|
"梓姫&李": "梓姫&李",
|
|
"接待老伯": "接待老伯",
|
|
"李&梓姬": "李&梓姬",
|
|
"斯宾瑟岚山": "斯宾瑟岚山",
|
|
"工作人员们": "工作人员们"
|
|
}
|
|
|
|
|
|
import json
|
|
|
|
for path in a:
|
|
name = path[path.rindex('\\'):]
|
|
name = name[:2]
|
|
if name not in sc:
|
|
sc[name] = []
|
|
print(name)
|
|
|
|
|
|
with open(path, 'r', encoding='utf-8') as json_file:
|
|
data = json.load(json_file)
|
|
|
|
|
|
for texts in data['scenes']:
|
|
try:
|
|
for texts in texts['texts']:
|
|
|
|
n = texts[0]
|
|
if texts[1][0][0] is not None:
|
|
n = texts[1][0][0]
|
|
if n is None:
|
|
n = '旁白'
|
|
else:
|
|
if n in _n:
|
|
n = _n[n]
|
|
else:
|
|
_n[n] = clearT(n).replace('・', '&')
|
|
print(texts, n)
|
|
|
|
|
|
d = clearT(texts[1][0][1])
|
|
if d:
|
|
sc[name].append(n + ':' + d)
|
|
|
|
except KeyError:
|
|
if type(texts) is not dict:
|
|
print(texts)
|
|
|
|
|
|
|
|
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) |