fix: Zendriver browser binary detection in Docker
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
title: "애니 다운로더"
|
title: "애니 다운로더"
|
||||||
version: "0.5.2"
|
version: "0.5.3"
|
||||||
package_name: "anime_downloader"
|
package_name: "anime_downloader"
|
||||||
developer: "projectdx"
|
developer: "projectdx"
|
||||||
description: "anime downloader"
|
description: "anime downloader"
|
||||||
|
|||||||
@@ -37,6 +37,34 @@ browser_lock: Lock = Lock()
|
|||||||
loop: Optional[asyncio.AbstractEventLoop] = None
|
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):
|
class ZendriverHandler(BaseHTTPRequestHandler):
|
||||||
"""HTTP 요청 핸들러"""
|
"""HTTP 요청 핸들러"""
|
||||||
|
|
||||||
@@ -121,8 +149,16 @@ async def ensure_browser() -> Any:
|
|||||||
try:
|
try:
|
||||||
import zendriver as zd
|
import zendriver as zd
|
||||||
log_debug("[ZendriverDaemon] Starting new browser instance...")
|
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")
|
log_debug("[ZendriverDaemon] Browser started successfully")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log_debug(f"[ZendriverDaemon] Failed to start browser: {e}")
|
log_debug(f"[ZendriverDaemon] Failed to start browser: {e}")
|
||||||
|
|||||||
@@ -10,6 +10,32 @@ Zendriver 기반 Ohli24 HTML 페칭 스크립트
|
|||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import asyncio
|
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:
|
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
|
browser = None
|
||||||
|
|
||||||
try:
|
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)
|
page = await browser.get(url)
|
||||||
|
|
||||||
# 페이지 로드 대기 (DOM 안정화)
|
# 페이지 로드 대기 (DOM 안정화)
|
||||||
|
|||||||
@@ -136,6 +136,14 @@ class LogicOhli24(AnimeModuleBase):
|
|||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
cls.zendriver_setup_done = True
|
cls.zendriver_setup_done = True
|
||||||
logger.info("[Zendriver] Successfully installed")
|
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
|
return True
|
||||||
else:
|
else:
|
||||||
logger.warning(f"[Zendriver] Installation failed: {result.stderr[:200]}")
|
logger.warning(f"[Zendriver] Installation failed: {result.stderr[:200]}")
|
||||||
|
|||||||
Reference in New Issue
Block a user