Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8c9c592cf | ||
|
|
98cd620f23 | ||
|
|
5e8e10e2fa | ||
|
|
af0e2fca8a |
4
.github/workflows/deploy.yml
vendored
4
.github/workflows/deploy.yml
vendored
@@ -90,10 +90,10 @@ jobs:
|
|||||||
IMAGE="${DOCKERHUB_USER}/${IMAGE_NAME}:latest"
|
IMAGE="${DOCKERHUB_USER}/${IMAGE_NAME}:latest"
|
||||||
if [ -n "${VERSION_TAG}" ]; then
|
if [ -n "${VERSION_TAG}" ]; then
|
||||||
VERSIONED_IMAGE="${DOCKERHUB_USER}/${IMAGE_NAME}:${VERSION_TAG}"
|
VERSIONED_IMAGE="${DOCKERHUB_USER}/${IMAGE_NAME}:${VERSION_TAG}"
|
||||||
docker build -t "${IMAGE}" -t "${VERSIONED_IMAGE}" .
|
docker build --no-cache -t "${IMAGE}" -t "${VERSIONED_IMAGE}" .
|
||||||
docker push "${VERSIONED_IMAGE}"
|
docker push "${VERSIONED_IMAGE}"
|
||||||
else
|
else
|
||||||
docker build -t "${IMAGE}" .
|
docker build --no-cache -t "${IMAGE}" .
|
||||||
fi
|
fi
|
||||||
|
|
||||||
docker push "${IMAGE}"
|
docker push "${IMAGE}"
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
17
app/main.py
17
app/main.py
@@ -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)}
|
||||||
|
|
||||||
|
|||||||
@@ -23,10 +23,6 @@ def fetch_transcript(video_id: str) -> str:
|
|||||||
|
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
"skip_download": True,
|
"skip_download": True,
|
||||||
"writeautomaticsub": True,
|
|
||||||
"subtitleslangs": ["ko", "en"],
|
|
||||||
"subtitlesformat": "json3",
|
|
||||||
"format": "worst",
|
|
||||||
"quiet": True,
|
"quiet": True,
|
||||||
"no_warnings": True,
|
"no_warnings": True,
|
||||||
}
|
}
|
||||||
@@ -38,7 +34,7 @@ def fetch_transcript(video_id: str) -> str:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
||||||
info = ydl.extract_info(url, download=False)
|
info = ydl.extract_info(url, ie_key="Youtube", download=False, process=False)
|
||||||
finally:
|
finally:
|
||||||
if "cookiefile" in ydl_opts:
|
if "cookiefile" in ydl_opts:
|
||||||
os.unlink(ydl_opts["cookiefile"])
|
os.unlink(ydl_opts["cookiefile"])
|
||||||
|
|||||||
Reference in New Issue
Block a user