Fix: [2.0.11] 라이브 DownloadError 스킵 처리 및 채널명 표시
All checks were successful
news-summary-bot-cicd / build_push_deploy (push) Successful in 12m11s

- yt-dlp DownloadError에서 라이브/프리미어 감지 시 SkipVideo로 변환 (500 방지)
- channel_name 필드 추가로 Discord 알림에 채널명(머니코믹스/슈카월드) 표시

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
sm4640
2026-03-25 13:18:12 +09:00
parent da9e557c64
commit 22949d0602
3 changed files with 32 additions and 14 deletions

View File

@@ -46,7 +46,9 @@ def _parse_summary(summary: str) -> dict[str, str]:
return sections
async def send_to_discord(title: str, video_url: str, summary: str) -> None:
async def send_to_discord(
title: str, video_url: str, summary: str, channel_name: str = ""
) -> None:
"""Discord 웹훅으로 요약 전송 (임베드 디자인)."""
video_id = _extract_video_id(video_url)
thumbnail_url = (
@@ -86,14 +88,16 @@ async def send_to_discord(title: str, video_url: str, summary: str) -> None:
"inline": False,
})
embed_title = f"📰 [{channel_name}] {title}" if channel_name else f"📰 {title}"
embed = {
"title": f"📰 {title}",
"title": embed_title,
"url": video_url,
"description": description,
"color": 0x2B2D31,
"fields": fields,
"footer": {
"text": "YouTube 뉴스 요약 봇",
"text": f"YouTube 뉴스 요약 봇 • {channel_name}" if channel_name else "YouTube 뉴스 요약 봇",
"icon_url": "https://www.youtube.com/s/desktop/f5ced909/img/favicon_144x144.png",
},
"timestamp": datetime.now(timezone.utc).isoformat(),
@@ -110,22 +114,29 @@ async def send_to_discord(title: str, video_url: str, summary: str) -> None:
async def send_error_to_discord(
title: str, video_url: str, error: Exception
title: str, video_url: str, error: Exception, channel_name: str = ""
) -> None:
"""에러 발생 시 Discord 웹훅으로 에러 내용 전송."""
error_type = type(error).__name__
error_msg = str(error)[:1024]
error_title = f"❌ [{channel_name}] 뉴스 요약 실패" if channel_name else "❌ 뉴스 요약 실패"
fields = []
if channel_name:
fields.append({"name": "채널", "value": channel_name, "inline": True})
fields.extend([
{"name": "영상 제목", "value": title or "(제목 없음)", "inline": False},
{"name": "영상 URL", "value": video_url, "inline": False},
{"name": "에러 타입", "value": f"`{error_type}`", "inline": True},
{"name": "에러 내용", "value": f"```\n{error_msg}\n```", "inline": False},
])
embed = {
"title": "❌ 뉴스 요약 실패",
"title": error_title,
"color": 0xED4245,
"fields": [
{"name": "영상 제목", "value": title or "(제목 없음)", "inline": False},
{"name": "영상 URL", "value": video_url, "inline": False},
{"name": "에러 타입", "value": f"`{error_type}`", "inline": True},
{"name": "에러 내용", "value": f"```\n{error_msg}\n```", "inline": False},
],
"footer": {"text": "YouTube 뉴스 요약 봇 - 에러 알림"},
"fields": fields,
"footer": {"text": f"YouTube 뉴스 요약 봇 - 에러 알림 • {channel_name}" if channel_name else "YouTube 뉴스 요약 봇 - 에러 알림"},
"timestamp": datetime.now(timezone.utc).isoformat(),
}

View File

@@ -12,6 +12,7 @@ app = FastAPI(title="News Summary Bot")
class SummarizeRequest(BaseModel):
video_url: str
title: str = ""
channel_name: str = ""
@app.post("/summarize")
@@ -23,16 +24,17 @@ async def summarize_video(
raise HTTPException(status_code=401, detail="Unauthorized")
title = req.title or "제목 없음"
channel_name = req.channel_name or ""
try:
video_id = extract_video_id(req.video_url)
transcript = fetch_transcript(video_id)
summary = summarize(transcript, title)
await send_to_discord(title, req.video_url, summary)
await send_to_discord(title, req.video_url, summary, channel_name)
except SkipVideo as e:
return {"status": "skipped", "title": title, "reason": str(e)}
except Exception as e:
await send_error_to_discord(title, req.video_url, e)
await send_error_to_discord(title, req.video_url, e, channel_name)
raise HTTPException(status_code=500, detail=str(e))
return {"status": "ok", "title": title, "summary_length": len(summary)}

View File

@@ -42,6 +42,11 @@ def fetch_transcript(video_id: str) -> str:
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, ie_key="Youtube", download=False, process=False)
except yt_dlp.utils.DownloadError as e:
err_msg = str(e).lower()
if "live event" in err_msg or "is live" in err_msg or "premieres in" in err_msg:
raise SkipVideo("라이브/예정 영상은 요약 대상이 아닙니다")
raise
finally:
if "cookiefile" in ydl_opts:
os.unlink(ydl_opts["cookiefile"])