| import streamlit as st |
| import requests |
|
|
| st.set_page_config(page_title="๐ Quran Explorer", layout="centered") |
|
|
| |
| def is_pure_bismillah(surah_number): |
| url = f"http://api.alquran.cloud/v1/ayah/{surah_number}:1/quran-uthmani" |
| res = requests.get(url) |
| if res.status_code == 200: |
| text = res.json()["data"]["text"].strip() |
| return text == "๏ปฟุจูุณูู
ู ูฑูููููู ูฑูุฑููุญูู
ููฐูู ูฑูุฑููุญููู
ู" |
| return False |
|
|
| @st.cache_data |
| def get_surah_list(): |
| url = "http://api.alquran.cloud/v1/surah" |
| response = requests.get(url) |
| data = response.json() |
| return data["data"] if data["status"] == "OK" else [] |
|
|
| |
| st.title("๐ Quran Explorer") |
|
|
| surahs = get_surah_list() |
| surah_options = [f"{s['number']}. {s['englishName']} ({s['englishNameTranslation']})" for s in surahs] |
| surah_dict = {s['number']: s for s in surahs} |
|
|
| selected = st.selectbox("Select a Surah", options=surah_options) |
| surah_number = int(selected.split(".")[0]) |
| surah_info = surah_dict[surah_number] |
| total_ayahs = surah_info["numberOfAyahs"] |
|
|
| |
| reciters = { |
| "Mishary Rashid Alafasy": "ar.alafasy", |
| "Abdul Basit": "ar.abdulbasitmurattal", |
| "Maher Al Muaiqly": "ar.mahermuaiqly" |
| } |
| reciter_name = st.selectbox("Select Reciter", list(reciters.keys())) |
| reciter_code = reciters[reciter_name] |
|
|
| |
| mode = st.radio("๐ Display Mode", ["Single Ayah", "Full Surah"]) |
|
|
| |
| skip_bismillah = False |
| if surah_number != 9: |
| skip_bismillah = is_pure_bismillah(surah_number) |
| offset = 1 if skip_bismillah else 0 |
|
|
| |
| if mode == "Single Ayah": |
| display_ayahs = list(range(1, total_ayahs)) if skip_bismillah else list(range(1, total_ayahs + 1)) |
| ayah_number = st.selectbox("Select Ayah", display_ayahs) |
|
|
| if st.button("๐ Search Ayah"): |
| actual_ayah_number = ayah_number + offset |
| editions = f"quran-uthmani,en.sahih,ur.jalandhry,{reciter_code}" |
| url = f"http://api.alquran.cloud/v1/ayah/{surah_number}:{actual_ayah_number}/editions/{editions}" |
|
|
| res = requests.get(url) |
| if res.status_code == 200 and res.json()["status"] == "OK": |
| data = res.json()["data"] |
| arabic = data[0]["text"] |
| english = data[1]["text"] |
| urdu = data[2]["text"] |
| audio_url = data[3]["audio"] |
|
|
| st.markdown(f"<h2 style='text-align:right;font-family:Amiri;'>{arabic}</h2>", unsafe_allow_html=True) |
| st.write(f"**English (Sahih International):** {english}") |
| st.write(f"**Urdu (Jalandhry):** {urdu}") |
| st.audio(audio_url) |
|
|
| |
| else: |
| if st.button("๐ Load Full Surah"): |
| editions = f"quran-uthmani,en.sahih,ur.jalandhry,{reciter_code}" |
| url = f"http://api.alquran.cloud/v1/surah/{surah_number}/editions/{editions}" |
| res = requests.get(url) |
| if res.status_code == 200 and res.json()["status"] == "OK": |
| data = res.json()["data"] |
| arabic_list = data[0]["ayahs"] |
| english_list = data[1]["ayahs"] |
| urdu_list = data[2]["ayahs"] |
| audio_list = data[3]["ayahs"] |
|
|
| for i in range(len(arabic_list)): |
| if skip_bismillah and i == 0: |
| continue |
| st.markdown(f"<h2 style='text-align:right;font-family:Amiri;'>{arabic_list[i]['text']}</h2>", unsafe_allow_html=True) |
| st.write(f"**English (Sahih International):** {english_list[i]['text']}") |
| st.write(f"**Urdu (Jalandhry):** {urdu_list[i]['text']}") |
| st.audio(audio_list[i]["audio"]) |
|
|