Datasets:

Languages:
Chinese
Tags:
Not-For-All-Audiences
License:
File size: 9,195 Bytes
820104d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
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')  # 't2s'表示繁体转简体

    def _clearT(s):
        s = cc.convert(full2half(s))
        return s.lstrip('n').strip().strip(r'\n').replace('\n', '\\n')

    return _clearT


clearT = clearT()

# =================

a = get_all_files_in_directory(r'E:\tmp\haruno\scenario', ext='.ks')
b = r'D:\datasets\tmp'

# =================

sc = {}

_n = {
  "心の声": "旁白",
  "晴真": "晴真",
  "菜乃花": "菜乃花",
  "???《彩菜》": "?/彩菜",
  "クラスメイトの女子A": "同班女生A",
  "クラスメイトの女子B": "同班女生B",
  "晴真&菜乃花《菜乃花》": "晴真&菜乃花",
  "潤": "润",
  "祐希": "祐希",
  "玲於奈": "玲于奈",
  "花梨": "花梨",
  "雨音": "雨音",
  "花梨&祐希": "花梨&祐希",
  "このみ": "木乃实",
  "晴真の母親": "晴真母亲",
  "???": "???",
  "菜乃花&玲於奈": "菜乃花&玲于奈",
  "心の声《花梨》": "旁白/花梨",
  "女生徒B《花梨の同級生B》": "女学生B/与花梨同年级",
  "女生徒A《花梨の同級生A》": "女学生A/与花梨同年级",
  "花梨&祐希&玲於奈": "花梨&祐希&玲于奈",
  "???《潤》": "?/润",
  "???《菜乃花》": "?/菜乃花",
  "小さな女の子《菜乃花》": "小女孩/菜乃花",
  "菜乃花《菜乃花&彩菜》": "菜乃花/菜乃花&彩菜",
  "心の声《玲於奈》": "旁白/玲于奈",
  "心の声《彩菜》": "旁白/彩菜",
  "彩菜": "彩菜",
  "???《玲於奈》": "?/玲于奈",
  "母親らしき女性": "像母亲的女人",
  "男性": "男性",
  "迷子の少女": "迷路的少女",
  "花売りの少女《時雨》": "卖花的少女/时雨",
  "時雨": "时雨",
  "彩菜《菜乃花》": "彩菜/菜乃花",
  "花梨&玲於奈&祐希": "花梨&玲于奈&祐希",
  "真澄": "真澄",
  "晴乃": "晴乃",
  "???《このみ》": "?/木乃实",
  "???《時雨》": "?/时雨",
  "彩菜《晴乃》": "彩菜/晴乃",
  "???《雨音》": "?/雨音",
  "晴真&彩菜&潤《彩菜&潤》": "晴真&彩菜&润/彩菜&润",
  "晴真&彩菜&このみ《彩菜&このみ》": "晴真&彩菜&木乃实/彩菜&木乃实",
  "晴真&彩菜《彩菜》": "晴真&彩菜/彩菜",
  "心の声《このみ》": "旁白/木乃实",
  "全員《花梨&雨音&玲於奈&祐希》": "全员/花梨&雨音&玲于奈&祐希",
  "ジュンニーナ:潤《潤》": "Junnina:润",
  "アーヤ:花梨《花梨》": "Arya:花梨",
  "コノリーン:このみ《このみ》": "Conolene:木乃实",
  "王様:祐希《祐希》": "国王:祐希",
  "エレオナ:玲於奈《玲於奈》": "Eleona:玲于奈",
  "王子様:晴真": "王子:晴真",
  "女生徒《ソフト部部長》": "女学生/软件部部长",
  "女の子《あんず》": "女子/杏铃",
  "あんず": "杏铃",
  "晴真&花梨《花梨》": "晴真&花梨/花梨",
  "晴真&あんず《あんず》": "晴真&杏铃/杏铃",
  "???《祐希》": "?/祐希",
  "???《ソフト部部長》": "?/软件部部长",
  "ソフト部部長": "软件部部长",
  "みんな《菜乃花&祐希》": "大家/菜乃花&祐希",
  "雨音&玲於奈": "雨音&玲于奈",
  "みんな《菜乃花&花梨&雨音&玲於奈&祐希》": "大家/菜乃花&花梨&雨音&玲于奈&祐希",
  "みんな《菜乃花&雨音&玲於奈&祐希》": "大家/菜乃花&雨音&玲于奈&祐希",
  "みんな《菜乃花&雨音&玲於奈》": "大家/菜乃花&雨音&玲于奈",
  "晴真&祐希《祐希》": "晴真&祐希/祐希",
  "みんな《このみ&玲於奈&祐希》": "大家/木乃实&玲于奈&祐希",
  "ソフト部員A": "软件部员A",
  "ソフト部員B": "软件部员B",
  "ソフト部員C": "软件部员C",
  "みんな《雨音&玲於奈&祐希》": "大家/雨音&玲于奈&祐希",
  "このみ&雨音": "木乃实&雨音",
  "晴真&雨音《雨音》": "晴真&雨音/雨音",
  "男の子1": "男子1",
  "男の子2": "男子2",
  "男の子3": "男子3",
  "先生": "先生",
  "アナウンス": "广播",
  "女の人《時雨》": "女人/时雨",
  "???《死者を送る者》": "?/送死人的人",
  "村人1": "村人1",
  "村人2": "村人2",
  "村人3": "村人3",
  "村長": "村长",
  "桜木": "桜木",
  "妄想このみ《このみ》": "妄想木乃实/木乃实",
  "???《花梨》": "?/花梨",
  "女子生徒《花梨》": "女学生/花梨",
  "男子生徒《祐希》": "男学生/祐希》",
  "女子生徒&男子生徒《花梨&祐希》": "女学生&男学生/花梨&祐希",
  "晴真&女子生徒&男子生徒《花梨&祐希》": "晴真&女学生&男学生/花梨&祐希",
  "???《真澄》": "?/真澄",
  "晴真&このみ《このみ》": "晴真&木乃实/木乃实",
  "このみ&潤": "木乃实&润",
  "担任の先生": "班主任",
  "菜乃花&花梨&祐希": "菜乃花&花梨&祐希",
  "女子店員A": "女店员A",
  "女子店員B": "女店员B",
  "菜乃花&花梨": "菜乃花&花梨",
  "晴真&菜乃花&花梨&祐希《菜乃花&花梨&祐希》": "晴真&菜乃花&花梨&祐希/菜乃花&花梨&祐希",
  "晴真&花梨&祐希《花梨&祐希》": "晴真&花梨&祐希/花梨&祐希",
  "晴真&雨音&祐希《雨音&祐希》": "晴真&雨音&祐希/雨音&祐希",
  "ファンの男性A": "男粉丝A",
  "マネージャーさん": "经理",
  "ファンの男性B": "男粉丝B",
  "菜乃花&このみ": "菜乃花&木乃实",
  "チャラそうな金髪": "蓬松的金发",
  "チャラそうな鼻ピアス": "可爱的鼻环",  # ?
  "ガタイがいいボス": "体格健壮的老板",
  "野球少年A": "野球少年A",
  "野球少年B": "野球少年B",
  "菜乃花&潤": "菜乃花&润",
  "一同《菜乃花&花梨&雨音&玲於奈&祐希》": "一同/菜乃花&花梨&雨音&玲于奈&祐希",
  "心の声《菜乃花》": "旁白/菜乃花",
  "氷雨": "冰雨",  # 雨音线,时雨妹妹,雨音前世
  "時雨&氷雨": "时雨&冰雨"
}

