Datasets:

Languages:
Chinese
Tags:
Not-For-All-Audiences
License:
Limour's picture
Upload 3 files
f6d6399 verified
raw
history blame
2.14 kB
import json
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)]
def get_all_files_in_directory(directory, ext=''):
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=lambda x: custom_sort_key(x))
a = get_all_files_in_directory(r'E:\tmp\kiss\ks', ext='.txt.json')
_n = {
"創": "创",
"null": '旁白',
None: '旁白',
"テレビ": "电视的声音",
"エゴ": "EGO",
"スカウト": "星探",
"女客A": "女客人",
"先輩ホスト": "牛郎前辈",
"女客B": "女客人",
"オーナー": "老板",
"ゴロー": "GORO",
"おばちゃん": "老婆婆",
"フレンチブルドッグ": "法国斗牛犬",
"運転手": "司机",
"浅倉": "浅仓",
"レンタカー店員": "租车行店员",
"ナンパ女A": "搭讪女A",
"ナンパ女B": "搭讪女B",
"ホテル店員": "饭店柜台人员",
"ストーカー": "跟踪狂",
"博士": "博士",
"配達員": "送货员"
}
b = r'D:\datasets\tmp'
sc = {}
for path in a:
name = 'kiss'
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']:
# print(texts)
n = texts[0]
# _n[n] = texts[1][2][0]
n = _n[n]
d = texts[1][2][1]
if d:
sc[name].append(n + ':' + d)
except KeyError:
if type(texts) is not dict:
print(texts)
for k, v in sc.items():
with open(b + f'\\{k}.txt', 'w', encoding='utf-8') as f:
f.write('\n'.join(v))
tmp = json.dumps(_n, ensure_ascii=False, indent=2)