urstark commited on
Commit
aead0a6
·
1 Parent(s): f0f8aed

feat: migrate download logic to new ShrutiBots API & YT_API_KEY configuration

Browse files
Files changed (1) hide show
  1. app.py +6 -12
app.py CHANGED
@@ -26,8 +26,8 @@ BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN", "")
26
  CHAT_ID = int(os.getenv("TELEGRAM_CHAT_ID", "0"))
27
  HF_SECRET = os.getenv("HF_SECRET") or os.getenv("SECRET_TOKEN") or ""
28
  HF_TOKEN = os.getenv("HF_TOKEN", "")
29
- EXTERNAL_API_URL = os.getenv("EXTERNAL_API_URL", "https://shrutibots.site")
30
- API_KEY = os.getenv("API_KEY", "")
31
 
32
  # Initialize Pyrogram Client (MTProto - Bot Only)
33
  bot = Client(
@@ -103,18 +103,12 @@ def require_auth(f):
103
  async def fetch_download_url(video_id: str, media_type: str):
104
  try:
105
  async with aiohttp.ClientSession() as session:
106
- url = f"{EXTERNAL_API_URL}/download?url={video_id}&type={media_type}"
107
- if API_KEY:
108
- url += f"&api_key={API_KEY}"
109
  headers = {"Authorization": f"Bearer {HF_TOKEN}"} if HF_TOKEN else {}
110
- async with session.get(url, headers=headers) as resp:
111
  if resp.status == 200:
112
- data = await resp.json()
113
- token = data.get("download_token")
114
- if token:
115
- sep = "&" if "?" in video_id else "?"
116
- return f"{EXTERNAL_API_URL}/stream/{video_id}{sep}type={media_type}&token={token}"
117
- return data.get("url")
118
  except Exception as e:
119
  print(f"[Vault] Error fetching download URL: {str(e)}")
120
  return None
 
26
  CHAT_ID = int(os.getenv("TELEGRAM_CHAT_ID", "0"))
27
  HF_SECRET = os.getenv("HF_SECRET") or os.getenv("SECRET_TOKEN") or ""
28
  HF_TOKEN = os.getenv("HF_TOKEN", "")
29
+ EXTERNAL_API_URL = os.getenv("EXTERNAL_API_URL", "https://api01.shrutibots.site")
30
+ YT_API_KEY = os.getenv("YT_API_KEY", "")
31
 
32
  # Initialize Pyrogram Client (MTProto - Bot Only)
33
  bot = Client(
 
103
  async def fetch_download_url(video_id: str, media_type: str):
104
  try:
105
  async with aiohttp.ClientSession() as session:
106
+ url = f"{EXTERNAL_API_URL}/download"
107
+ params = {"url": video_id, "type": media_type, "api_key": YT_API_KEY}
 
108
  headers = {"Authorization": f"Bearer {HF_TOKEN}"} if HF_TOKEN else {}
109
+ async with session.get(url, params=params, headers=headers) as resp:
110
  if resp.status == 200:
111
+ return f"{EXTERNAL_API_URL}/download?url={video_id}&type={media_type}&api_key={YT_API_KEY}"
 
 
 
 
 
112
  except Exception as e:
113
  print(f"[Vault] Error fetching download URL: {str(e)}")
114
  return None