jebin2 commited on
Commit
719ce21
·
1 Parent(s): e213765
Files changed (1) hide show
  1. routers/gemini.py +21 -5
routers/gemini.py CHANGED
@@ -426,11 +426,27 @@ async def download_video(
426
  # Stream video directly from Gemini URL to client
427
  # No local file storage needed
428
  async def stream_video():
429
- async with httpx.AsyncClient(timeout=120.0, follow_redirects=True) as client:
430
- async with client.stream("GET", video_url) as response:
431
- response.raise_for_status()
432
- async for chunk in response.aiter_bytes(chunk_size=8192):
433
- yield chunk
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
434
 
435
  return StreamingResponse(
436
  stream_video(),
 
426
  # Stream video directly from Gemini URL to client
427
  # No local file storage needed
428
  async def stream_video():
429
+ try:
430
+ async with httpx.AsyncClient(timeout=120.0, follow_redirects=True) as client:
431
+ async with client.stream("GET", video_url) as response:
432
+ response.raise_for_status()
433
+ async for chunk in response.aiter_bytes(chunk_size=8192):
434
+ yield chunk
435
+ except httpx.HTTPStatusError as e:
436
+ if e.response.status_code in (401, 403, 404, 410):
437
+ raise HTTPException(
438
+ status_code=status.HTTP_410_GONE,
439
+ detail="Video URL has expired. Please generate a new video."
440
+ )
441
+ raise HTTPException(
442
+ status_code=status.HTTP_502_BAD_GATEWAY,
443
+ detail=f"Failed to fetch video from source: {e.response.status_code}"
444
+ )
445
+ except Exception as e:
446
+ raise HTTPException(
447
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
448
+ detail=f"Failed to stream video: {str(e)}"
449
+ )
450
 
451
  return StreamingResponse(
452
  stream_video(),