Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -30,7 +30,7 @@ GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN", "توکن_گیتهاب").strip(
|
|
| 30 |
TG_BOT_TOKEN = os.environ.get("TG_BOT_TOKEN", "توکن_تلگرام").strip()
|
| 31 |
|
| 32 |
# توکن مربوط به RapidAPI برای دانلود یوتیوب (مهم)
|
| 33 |
-
RAPIDAPI_KEY = os.environ.get("RAPIDAPI_KEY", "
|
| 34 |
|
| 35 |
GITHUB_REPO = "hajiliker6-source/internet-melli"
|
| 36 |
|
|
@@ -88,9 +88,9 @@ async def download_youtube_rapidapi(url, chat_id, message_id, client):
|
|
| 88 |
}
|
| 89 |
|
| 90 |
async with aiohttp.ClientSession(headers=headers) as session:
|
| 91 |
-
# مرحله 1: شروع دانلود (مسیر ا
|
| 92 |
payload = {"url": url, "format": "mp4", "quality": 720}
|
| 93 |
-
async with session.post(f"{API_BASE}/
|
| 94 |
|
| 95 |
if resp.status != 200:
|
| 96 |
server_log = await resp.text()
|
|
@@ -111,8 +111,11 @@ async def download_youtube_rapidapi(url, chat_id, message_id, client):
|
|
| 111 |
if not job_id:
|
| 112 |
raise Exception(f"سرور شناسه Job ID را برنگرداند. پاسخ سرور:\n{start_data}")
|
| 113 |
|
| 114 |
-
# خواندن داینامیک مسیر وضعیت
|
| 115 |
-
status_path = start_data.get("statusUrl"
|
|
|
|
|
|
|
|
|
|
| 116 |
if status_path.startswith("/"):
|
| 117 |
status_url = API_BASE + status_path
|
| 118 |
else:
|
|
@@ -147,7 +150,7 @@ async def download_youtube_rapidapi(url, chat_id, message_id, client):
|
|
| 147 |
try: await client.edit_message_text(chat_id, status_msg_id, "📥 پردازش موفق! در حال دانلود ویدیو از سرور واسط...")
|
| 148 |
except: pass
|
| 149 |
|
| 150 |
-
# مرحله 3: دانلود فایل نهایی
|
| 151 |
temp_dir = "/app/downloads"
|
| 152 |
os.makedirs(temp_dir, exist_ok=True)
|
| 153 |
filename = f"youtube_{uuid.uuid4().hex[:6]}.mp4"
|
|
|
|
| 30 |
TG_BOT_TOKEN = os.environ.get("TG_BOT_TOKEN", "توکن_تلگرام").strip()
|
| 31 |
|
| 32 |
# توکن مربوط به RapidAPI برای دانلود یوتیوب (مهم)
|
| 33 |
+
RAPIDAPI_KEY = os.environ.get("RAPIDAPI_KEY", "b448420296msh34bbdc459d62fa0p124de1jsn8778ca694e65").strip()
|
| 34 |
|
| 35 |
GITHUB_REPO = "hajiliker6-source/internet-melli"
|
| 36 |
|
|
|
|
| 88 |
}
|
| 89 |
|
| 90 |
async with aiohttp.ClientSession(headers=headers) as session:
|
| 91 |
+
# مرحله 1: شروع دانلود (مسیر نهایی و قطعی: /download)
|
| 92 |
payload = {"url": url, "format": "mp4", "quality": 720}
|
| 93 |
+
async with session.post(f"{API_BASE}/download", json=payload) as resp:
|
| 94 |
|
| 95 |
if resp.status != 200:
|
| 96 |
server_log = await resp.text()
|
|
|
|
| 111 |
if not job_id:
|
| 112 |
raise Exception(f"سرور شناسه Job ID را برنگرداند. پاسخ سرور:\n{start_data}")
|
| 113 |
|
| 114 |
+
# خواندن داینامیک مسیر وضعیت
|
| 115 |
+
status_path = start_data.get("statusUrl")
|
| 116 |
+
if not status_path:
|
| 117 |
+
status_path = f"/status/{job_id}" # بکاپ اگر سرور لینک نداد
|
| 118 |
+
|
| 119 |
if status_path.startswith("/"):
|
| 120 |
status_url = API_BASE + status_path
|
| 121 |
else:
|
|
|
|
| 150 |
try: await client.edit_message_text(chat_id, status_msg_id, "📥 پردازش موفق! در حال دانلود ویدیو از سرور واسط...")
|
| 151 |
except: pass
|
| 152 |
|
| 153 |
+
# مرحله 3: دانلود فایل نهایی
|
| 154 |
temp_dir = "/app/downloads"
|
| 155 |
os.makedirs(temp_dir, exist_ok=True)
|
| 156 |
filename = f"youtube_{uuid.uuid4().hex[:6]}.mp4"
|