Datasets:
File size: 1,608 Bytes
add8e69 | 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 | import os
import json
from pathlib import Path
def fix_json():
base_dir = Path(".")
reciters = []
for entry in base_dir.iterdir():
if entry.is_dir() and not entry.name.startswith('.') and entry.name not in ('audio', 'wbw_tester', '__pycache__', 'test_segments'):
if (entry / '001').exists():
reciters.append(entry.name)
reciters = sorted(reciters)
print(f"Found {len(reciters)} reciters.")
for r in reciters:
for s in range(1, 115):
surah_str = f"{s:03d}"
json_path = base_dir / r / surah_str / f"{surah_str}.json"
if not json_path.exists():
continue
with open(json_path, 'r') as f:
try:
data = json.load(f)
except Exception:
continue
if isinstance(data, dict):
continue # already a dict
new_data = {}
current_verse = 0
for seg in data:
# new verse if seg[0] == 0
if seg[0] == 0:
current_verse += 1
key = f"{s}:{current_verse}"
if key not in new_data:
new_data[key] = {"segments": []}
new_data[key]["segments"].append(seg)
# overwrite the file
with open(json_path, 'w') as f:
json.dump(new_data, f, separators=(',', ':'))
if __name__ == '__main__':
fix_json()
|