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>
This commit is contained in:
sm4640
2026-03-24 16:23:51 +09:00
parent d4bd508618
commit 11852bf48c

View File

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