File size: 1,495 Bytes
3c6e2f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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")