From 423db6c60bd9b9105c19ca56ad1f84e0e626fbe1 Mon Sep 17 00:00:00 2001 From: Khoa Vo Date: Thu, 1 Jan 2026 16:56:23 +0700 Subject: [PATCH] Final Polish: Remove debug logs and cleanup stream_audio --- backend/api/routes.py | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/backend/api/routes.py b/backend/api/routes.py index c433033..764efae 100644 --- a/backend/api/routes.py +++ b/backend/api/routes.py @@ -685,39 +685,25 @@ async def stream_audio(id: str): if 'Cookie' in base_headers: req_headers['Cookie'] = base_headers['Cookie'] - print(f"DEBUG_STREAM [{id}]: Opening connection to {stream_url[:50]}...", flush=True) - print(f"DEBUG_STREAM [{id}]: Headers: User-Agent={req_headers.get('User-Agent')[:30]}..., Cookie Present={'Cookie' in req_headers}", flush=True) - # Disable SSL verify to match yt-dlp 'nocheckcertificate' (fixes NAS CA issues) external_req = requests.get(stream_url, stream=True, timeout=30, headers=req_headers, verify=False) - print(f"DEBUG_STREAM [{id}]: Upstream Status: {external_req.status_code}", flush=True) - external_req.raise_for_status() + except requests.exceptions.HTTPError as http_err: error_details = f"Upstream error: {http_err.response.status_code}" - print(f"DEBUG_STREAM [{id}]: FAILED {error_details}", flush=True) - try: - print(f"DEBUG_STREAM [{id}]: Response Headers: {http_err.response.headers}", flush=True) - print(f"DEBUG_STREAM [{id}]: Response Body keys: {http_err.response.text[:200]}", flush=True) - except: - pass - + print(f"Stream Error: {error_details}") # If 403/404/410, invalidate cache if http_err.response.status_code in [403, 404, 410]: - print(f"DEBUG_STREAM [{id}]: Invalidating cache key {cache_key}", flush=True) cache.delete(cache_key) raise HTTPException(status_code=500, detail=error_details) except Exception as e: - print(f"DEBUG_STREAM [{id}]: Connection Failed: {e}", flush=True) - import traceback - traceback.print_exc() + print(f"Stream Connection Error: {e}") raise HTTPException(status_code=500, detail=f"Stream connection failed: {str(e)}") # Forward Content-Length if available headers = {} if "Content-Length" in external_req.headers: headers["Content-Length"] = external_req.headers["Content-Length"] - print(f"DEBUG_STREAM [{id}]: Content-Length: {headers['Content-Length']}", flush=True) def iterfile(): try: @@ -725,9 +711,7 @@ async def stream_audio(id: str): for chunk in external_req.iter_content(chunk_size=64*1024): yield chunk external_req.close() - print(f"DEBUG_STREAM [{id}]: Stream finished successfully", flush=True) except Exception as e: - print(f"DEBUG_STREAM [{id}]: Stream Iterator Error: {e}", flush=True) pass return StreamingResponse(iterfile(), media_type=mime_type, headers=headers)