From 11852bf48c1328be2784eea4b2336cb908ec56f0 Mon Sep 17 00:00:00 2001 From: sm4640 Date: Tue, 24 Mar 2026 16:23:51 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20[2.0.4]=20=EC=BF=A0=ED=82=A4=20read-only?= =?UTF-8?q?=20=EB=A7=88=EC=9A=B4=ED=8A=B8=20=EB=B0=8F=20=ED=8F=AC=EB=A7=B7?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 쿠키 파일을 임시 파일에 복사하여 yt-dlp 쓰기 가능하도록 처리 - format: worst 추가하여 포맷 선택 에러 방지 Co-Authored-By: Claude Opus 4.6 --- app/transcript.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/app/transcript.py b/app/transcript.py index 10f9693..0b686e9 100644 --- a/app/transcript.py +++ b/app/transcript.py @@ -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