Spaces:
Running on Zero
Running on Zero
feat: integrate Cloudflare R2 Quran translations, add translation endpoints and edge caching
3c6e2f1 Download scripts/map_surah_audio.py from sahihislam/superadmin: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/spaces/sahihislam/superadmin/resolve/main/scripts/map_surah_audio.py
- Command line
-
hf download hf://spaces/sahihislam/superadmin/scripts/map_surah_audio.py
-
curl -L -o map_surah_audio.py https://huggingface.co/spaces/sahihislam/superadmin/resolve/main/scripts/map_surah_audio.py
1.5 kB
| import sys | |
| import urllib.request | |
| import json | |
| import re | |
| sys.stdout.reconfigure(encoding='utf-8') | |
| collections = { | |
| 'Maududi_Urdu': 'Tafheem-ul-Quran-by-Syed-Abul-Ala-Moududi-Audio-MP3-CD', | |
| 'Maududi_English': 'Towards-Understanding-the-Quran-Abridged-Version-Of-Tafhim-Al-Quran-Audio-Mp3', | |
| 'Saadi_Arabic': 'Tafseer_Al-Saadi_mp3', | |
| 'Ibn_Kathir_Urdu': 'Tafsir-ibne-kaseer-kathir-urdu-----audio-mp3-hq', | |
| } | |
| mappings = {} | |
| for key, coll in collections.items(): | |
| meta_url = f"https://archive.org/metadata/{coll}/files" | |
| req = urllib.request.Request(meta_url, headers={'User-Agent': 'Mozilla/5.0'}) | |
| with urllib.request.urlopen(req, timeout=15) as r: | |
| data = json.loads(r.read()) | |
| files = [f['name'] for f in data.get('result', []) if f['name'].endswith('.mp3')] | |
| surah_map = {} | |
| for f in files: | |
| m = re.match(r"^(\d{3})\b", f) | |
| if m: | |
| s_num = int(m.group(1)) | |
| if 1 <= s_num <= 114: | |
| surah_map[s_num] = f | |
| mappings[key] = surah_map | |
| print(f"{key}: mapped {len(surah_map)} / 114 Surahs") | |
| if len(surah_map) < 114: | |
| missing = [i for i in range(1, 115) if i not in surah_map] | |
| print(f" Missing: {missing}") | |
| with open("BACKEND/scripts/archive_surah_audio_mappings.json", "w", encoding="utf-8") as out: | |
| json.dump(mappings, out, ensure_ascii=False, indent=2) | |
| print("Saved mappings to BACKEND/scripts/archive_surah_audio_mappings.json") | |