Datasets:
| 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() | |