# =================
import re
reg_n = re.compile(r'\[Talk( [^] ]+?)? name=([^] ]+?)]')
reg_macCmd = re.compile(r'\[macCmd num=(\d) text=([^] ]+?)]')
# =================
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 f:
        data = f.readlines()

    # =================
    macCmd = []
    Hitret = True
    for i,line in enumerate(data):
        line = line.strip()
        if line.startswith('[Hitret]'):
            Hitret = True
            continue
        if 'exp="f.selans' in line:

            try:
                d = '选择:' + macCmd.pop()
                sc[name].append('旁白' + ':' + d)
                # print(d, line)
            except IndexError as e:
                if name == r'\@':  # 懒得解析了,硬编码一下
                    break
                else:
                    raise e
        else:
            if line.startswith('[if'):
                continue
        if line.startswith(';'):
            continue
        if line.isascii():
            continue
        tmp = reg_macCmd.findall(line)
        if len(tmp) == 1:
            macCmd = [tmp[0][1]] + macCmd
            # print(macCmd)
            continue
        if line.startswith('[mac'):
            continue
        n = reg_n.findall(line)
        # print(n)
        if len(n) == 1:
            n = n[0][1]
            if n in _n:
                n = _n[n]
            else:
                _n[n] = clearT(n)
                print(line)
            Hitret = False
            nn = n
            continue
        else:
            if Hitret:
                nn = '旁白'
            if line.startswith('['):
                print(line)
            else:
                Hitret = False
        if not Hitret:
            d = clearT(line)
            sc[name].append(nn + ':' + d)
    assert not macCmd

# =================

for k, v in sc.items():
    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=2)