Spaces:
Running
Running
Upload clean.py
Browse files
clean.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
assets_dir = './assets'
|
4 |
+
character = {}
|
5 |
+
|
6 |
+
# Step 1: Load character dictionary
|
7 |
+
for i in os.listdir(assets_dir):
|
8 |
+
if i.endswith('.wav'):
|
9 |
+
audio_path = f"{assets_dir}/{i}"
|
10 |
+
image_path= f"{assets_dir}/{i.replace('.wav', '.png')}"
|
11 |
+
sound_name = i.replace('.wav', '').replace('_', ' ').title()
|
12 |
+
character[sound_name] = {
|
13 |
+
'image_path': image_path,
|
14 |
+
'audio_path': audio_path
|
15 |
+
}
|
16 |
+
|
17 |
+
# Step 2: Define custom priority order
|
18 |
+
priority_names = [
|
19 |
+
'Bombardiro Crocodilo',
|
20 |
+
'Tralalero Tralala',
|
21 |
+
'Bombombini Gusini',
|
22 |
+
'Tung Tung Tung Tung Tung Tung Tung Tung Tung Sahur',
|
23 |
+
'Brr Brr Patapim',
|
24 |
+
'Cappuccino Assassino',
|
25 |
+
'Lirili Larila',
|
26 |
+
'Trulimero Trulichina',
|
27 |
+
'Boneca Ambalabu',
|
28 |
+
'Chimpanzini Bananini' # Note: Fix spacing issue from original
|
29 |
+
]
|
30 |
+
|
31 |
+
# Normalize keys to fix any mismatch
|
32 |
+
fixed_character = {}
|
33 |
+
for name, data in character.items():
|
34 |
+
fixed_name = ' '.join(name.split()) # Removes extra spaces
|
35 |
+
fixed_character[fixed_name] = data
|
36 |
+
|
37 |
+
# Step 3: Sort with custom priority
|
38 |
+
sorted_keys = (
|
39 |
+
priority_names +
|
40 |
+
sorted([k for k in fixed_character if k not in priority_names])
|
41 |
+
)
|
42 |
+
|
43 |
+
# Step 4: Create the final sorted dictionary
|
44 |
+
sorted_character = {k: fixed_character[k] for k in sorted_keys}
|
45 |
+
|
46 |
+
import json
|
47 |
+
json_path = 'character.json'
|
48 |
+
with open(json_path, 'w', encoding='utf-8') as f:
|
49 |
+
json.dump(sorted_character, f, ensure_ascii=False, indent=4)
|
50 |
+
|