Update app.py
Browse files700 unmodified lines7017027037047057067077087097 unmodified lines717718719720721722723724725700 unmodified lines"""Fetches the actual MP3 download URL using the provided YouTube Video ID (vid)."""async with httpx.AsyncClient() as client:try:# 3. Get Download Link using the vid from the request bodydl_api_url = f"https://spotubedl.com/api/download/{request.vid}?engine=v1&format=mp3&quality=128"dl_resp = await client.get(dl_api_url, headers=HEADERS)dl_resp.raise_for_status()7 unmodified linesexcept httpx.HTTPStatusError as e:raise HTTPException(status_code=e.response.status_code, detail="Failed to fetch download link from upstream API.")except Exception as e:raise HTTPException(status_code=500, detail=str(e))700 unmodified lines7017027037047057067077087097107117127 unmodified lines720721722723724725726727728729730731732700 unmodified lines"""Fetches the actual MP3 download URL using the provided YouTube Video ID (vid)."""# Create a custom timeout (e.g., 30 seconds instead of the default 5 seconds)custom_timeout = httpx.Timeout(20.0)# Pass the timeout to the AsyncClientasync with httpx.AsyncClient(timeout=custom_timeout) as client:try:dl_api_url = f"https://spotubedl.com/api/download/{request.vid}?engine=v1&format=mp3&quality=128"dl_resp = await client.get(dl_api_url, headers=HEADERS)dl_resp.raise_for_status()7 unmodified linesexcept httpx.HTTPStatusError as e:raise HTTPException(status_code=e.response.status_code, detail="Failed to fetch download link from upstream API.")except httpx.TimeoutException:# Catching the timeout specifically gives you better debugging inforaise HTTPException(status_code=504, detail="Upstream API took too long to respond.")except Exception as e:# Print the actual error to your console so you can see it next time!print(f"Internal Error: {repr(e)}")raise HTTPException(status_code=500, detail=str(e))
app.py+10-3