Chrunos commited on
Commit
7c5ed7b
·
verified ·
1 Parent(s): 7ee85db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -287,15 +287,27 @@ def jio_fetch(url: str) -> str:
287
 
288
 
289
  @app.post("/jio_dl")
290
- async def jio_download(request: Request):
291
  try:
292
- data = await request.json()
293
- url = data.get('url')
294
- if not url:
295
- logger.error("No 'url' provided in the request data.")
296
- raise HTTPException(status_code=400, detail="Missing 'url' in request data")
297
  response = jio_fetch(url)
298
- return response
 
 
 
 
 
 
 
 
 
 
 
 
299
  except HTTPException:
300
  # Re - raise the HTTPException if it's already raised in jio_fetch
301
  raise
 
287
 
288
 
289
  @app.post("/jio_dl")
290
+ async def jio_download(request: JioDownloadRequest):
291
  try:
292
+ url = request.url
293
+ quality = request.quality
294
+ if not url or not quality:
295
+ logger.error("Missing 'url' or 'quality' in request data.")
296
+ raise HTTPException(status_code=400, detail="Missing 'url' or 'quality' in request data")
297
  response = jio_fetch(url)
298
+ data = response.get("data")
299
+ if not data or len(data) == 0:
300
+ logger.error("No data found in the response.")
301
+ raise HTTPException(status_code=404, detail="No data found for the given URL.")
302
+ download_urls = data[0].get("downloadUrl")
303
+ if not download_urls:
304
+ logger.error("No download URLs found in the response.")
305
+ raise HTTPException(status_code=404, detail="No download URLs found for the given song.")
306
+ for download_url in download_urls:
307
+ if download_url.get("quality") == quality:
308
+ return {"download_url": download_url.get("url")}
309
+ logger.error(f"No download URL found for quality {quality}.")
310
+ raise HTTPException(status_code=404, detail=f"No download URL found for quality {quality}.")
311
  except HTTPException:
312
  # Re - raise the HTTPException if it's already raised in jio_fetch
313
  raise