From c1ed966596180fc584d1cf4fe305c578c3846a69 Mon Sep 17 00:00:00 2001 From: projectdx Date: Sat, 3 Jan 2026 20:24:56 +0900 Subject: [PATCH] fix: Zendriver browser binary detection in Docker --- info.yaml | 2 +- lib/zendriver_daemon.py | 40 ++++++++++++++++++++++++++++++++++++++-- lib/zendriver_ohli24.py | 35 ++++++++++++++++++++++++++++++++++- mod_ohli24.py | 8 ++++++++ 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/info.yaml b/info.yaml index 420219f..d01cf1d 100644 --- a/info.yaml +++ b/info.yaml @@ -1,5 +1,5 @@ title: "애니 다운로더" -version: "0.5.2" +version: "0.5.3" package_name: "anime_downloader" developer: "projectdx" description: "anime downloader" diff --git a/lib/zendriver_daemon.py b/lib/zendriver_daemon.py index d804ba7..7d8d435 100644 --- a/lib/zendriver_daemon.py +++ b/lib/zendriver_daemon.py @@ -37,6 +37,34 @@ browser_lock: Lock = Lock() loop: Optional[asyncio.AbstractEventLoop] = None +def find_browser_executable() -> Optional[str]: + """시스템에서 브라우저 실행 파일 찾기 (Docker/Ubuntu 환경 대응)""" + common_paths: List[str] = [ + "/usr/bin/google-chrome", + "/usr/bin/google-chrome-stable", + "/usr/bin/chromium-browser", + "/usr/bin/chromium", + "/usr/lib/chromium-browser/chromium-browser", + "google-chrome", # PATH에서 찾기 + "chromium-browser", + "chromium", + ] + + # 먼저 절대 경로 확인 + for path in common_paths: + if path.startswith("/") and os.path.exists(path): + return path + + # shutil.which로 PATH 확인 + import shutil + for cmd in ["google-chrome", "google-chrome-stable", "chromium-browser", "chromium"]: + found = shutil.which(cmd) + if found: + return found + + return None + + class ZendriverHandler(BaseHTTPRequestHandler): """HTTP 요청 핸들러""" @@ -121,8 +149,16 @@ async def ensure_browser() -> Any: try: import zendriver as zd log_debug("[ZendriverDaemon] Starting new browser instance...") - # zendriver.start()는 브라우저를 시작하고 첫 번째 페이지를 반환할 수 있음 - browser = await zd.start(headless=True) + + # 실행 가능한 브라우저 찾기 + exec_path = find_browser_executable() + if exec_path: + log_debug(f"[ZendriverDaemon] Found browser at: {exec_path}") + browser = await zd.start(headless=True, browser_executable_path=exec_path) + else: + log_debug("[ZendriverDaemon] No explicit browser path found, trying default") + browser = await zd.start(headless=True) + log_debug("[ZendriverDaemon] Browser started successfully") except Exception as e: log_debug(f"[ZendriverDaemon] Failed to start browser: {e}") diff --git a/lib/zendriver_ohli24.py b/lib/zendriver_ohli24.py index 2a77eb2..dcbd40d 100644 --- a/lib/zendriver_ohli24.py +++ b/lib/zendriver_ohli24.py @@ -10,6 +10,32 @@ Zendriver 기반 Ohli24 HTML 페칭 스크립트 import sys import json import asyncio +import os +import shutil + + +def find_browser_executable(): + """시스템에서 브라우저 실행 파일 찾기 (Docker/Ubuntu 환경 대응)""" + common_paths = [ + "/usr/bin/google-chrome", + "/usr/bin/google-chrome-stable", + "/usr/bin/chromium-browser", + "/usr/bin/chromium", + "/usr/lib/chromium-browser/chromium-browser", + ] + + # 먼저 절대 경로 확인 + for path in common_paths: + if os.path.exists(path): + return path + + # shutil.which로 PATH 확인 + for cmd in ["google-chrome", "google-chrome-stable", "chromium-browser", "chromium"]: + found = shutil.which(cmd) + if found: + return found + + return None async def fetch_html(url: str, timeout: int = 60) -> dict: @@ -24,8 +50,15 @@ async def fetch_html(url: str, timeout: int = 60) -> dict: browser = None try: + # 실행 가능한 브라우저 찾기 + exec_path = find_browser_executable() + # 브라우저 시작 - browser = await zd.start(headless=True) + if exec_path: + browser = await zd.start(headless=True, browser_executable_path=exec_path) + else: + browser = await zd.start(headless=True) + page = await browser.get(url) # 페이지 로드 대기 (DOM 안정화) diff --git a/mod_ohli24.py b/mod_ohli24.py index 853e2f1..70772dd 100644 --- a/mod_ohli24.py +++ b/mod_ohli24.py @@ -136,6 +136,14 @@ class LogicOhli24(AnimeModuleBase): if result.returncode == 0: cls.zendriver_setup_done = True logger.info("[Zendriver] Successfully installed") + + # 브라우저 존재 확인 안내 + import shutil + has_browser = any(shutil.which(cmd) for cmd in ["google-chrome", "google-chrome-stable", "chromium-browser", "chromium"]) + if not has_browser: + logger.warning("[Zendriver] 브라우저(Chrome/Chromium)가 시스템에 설치되어 있지 않습니다. Docker 환경에서는 직접 설치가 필요할 수 있습니다.") + logger.warning("[Zendriver] Ubuntu Tip: apt-get update && apt-get install -y chromium-browser") + return True else: logger.warning(f"[Zendriver] Installation failed: {result.stderr[:200]}")