Chrunos commited on
Commit
0cf8fb7
·
verified ·
1 Parent(s): 8e49823

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -260,29 +260,34 @@ def jio_search(query: str, quality: str) -> str:
260
  response = session.get(api_url)
261
  # Check if the request was successful
262
  response.raise_for_status()
 
263
  data = response.json().get("data")
264
- song_data = data.get("results")
265
- if not song_data or len(song_data) == 0:
266
  logger.error("No data found in the response.")
267
- raise HTTPException(status_code=404, detail="No data found for the given URL.")
268
- download_urls = song_data[0].get("downloadUrl")
269
- if not download_urls:
270
- logger.error("No download URLs found in the response.")
271
- raise HTTPException(status_code=404, detail="No download URLs found for the given song.")
272
- for download_url in download_urls:
273
- if download_url.get("quality") == quality:
274
- return download_url.get("url")
275
- logger.error(f"No download URL found for quality {quality}.")
276
- raise HTTPException(status_code=404, detail=f"No download URL found for quality {quality}.")
 
 
 
 
 
277
  except cloudscraper.exceptions.CloudflareChallengeError as cf_err:
278
- logger.error(f"Cloudflare challenge error while fetching {url}: {cf_err}")
279
  raise HTTPException(status_code=503, detail="Cloudflare challenge failed")
280
  except HTTPException:
281
  # Re - raise the HTTPException if it's already raised
282
  raise
283
  except Exception as e:
284
- logger.error(f"Error while fetching {url}: {e}")
285
- raise HTTPException(status_code=500, detail=f"An error occurred while fetching: {str(e)}")
286
 
287
 
288
  def jio_fetch(url: str, quality: str) -> str:
 
260
  response = session.get(api_url)
261
  # Check if the request was successful
262
  response.raise_for_status()
263
+ # Get the data from the response
264
  data = response.json().get("data")
265
+ if not data:
 
266
  logger.error("No data found in the response.")
267
+ raise HTTPException(status_code=404, detail="No data found for the given query.")
268
+ # Get the song results
269
+ song_results = data.get("results")
270
+ if not song_results or len(song_results) == 0:
271
+ logger.error("No song results found in the response.")
272
+ raise HTTPException(status_code=404, detail="No song results found for the given query.")
273
+ # Iterate through each song result
274
+ for song in song_results:
275
+ download_urls = song.get("downloadUrl")
276
+ if download_urls:
277
+ for download_url in download_urls:
278
+ if download_url.get("quality") == quality:
279
+ return download_url.get("url")
280
+ logger.error(f"No download URL found for quality {quality} in the search results for query {query}.")
281
+ raise HTTPException(status_code=404, detail=f"No download URL found for quality {quality} in the search results for query {query}.")
282
  except cloudscraper.exceptions.CloudflareChallengeError as cf_err:
283
+ logger.error(f"Cloudflare challenge error while searching for {query}: {cf_err}")
284
  raise HTTPException(status_code=503, detail="Cloudflare challenge failed")
285
  except HTTPException:
286
  # Re - raise the HTTPException if it's already raised
287
  raise
288
  except Exception as e:
289
+ logger.error(f"Error while searching for {query}: {e}")
290
+ raise HTTPException(status_code=500, detail=f"An error occurred while searching: {str(e)}")
291
 
292
 
293
  def jio_fetch(url: str, quality: str) -> str: