Fix: [2.0.10] 라이브/쇼츠 스킵 및 네트워크 타임아웃 설정
All checks were successful
news-summary-bot-cicd / build_push_deploy (push) Successful in 18m49s
All checks were successful
news-summary-bot-cicd / build_push_deploy (push) Successful in 18m49s
- 라이브/쇼츠 영상 감지 시 에러 대신 스킵 처리 - yt-dlp socket_timeout, httpx timeout, Discord webhook timeout 30초로 설정 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -104,7 +104,7 @@ async def send_to_discord(title: str, video_url: str, summary: str) -> None:
|
|||||||
|
|
||||||
payload = {"embeds": [embed]}
|
payload = {"embeds": [embed]}
|
||||||
|
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient(timeout=30.0) 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()
|
||||||
|
|
||||||
@@ -131,5 +131,5 @@ async def send_error_to_discord(
|
|||||||
|
|
||||||
payload = {"embeds": [embed]}
|
payload = {"embeds": [embed]}
|
||||||
|
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient(timeout=30.0) as client:
|
||||||
await client.post(settings.discord_webhook_url, json=payload)
|
await client.post(settings.discord_webhook_url, json=payload)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from pydantic import BaseModel
|
|||||||
from app.config import settings
|
from app.config import settings
|
||||||
from app.discord import send_error_to_discord, 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 SkipVideo, extract_video_id, fetch_transcript
|
||||||
|
|
||||||
app = FastAPI(title="News Summary Bot")
|
app = FastAPI(title="News Summary Bot")
|
||||||
|
|
||||||
@@ -29,6 +29,8 @@ async def summarize_video(
|
|||||||
transcript = fetch_transcript(video_id)
|
transcript = fetch_transcript(video_id)
|
||||||
summary = summarize(transcript, title)
|
summary = summarize(transcript, title)
|
||||||
await send_to_discord(title, req.video_url, summary)
|
await send_to_discord(title, req.video_url, summary)
|
||||||
|
except SkipVideo as e:
|
||||||
|
return {"status": "skipped", "title": title, "reason": str(e)}
|
||||||
except Exception as 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)
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|||||||
@@ -8,8 +8,14 @@ import yt_dlp
|
|||||||
COOKIES_SRC = "/app/cookies.txt"
|
COOKIES_SRC = "/app/cookies.txt"
|
||||||
|
|
||||||
|
|
||||||
|
class SkipVideo(Exception):
|
||||||
|
"""라이브/쇼츠 등 요약 대상이 아닌 영상."""
|
||||||
|
|
||||||
|
|
||||||
def extract_video_id(url: str) -> str:
|
def extract_video_id(url: str) -> str:
|
||||||
"""YouTube URL에서 video ID 추출."""
|
"""YouTube URL에서 video ID 추출."""
|
||||||
|
if "/shorts/" in url:
|
||||||
|
raise SkipVideo("쇼츠 영상은 요약 대상이 아닙니다")
|
||||||
if "youtu.be/" in url:
|
if "youtu.be/" in url:
|
||||||
return url.split("youtu.be/")[1].split("?")[0]
|
return url.split("youtu.be/")[1].split("?")[0]
|
||||||
if "v=" in url:
|
if "v=" in url:
|
||||||
@@ -25,6 +31,7 @@ def fetch_transcript(video_id: str) -> str:
|
|||||||
"skip_download": True,
|
"skip_download": True,
|
||||||
"quiet": True,
|
"quiet": True,
|
||||||
"no_warnings": True,
|
"no_warnings": True,
|
||||||
|
"socket_timeout": 30,
|
||||||
}
|
}
|
||||||
|
|
||||||
if os.path.isfile(COOKIES_SRC):
|
if os.path.isfile(COOKIES_SRC):
|
||||||
@@ -39,6 +46,9 @@ def fetch_transcript(video_id: str) -> str:
|
|||||||
if "cookiefile" in ydl_opts:
|
if "cookiefile" in ydl_opts:
|
||||||
os.unlink(ydl_opts["cookiefile"])
|
os.unlink(ydl_opts["cookiefile"])
|
||||||
|
|
||||||
|
if info.get("is_live") or info.get("live_status") in ("is_live", "is_upcoming"):
|
||||||
|
raise SkipVideo("라이브/예정 영상은 요약 대상이 아닙니다")
|
||||||
|
|
||||||
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
|
||||||
if not lang:
|
if not lang:
|
||||||
@@ -53,7 +63,7 @@ def fetch_transcript(video_id: str) -> str:
|
|||||||
if not sub_url:
|
if not sub_url:
|
||||||
raise ValueError(f"json3 자막 포맷을 찾을 수 없습니다: {video_id}")
|
raise ValueError(f"json3 자막 포맷을 찾을 수 없습니다: {video_id}")
|
||||||
|
|
||||||
resp = httpx.get(sub_url)
|
resp = httpx.get(sub_url, timeout=30.0)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user