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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -15
app.py CHANGED
@@ -252,30 +252,56 @@ async def get_track_download_url(video_url: str) -> str:
252
 
253
  def jio_search(query: str) -> str:
254
  try:
255
- api_url = f"https://saavn.dev/api/search/songs?query={query}/"
 
256
  session = cloudscraper.create_scraper()
257
-
258
- # Use the correct API endpoint
259
  response = session.get(api_url)
260
- return response
261
-
 
 
 
 
 
 
 
262
 
 
263
  def jio_fetch(url: str) -> str:
264
  try:
265
- api_url = f"https://saavn.dev/api/songs?link={url}/"
 
266
  session = cloudscraper.create_scraper()
267
-
268
- # Use the correct API endpoint
269
  response = session.get(api_url)
270
- return response
271
-
 
 
 
 
 
 
 
 
 
272
  @app.post("/jio_dl")
273
  async def jio_download(request: Request):
274
- data = await request.json()
275
- url = data.get('url')
276
- response = jio_fetch(url)
277
- return response
278
-
 
 
 
 
 
 
 
 
 
279
 
280
 
281
 
 
252
 
253
  def jio_search(query: str) -> str:
254
  try:
255
+ # Construct the API URL
256
+ api_url = f"https://saavn.dev/api/search/songs?query={query}"
257
  session = cloudscraper.create_scraper()
258
+ # Make the API request
 
259
  response = session.get(api_url)
260
+ # Check if the request was successful
261
+ response.raise_for_status()
262
+ return response.text
263
+ except cloudscraper.exceptions.CloudflareChallengeError as cf_err:
264
+ logger.error(f"Cloudflare challenge error while searching for {query}: {cf_err}")
265
+ raise HTTPException(status_code=503, detail="Cloudflare challenge failed")
266
+ except Exception as e:
267
+ logger.error(f"Error while searching for {query}: {e}")
268
+ raise HTTPException(status_code=500, detail=f"An error occurred while searching: {str(e)}")
269
 
270
+
271
  def jio_fetch(url: str) -> str:
272
  try:
273
+ # Construct the API URL
274
+ api_url = f"https://saavn.dev/api/songs?link={url}"
275
  session = cloudscraper.create_scraper()
276
+ # Make the API request
 
277
  response = session.get(api_url)
278
+ # Check if the request was successful
279
+ response.raise_for_status()
280
+ return response.text
281
+ except cloudscraper.exceptions.CloudflareChallengeError as cf_err:
282
+ logger.error(f"Cloudflare challenge error while fetching {url}: {cf_err}")
283
+ raise HTTPException(status_code=503, detail="Cloudflare challenge failed")
284
+ except Exception as e:
285
+ logger.error(f"Error while fetching {url}: {e}")
286
+ raise HTTPException(status_code=500, detail=f"An error occurred while fetching: {str(e)}")
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
302
+ except Exception as e:
303
+ logger.error(f"Error in jio_download: {e}")
304
+ raise HTTPException(status_code=500, detail=f"An error occurred during download: {str(e)}")
305
 
306
 
307