Initial API upload
Browse files
main.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from fastapi import FastAPI, HTTPException
|
| 2 |
-
from fastapi.responses import FileResponse, JSONResponse, RedirectResponse, StreamingResponse
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
from scalar_fastapi import get_scalar_api_reference
|
| 5 |
import json
|
|
@@ -42,6 +42,7 @@ MUSHAFS_DIR = CDN_DIR / "mushafs"
|
|
| 42 |
PROFILES_DIR = CDN_DIR / "reciters" / "profiles-images"
|
| 43 |
ATHAN_DIR = CDN_DIR / "reciters" / "athan"
|
| 44 |
BACKGROUND_AUDIO_DIR = CDN_DIR / "background_audio"
|
|
|
|
| 45 |
|
| 46 |
# Simple keep-alive function using threading.Timer
|
| 47 |
def keep_alive():
|
|
@@ -82,36 +83,36 @@ RECITERS = {
|
|
| 82 |
"name": "Abdul Baset",
|
| 83 |
"arabic_name": "عبد الباسط عبد الصمد",
|
| 84 |
"types": ["mujawwad", "murattal"],
|
| 85 |
-
"description": "
|
| 86 |
"profile_image": "abdelbasset-profile.png"
|
| 87 |
},
|
| 88 |
"khalil-al-husary": {
|
| 89 |
"name": "Khalil Al-Husary",
|
| 90 |
"arabic_name": "محمود خليل الحصري",
|
| 91 |
-
"types": ["murattal", "muallim"],
|
| 92 |
-
"description": "
|
| 93 |
"profile_image": "mahmoud-khalil-al-hussary-profile.png"
|
| 94 |
},
|
| 95 |
"siddiq-minshawi": {
|
| 96 |
"name": "Siddiq Minshawi",
|
| 97 |
"arabic_name": "محمد صديق المنشاوي",
|
| 98 |
"types": ["murattal", "kids-repeat"],
|
| 99 |
-
"description": "Siddiq Minshawi was
|
| 100 |
"profile_image": "mohamed-siddiq-el-minshawi-profile.png"
|
| 101 |
},
|
| 102 |
"hani-ar-rifai": {
|
| 103 |
"name": "Hani Ar-Rifai",
|
| 104 |
"arabic_name": "هاني الرفاعي",
|
| 105 |
"types": ["murattal"],
|
| 106 |
-
"description": "Hani Ar-Rifai is a
|
| 107 |
"profile_image": "hani-ar-rifai-profile.jpeg"
|
| 108 |
},
|
| 109 |
"abdurrahmaan-as-sudais": {
|
| 110 |
"name": "Abdurrahmaan As-Sudais",
|
| 111 |
"arabic_name": "عبد الرحمن السديس",
|
| 112 |
"types": ["murattal"],
|
| 113 |
-
"description": "
|
| 114 |
-
"profile_image": "abdul-rahman-al-sudais-profile.png"
|
| 115 |
},
|
| 116 |
"maher-al-muaiqly": {
|
| 117 |
"name": "Maher Al-Muaiqly",
|
|
@@ -496,6 +497,121 @@ async def get_background_audio(filename: str):
|
|
| 496 |
|
| 497 |
raise HTTPException(status_code=404, detail="Background audio file not found")
|
| 498 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 499 |
if __name__ == "__main__":
|
| 500 |
import uvicorn
|
| 501 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
| 1 |
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from fastapi.responses import FileResponse, JSONResponse, RedirectResponse, StreamingResponse, Response
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
from scalar_fastapi import get_scalar_api_reference
|
| 5 |
import json
|
|
|
|
| 42 |
PROFILES_DIR = CDN_DIR / "reciters" / "profiles-images"
|
| 43 |
ATHAN_DIR = CDN_DIR / "reciters" / "athan"
|
| 44 |
BACKGROUND_AUDIO_DIR = CDN_DIR / "background_audio"
|
| 45 |
+
FONTS_DIR = CDN_DIR / "fonts"
|
| 46 |
|
| 47 |
# Simple keep-alive function using threading.Timer
|
| 48 |
def keep_alive():
|
|
|
|
| 83 |
"name": "Abdul Baset",
|
| 84 |
"arabic_name": "عبد الباسط عبد الصمد",
|
| 85 |
"types": ["mujawwad", "murattal"],
|
| 86 |
+
"description": "Abdulbasit Abdusamad is a renowned Qur'an reciter born in 1927 in a village called Almara'za in Egypt.\n\nHe learned the Holy Qur’an at an early age from Shaykh Mohamed El Amir and later from Mohamed Selim Hamada. He entered the National Radio Station in 1951. The first surah he recited was Surah Fater.\n\nIn 1952, Abdulbasit Abdulsamad was appointed official reciter to Al-Imam Achafiî's mosque and then to Al-Imam Al Hussain's mosque in 1985.\n\nAbdulbasit has left a fortune of high-quality recordings of both the Mujawwad recitation (A slow, melodious recitation style emphasizing beauty, emotion, and full, elaborate articulation of tajwīd, usually at a slow pace) and the Murattal recitation (A measured, clear recitation with a medium pace). He was an ambassador of the Holy Qur'an across many countries and the first president of the Egyptian reciters' Bar in 1984.\n\nAbdulbasit Abdusamad went to many Arab countries to recite the Qur'an in Ramadan, such as Saudi Arabia and Syria.\n\nHe died on November 30th, 1988. May Allah have mercy on his soul, bless him, and grant him a place in Jannah.",
|
| 87 |
"profile_image": "abdelbasset-profile.png"
|
| 88 |
},
|
| 89 |
"khalil-al-husary": {
|
| 90 |
"name": "Khalil Al-Husary",
|
| 91 |
"arabic_name": "محمود خليل الحصري",
|
| 92 |
+
"types": ["murattal", "muallim","mujawwad","ijazah"],
|
| 93 |
+
"description": "Mahmoud Al-Hussary is a renowned reciter of the Qur'an. He was born in a village called Shubra Al-Namlah in Tanta, Egypt. \n\n Mahmoud entered the Quran School at the age of four. At 8, he had already memorized the whole Qur'an and at 12, he had learned the ten recitations of the Qur'an from Al-Azhar in 1958. Mahmoud Khalil Al-Hussary first recited the Quran in his village mosque. In 1944, he entered the official radio station as a reciter, where he made his first recitation on 16 February 1944. On August 7, 1948, he was nominated Muazzin (Prayer caller) of Sidi Hamzah Mosque and then a reciter in the same mosque. He was also supervising the recitation centers of the Al Gharbia Governorate.\n\nIn 1949, Mahmoud Al-Hussary was appointed reciter of Sidi Ahmed Al-Badawi of Tanta of Al-Ahmadi Mosque and then of Al-Imam Al Hussein Mosque in Cairo by 1955. \n\n All along his way, Sheikh Mahmoud obtained various medals and decorations and was honored by numerous Islamic and foreign countries which he visited. He was treated with special care by leaders, kings, and presidents. He received the medal of honor concerning Sciences and Arts from the president, Gamal Abdel Nasser, in 1967 and was elected as president of the Islamic world league of Koran reciters. He had the chance to recite the Quran in front of the American congress and the United Nations. Thanks to him, Allah guided dozens of people during his journeys abroad. He remained, for the rest of his life, a researcher, a writer, a thinker, and of course one of the biggest public figures in Egypt and in the Arab Muslim world.",
|
| 94 |
"profile_image": "mahmoud-khalil-al-hussary-profile.png"
|
| 95 |
},
|
| 96 |
"siddiq-minshawi": {
|
| 97 |
"name": "Siddiq Minshawi",
|
| 98 |
"arabic_name": "محمد صديق المنشاوي",
|
| 99 |
"types": ["murattal", "kids-repeat"],
|
| 100 |
+
"description": "Muhammad Siddiq Al-Minshawi, also simply known as Al-Minshawy or Menshawy, born in Upper Egypt, was a Qur'anic reciter and a Hafiz. \n\n He is of the same generation as Shaykh Kamil Yusuf al-Bahtimi, and, in fact, he was also a protégé of Shaykh Muhammad Salâmah. His father was also a well-known reciter, and his brother, Shaykh Mahmûd al-Minshâwî, has now established himself as a respected professional reciter in Cairo. Shaykh al-Minshâwî was born in Upper Egypt and established himself as a reciter there before coming to Cairo. He is especially admired for the spirituality, gravity, and dignity of his style",
|
| 101 |
"profile_image": "mohamed-siddiq-el-minshawi-profile.png"
|
| 102 |
},
|
| 103 |
"hani-ar-rifai": {
|
| 104 |
"name": "Hani Ar-Rifai",
|
| 105 |
"arabic_name": "هاني الرفاعي",
|
| 106 |
"types": ["murattal"],
|
| 107 |
+
"description": "Sheikh Hani Ar-Rifai was born in 1974 in the city of Jeddah, Saudi Arabia. He is currently the Imam and the Khateeb of Anani’s mosque in Jeddah. He is well-known for his unique voice filled with emotion, which attracts many listeners to his recitations of the Holy Qur’an. \n\n The Sheikh grew up in a conservative family that placed great importance on the learning of the Qur’an. By the age of twelve, Sheikh Hani Ar-Rifai had learned all the verses of the holy book.\n\n He specialized in Islamic Studies at King Abdulaziz University. He studied under the guidance of renowned scholars and sheikhs, including Sheikh Al-alama Abullah Ibn Bayyah, Sheikh Khaldoun Al-Ahdab, and Sheikh Ali Jaber.\n\n Owing to the emotional and soul-warming rendition of the Book of Allah, Sheikh Hani Ar-Rifai was elected as a special reciter of the Holy Qur’an in the Royal Court by the Saudi Ministry of Culture and Information. The Sheikh participated in numerous religious events, reciting ayahs of the Holy Qur’an or offering advice. He was also chosen to be the personal reciter of King Fahd Ibn Abdelaziz Al-Saud from 1998 till his death.\n\n From 1998 to 2002, the sheikh worked as a teacher of Islamic Studies in different public schools in Saudi Arabia. He was then appointed the director of the legal affairs of King Faysal’s hospital and the Research Center in Jeddah. He was granted the coveted designation as the Director of the legal affairs of King Faysal’s Hospital and the Research Center in Jeddah.\n His Qur’an recitation was broadcast on various channels such as “Alfaj”, “Iqra”, “Almajd”, and “Ashariqa”.",
|
| 108 |
"profile_image": "hani-ar-rifai-profile.jpeg"
|
| 109 |
},
|
| 110 |
"abdurrahmaan-as-sudais": {
|
| 111 |
"name": "Abdurrahmaan As-Sudais",
|
| 112 |
"arabic_name": "عبد الرحمن السديس",
|
| 113 |
"types": ["murattal"],
|
| 114 |
+
"description": "Abdul Rahman Ibn Abdul Aziz as-Sudais (عبد الرحمن السديس) was born in the city of Qassim, Saudi Arabia in 1962 (1382 A.H). He's originally from the Anza clan. He had memorized the Qur'an by the age of 12 growing up in Riyadh. \n \n Al-Sudais studied at the Al Muthana Bin Harith Elementary School and later at the Riyadh Scientific Institution, from which he graduated in 1979 with an excellent grade. He obtained a degree in Sharia from Riyadh University in 1983 and became an IFK (Islamic Fundamental Knowledge) lecturer after the conclusion of his study. He obtained his Master's in Islamic fundamentals from the Sharia College of Imam Muhammad bin Saud Islamic University in 1987 and received his PhD in Islamic Sharia from Umm al-Qura University in 1995 while working there as an assistant professor after serving at Riyadh University. \n\n He is respected for his precise, controlled, and particularly emotional recitation of the Qur'an in accordance with Tajweed – the rules of beautiful recitation. He was particularly called upon in the Ramadan Taraweeh prayers of 2006 (1427 AH) to recite the last few surahs of the Qur'an as well as to deliver the closing dua, which was followed by millions of Muslims in Mecca and around the World via TV or radio.\n\n\nIn 2005, he received the Islamic Personality of the Year award in the 9th annual Dubai International Holy Qur’an Award. He is the leading Imam at Masjidil Haram, Makkah.",
|
| 115 |
+
"profile_image": "abdul-rahman-al-sudais-profile.png"
|
| 116 |
},
|
| 117 |
"maher-al-muaiqly": {
|
| 118 |
"name": "Maher Al-Muaiqly",
|
|
|
|
| 497 |
|
| 498 |
raise HTTPException(status_code=404, detail="Background audio file not found")
|
| 499 |
|
| 500 |
+
# Get fonts CSS (like Google Fonts)
|
| 501 |
+
@app.get("/api/fonts.css")
|
| 502 |
+
async def get_fonts_css(family: str = None, display: str = "swap"):
|
| 503 |
+
# Define available fonts
|
| 504 |
+
available_fonts = {
|
| 505 |
+
"kitab": {
|
| 506 |
+
"family": "kitab",
|
| 507 |
+
"files": [
|
| 508 |
+
("Kitab-Regular.woff2", "woff2"),
|
| 509 |
+
("Kitab-Regular.ttf", "truetype")
|
| 510 |
+
],
|
| 511 |
+
"local": ["kitab"]
|
| 512 |
+
},
|
| 513 |
+
"Uthmani": {
|
| 514 |
+
"family": "Uthmani",
|
| 515 |
+
"files": [
|
| 516 |
+
("Uthmani-Regular.ttf", "truetype"),
|
| 517 |
+
("Uthmani-Regular.woff2", "woff2")
|
| 518 |
+
],
|
| 519 |
+
"local": []
|
| 520 |
+
},
|
| 521 |
+
"sfPro": {
|
| 522 |
+
"family": "sfPro",
|
| 523 |
+
"files": [
|
| 524 |
+
("SF-ProUI.ttf", "truetype"),
|
| 525 |
+
("SF-ProUI.woff2", "woff2")
|
| 526 |
+
],
|
| 527 |
+
"local": []
|
| 528 |
+
},
|
| 529 |
+
"sfArabic": {
|
| 530 |
+
"family": "sfArabic",
|
| 531 |
+
"files": [
|
| 532 |
+
("SF-ArabicUI.ttf", "truetype"),
|
| 533 |
+
("SF-ArabicUI.woff2", "woff2")
|
| 534 |
+
],
|
| 535 |
+
"local": []
|
| 536 |
+
}
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
# Parse font families from query parameter
|
| 540 |
+
selected_fonts = []
|
| 541 |
+
if family:
|
| 542 |
+
# Split by | and clean up
|
| 543 |
+
font_names = [f.strip() for f in family.split("|")]
|
| 544 |
+
for font_name in font_names:
|
| 545 |
+
if font_name in available_fonts:
|
| 546 |
+
selected_fonts.append(available_fonts[font_name])
|
| 547 |
+
else:
|
| 548 |
+
# If no family specified, return all fonts
|
| 549 |
+
selected_fonts = list(available_fonts.values())
|
| 550 |
+
|
| 551 |
+
# Generate CSS
|
| 552 |
+
css_parts = []
|
| 553 |
+
for font in selected_fonts:
|
| 554 |
+
src_parts = []
|
| 555 |
+
# Add local references
|
| 556 |
+
for local_name in font.get("local", []):
|
| 557 |
+
src_parts.append(f'local("{local_name}")')
|
| 558 |
+
# Add file references
|
| 559 |
+
for filename, format_type in font["files"]:
|
| 560 |
+
src_parts.append(f'url("/api/fonts/{filename}") format("{format_type}")')
|
| 561 |
+
|
| 562 |
+
font_face = f"""@font-face {{
|
| 563 |
+
font-family: "{font['family']}";
|
| 564 |
+
font-display: {display};
|
| 565 |
+
src: {', '.join(src_parts)};
|
| 566 |
+
}}"""
|
| 567 |
+
css_parts.append(font_face)
|
| 568 |
+
|
| 569 |
+
css_content = "\n\n".join(css_parts)
|
| 570 |
+
return Response(content=css_content, media_type="text/css")
|
| 571 |
+
|
| 572 |
+
# Get font file
|
| 573 |
+
@app.api_route("/api/fonts/{filename}", methods=["GET", "HEAD"], operation_id="getFontFile")
|
| 574 |
+
async def get_font_file(filename: str):
|
| 575 |
+
# Sanitize filename to prevent path traversal
|
| 576 |
+
safe_filename = Path(filename).name
|
| 577 |
+
|
| 578 |
+
if USE_HF_CDN:
|
| 579 |
+
try:
|
| 580 |
+
hf_filename = f"fonts/{safe_filename}"
|
| 581 |
+
local_path = hf_hub_download(
|
| 582 |
+
repo_id=HF_DATASET_URL,
|
| 583 |
+
filename=hf_filename,
|
| 584 |
+
repo_type="dataset",
|
| 585 |
+
token=HF_TOKEN
|
| 586 |
+
)
|
| 587 |
+
# Determine media type based on extension
|
| 588 |
+
ext = Path(safe_filename).suffix.lower()
|
| 589 |
+
if ext == ".woff2":
|
| 590 |
+
media_type = "font/woff2"
|
| 591 |
+
elif ext == ".ttf":
|
| 592 |
+
media_type = "font/ttf"
|
| 593 |
+
else:
|
| 594 |
+
media_type = "application/octet-stream"
|
| 595 |
+
return FileResponse(local_path, media_type=media_type)
|
| 596 |
+
except Exception as e:
|
| 597 |
+
print(f"Error fetching font from HF CDN: {e}")
|
| 598 |
+
# Fall back to local
|
| 599 |
+
pass
|
| 600 |
+
|
| 601 |
+
# Try local file
|
| 602 |
+
font_path = FONTS_DIR / safe_filename
|
| 603 |
+
if font_path.exists():
|
| 604 |
+
ext = font_path.suffix.lower()
|
| 605 |
+
if ext == ".woff2":
|
| 606 |
+
media_type = "font/woff2"
|
| 607 |
+
elif ext == ".ttf":
|
| 608 |
+
media_type = "font/ttf"
|
| 609 |
+
else:
|
| 610 |
+
media_type = "application/octet-stream"
|
| 611 |
+
return FileResponse(font_path, media_type=media_type)
|
| 612 |
+
|
| 613 |
+
raise HTTPException(status_code=404, detail="Font file not found")
|
| 614 |
+
|
| 615 |
if __name__ == "__main__":
|
| 616 |
import uvicorn
|
| 617 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|