2 Commits
2.0.3 ... 2.0.5

Author SHA1 Message Date
sm4640
af0e2fca8a Feat: [2.0.5] 에러 발생 시 Discord 알림 전송
Some checks failed
news-summary-bot-cicd / build_push_deploy (push) Failing after 3m42s
- 요약 처리 중 에러 발생 시 Discord에 에러 상세 내용 전송
- 에러 타입, 메시지, 영상 정보를 포함한 embed 형식

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 16:27:03 +09:00
sm4640
11852bf48c Fix: [2.0.4] 쿠키 read-only 마운트 및 포맷 에러 해결
Some checks failed
news-summary-bot-cicd / build_push_deploy (push) Has been cancelled
- 쿠키 파일을 임시 파일에 복사하여 yt-dlp 쓰기 가능하도록 처리
- format: worst 추가하여 포맷 선택 에러 방지

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 16:23:51 +09:00
3 changed files with 55 additions and 9 deletions

View File

@@ -107,3 +107,29 @@ async def send_to_discord(title: str, video_url: str, summary: str) -> None:
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
resp = await client.post(settings.discord_webhook_url, json=payload) resp = await client.post(settings.discord_webhook_url, json=payload)
resp.raise_for_status() resp.raise_for_status()
async def send_error_to_discord(
title: str, video_url: str, error: Exception
) -> None:
"""에러 발생 시 Discord 웹훅으로 에러 내용 전송."""
error_type = type(error).__name__
error_msg = str(error)[:1024]
embed = {
"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 뉴스 요약 봇 - 에러 알림"},
"timestamp": datetime.now(timezone.utc).isoformat(),
}
payload = {"embeds": [embed]}
async with httpx.AsyncClient() as client:
await client.post(settings.discord_webhook_url, json=payload)

View File

@@ -2,7 +2,7 @@ from fastapi import FastAPI, Header, HTTPException
from pydantic import BaseModel from pydantic import BaseModel
from app.config import settings from app.config import settings
from app.discord import send_to_discord from app.discord import send_error_to_discord, send_to_discord
from app.summarizer import summarize from app.summarizer import summarize
from app.transcript import extract_video_id, fetch_transcript from app.transcript import extract_video_id, fetch_transcript
@@ -22,11 +22,16 @@ async def summarize_video(
if settings.api_secret and x_api_secret != settings.api_secret: if settings.api_secret and x_api_secret != settings.api_secret:
raise HTTPException(status_code=401, detail="Unauthorized") raise HTTPException(status_code=401, detail="Unauthorized")
video_id = extract_video_id(req.video_url) title = req.title or "제목 없음"
transcript = fetch_transcript(video_id)
title = req.title or video_id try:
summary = summarize(transcript, title) video_id = extract_video_id(req.video_url)
await send_to_discord(title, req.video_url, summary) transcript = fetch_transcript(video_id)
summary = summarize(transcript, title)
await send_to_discord(title, req.video_url, summary)
except Exception as e:
await send_error_to_discord(title, req.video_url, e)
raise HTTPException(status_code=500, detail=str(e))
return {"status": "ok", "title": title, "summary_length": len(summary)} return {"status": "ok", "title": title, "summary_length": len(summary)}

View File

@@ -1,6 +1,12 @@
import os
import shutil
import tempfile
import httpx import httpx
import yt_dlp import yt_dlp
COOKIES_SRC = "/app/cookies.txt"
def extract_video_id(url: str) -> str: def extract_video_id(url: str) -> str:
"""YouTube URL에서 video ID 추출.""" """YouTube URL에서 video ID 추출."""
@@ -20,13 +26,22 @@ def fetch_transcript(video_id: str) -> str:
"writeautomaticsub": True, "writeautomaticsub": True,
"subtitleslangs": ["ko", "en"], "subtitleslangs": ["ko", "en"],
"subtitlesformat": "json3", "subtitlesformat": "json3",
"format": "worst",
"quiet": True, "quiet": True,
"no_warnings": True, "no_warnings": True,
"cookiefile": "/app/cookies.txt",
} }
with yt_dlp.YoutubeDL(ydl_opts) as ydl: if os.path.isfile(COOKIES_SRC):
info = ydl.extract_info(url, download=False) tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".txt")
shutil.copy2(COOKIES_SRC, tmp.name)
ydl_opts["cookiefile"] = tmp.name
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=False)
finally:
if "cookiefile" in ydl_opts:
os.unlink(ydl_opts["cookiefile"])
subs = info.get("automatic_captions", {}) subs = info.get("automatic_captions", {})
lang = "ko" if "ko" in subs else "en" if "en" in subs else None lang = "ko" if "ko" in subs else "en" if "en" in subs else None