Update app.py
Browse files
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 |
-
|
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
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
|
|
|
|
|
|
|
|
|
|
277 |
except cloudscraper.exceptions.CloudflareChallengeError as cf_err:
|
278 |
-
logger.error(f"Cloudflare challenge error while
|
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
|
285 |
-
raise HTTPException(status_code=500, detail=f"An error occurred while
|
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:
|