INNER CODE UNIT · Python
proxy_thumbnail
liyupi/free-video-downloader · backend/main.py:130
async def proxy_thumbnail(url: str = Query(..., description="缩略图URL")):
"""代理获取视频缩略图,绕过防盗链"""
try:
async with httpx.AsyncClient(timeout=15, follow_redirects=True) as client:
resp = await client.get(url, headers={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
"Referer": url,
})
resp.raise_for_status()
content_type = resp.headers.get("content-type", "image/jpeg")
return StreamingResponse(
iter([resp.content]),
media_type=content_type,
headers={"Cache-Control": "public, max-age=86400"},
)
except Exception:
raise HTTPException(status_code=502, detail="缩略图加载失败")