Datasets:

Languages:
Chinese
Tags:
Not-For-All-Audiences
License:
Limour commited on
Commit
183d326
·
verified ·
1 Parent(s): 082fae5

真恋~寄语枫秋~

Browse files
v-corpus-zh/SP-time/真恋~寄语枫秋~/0.txt.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1cd598a59e532191d1f3bb5566819fad9af24ae85fb7a159afc989cb7755684c
3
+ size 523187
v-corpus-zh/SP-time/真恋~寄语枫秋~/真恋~寄语枫秋~_ks.py ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def get_all_files_in_directory(directory, ext=''):
2
+ import os
3
+ import re
4
+ custom_sort_key_re = re.compile('([0-9]+)')
5
+
6
+ def custom_sort_key(s):
7
+ # 将字符串中的数字部分转换为整数,然后进行排序
8
+ return [int(x) if x.isdigit() else x for x in custom_sort_key_re.split(s)]
9
+
10
+ all_files = []
11
+ for root, dirs, files in os.walk(directory):
12
+ for file in files:
13
+ if file.endswith(ext):
14
+ file_path = os.path.join(root, file)
15
+ all_files.append(file_path)
16
+ return sorted(all_files, key=custom_sort_key)
17
+
18
+
19
+ def clearT():
20
+ import unicodedata
21
+ from opencc import OpenCC
22
+
23
+ def full2half(input_str):
24
+ return ''.join([unicodedata.normalize('NFKC', char) for char in input_str])
25
+
26
+ cc = OpenCC('t2s') # 't2s'表示繁体转简体
27
+
28
+ def _clearT(s):
29
+ s = cc.convert(full2half(s))
30
+ return s.strip().replace('\n', '\\n')
31
+
32
+ return _clearT
33
+
34
+
35
+ clearT = clearT()
36
+
37
+ # =================
38
+
39
+ a = get_all_files_in_directory(r'E:\tmp\真恋~寄语枫秋~_\ks\scenario', ext='.ks')
40
+ b = r'E:\tmp\真恋~寄语枫秋~_\text'
41
+
42
+ # =================
43
+
44
+ sc = {}
45
+
46
+ _n = {
47
+ "?": "?",
48
+ "我": "我",
49
+ "唐海音": "唐海音",
50
+ "妈妈": "妈妈",
51
+ "姚枫怡": "姚枫怡",
52
+ "郭恒逸": "郭恒逸",
53
+ "沈听涛": "沈听涛",
54
+ "老师": "老师",
55
+ "学生A": "学生A",
56
+ "姚枫茜": "姚枫茜",
57
+ "学生C": "学生C",
58
+ "学生D": "学生D",
59
+ "朱莉雅": "朱莉雅",
60
+ "云游少女": "云游少女",
61
+ "龙王": "龙王",
62
+ "庭雪": "庭雪",
63
+ "男子": "男子",
64
+ "主沐恩": "主沐恩",
65
+ "茶水保安": "茶水保安",
66
+ "学生": "学生",
67
+ "女子": "女子",
68
+ "女孩": "女孩",
69
+ "少女": "少女",
70
+ "早餐老板": "早餐老板",
71
+ "服务女仆": "服务女仆",
72
+ "木馨": "木馨",
73
+ "营业员": "营业员",
74
+ "归海枫": "归海枫",
75
+ "男生": "男生",
76
+ "亲卫队A": "亲卫队A",
77
+ "亲卫队C": "亲卫队C",
78
+ "亲卫队": "亲卫队",
79
+ "亲卫队B": "亲卫队B",
80
+ "女孩B": "女孩B",
81
+ "护士": "护士",
82
+ "医生": "医生",
83
+ "助手一": "助手一",
84
+ "众人": "众人",
85
+ "助一": "助一",
86
+ "亲卫队队长": "亲卫队队长",
87
+ "枫茜母": "枫茜母",
88
+ "班主任": "班主任",
89
+ "学生B": "学生B",
90
+ "众学生": "众学生",
91
+ "主持人": "主持人",
92
+ "观众": "观众",
93
+ "评委": "评委",
94
+ "评委A": "评委A",
95
+ "店长": "店长",
96
+ "阿姨": "阿姨",
97
+ "爸爸": "爸爸",
98
+ "喇叭": "喇叭",
99
+ "监考老师": "监考老师",
100
+ "同学A": "同学A",
101
+ "同学B": "同学B",
102
+ "同学C": "同学C",
103
+ "弹幕党": "弹幕党",
104
+ "校长": "校长",
105
+ "枫怡党": "枫怡党",
106
+ "枫茜党": "枫茜党",
107
+ "女生A": "女生A",
108
+ "同学": "同学",
109
+ "同学众": "众同学",
110
+ "橙香": "橙香",
111
+ "小明": "小明",
112
+ "老人": "老人",
113
+ "侄子": "侄子",
114
+ "乞丐": "乞丐",
115
+ "青年": "青年",
116
+ "男人": "男人"
117
+ }
118
+
119
+ # =================
120
+
121
+ import re
122
+
123
+ reg_removeWait = re.compile(r'\[.+?]')
124
+
125
+
126
+ def removeWait(_line):
127
+ _tmp = reg_removeWait.sub('', _line)
128
+ if _tmp:
129
+ return _tmp
130
+ else:
131
+ return _line
132
+
133
+
134
+ # =================
135
+
136
+ def startsWithAny(s: str, keys):
137
+ for x in keys:
138
+ if s.startswith(x):
139
+ return x
140
+ else:
141
+ return False
142
+
143
+
144
+ def indexWithAny(s: str, keys):
145
+ for x in keys:
146
+ if x in s:
147
+ idx = s.index(x)
148
+ return x, s[:idx], s[idx:]
149
+ else:
150
+ return False
151
+
152
+
153
+ def endsWithAny(s: str, keys):
154
+ for x in keys:
155
+ if s.endswith(x):
156
+ return x
157
+ else:
158
+ return False
159
+
160
+
161
+ def simpleSplit(_s: str, _sp, _st=0, _shift=True):
162
+ _idx = _s.index(_sp, _st)
163
+ if _shift:
164
+ return _s[:_idx], _s[_idx + len(_sp):]
165
+ else:
166
+ return _s[:_idx], _s[_idx:]
167
+
168
+
169
+ brackets = {'「': '」', '『': '』', '(': ')', '“': '”'} # , '【': '】'
170
+ brackets_r = {v: k for k, v in brackets.items()}
171
+
172
+ cache = []
173
+ cache_tmp = ''
174
+ cache_var_n = ''
175
+
176
+
177
+ def log_process(var_d: str):
178
+ global cache, cache_tmp, cache_var_n, _n
179
+ var_d = var_d.strip()
180
+ if var_d.startswith('【'):
181
+ var_n, var_d = simpleSplit(var_d, '】')
182
+ var_n = clearT(var_n[1:]).replace('???', '?')
183
+ if var_n in _n:
184
+ var_n = _n[var_n]
185
+ else:
186
+ _n[var_n] = clearT(var_n)
187
+ print(line)
188
+ var_d = var_d.strip()
189
+ if cache:
190
+ sp = cache_var_n + '<sp>:' + clearT(' '.join(cache)) + '\n' # 标记一下,后期手动处理
191
+ cache = []
192
+ else:
193
+ sp = ''
194
+
195
+ tmp = startsWithAny(var_d, brackets)
196
+ if tmp:
197
+ if var_d.endswith(brackets[tmp]):
198
+ return sp + var_n + ':' + clearT(var_d)
199
+ else:
200
+ cache.append(var_d)
201
+ cache_tmp = brackets[tmp]
202
+ cache_var_n = var_n
203
+ return sp.rstrip()
204
+ else:
205
+ return sp + var_n + '<sp>:' + clearT(var_d) # 标记一下,后期手动处理
206
+ else:
207
+ if cache:
208
+ cache.append(var_d)
209
+ if var_d.endswith(cache_tmp):
210
+ sp = cache_var_n + ':' + clearT(' '.join(cache))
211
+ cache = []
212
+ return sp
213
+ else:
214
+ return ''
215
+ else:
216
+ return '旁白:' + clearT(var_d)
217
+
218
+
219
+ # =================
220
+ for path in a:
221
+ name = path[path.rindex('\\'):]
222
+ print(name)
223
+ name = '0'
224
+ if name not in sc:
225
+ sc[name] = []
226
+ print(name)
227
+ # =================
228
+
229
+ with open(path, 'r', encoding='utf-16-le') as f:
230
+ data = list(x.rstrip() for x in f.readlines())
231
+ # print(data[0])
232
+ data = list(filter(lambda x: x and (not x.startswith(';')), data))
233
+
234
+ # =================
235
+ w_i = -1
236
+ while w_i < len(data) - 1:
237
+ w_i += 1
238
+ line: str = data[w_i]
239
+ # =================
240
+ if not line.endswith('[p]'):
241
+ continue
242
+ d = log_process(removeWait(line))
243
+ if d:
244
+ sc[name].append(d)
245
+
246
+ # =================
247
+
248
+ for k, v in sc.items():
249
+ if v:
250
+ with open(b + f'\\{k}.txt', 'w', encoding='utf-8') as f:
251
+ f.write('\n'.join(v))
252
+
253
+ # =================
254
+ import json
255
+ tmp = json.dumps(_n, ensure_ascii=False, indent=4)