v0.6.10: Fix Ohli24 GDM integration and update README

This commit is contained in:
2026-01-07 15:09:04 +09:00
parent 759f772ca8
commit c532ffaef8
7 changed files with 368 additions and 191 deletions

View File

@@ -15,31 +15,49 @@ import shutil
def find_browser_executable(manual_path=None):
"""시스템에서 브라우저 실행 파일 찾기 (Docker/Ubuntu 환경 대응)"""
"""시스템에서 브라우저 실행 파일 찾기 (OS별 대응)"""
import platform
# 수동 설정 시 우선
if manual_path and os.path.exists(manual_path):
return manual_path
common_paths = [
"/usr/bin/google-chrome",
"/usr/bin/google-chrome-stable",
"/usr/bin/chromium-browser",
"/usr/bin/chromium",
"/usr/lib/chromium-browser/chromium-browser",
]
system = platform.system()
app_dirs = ["/Applications", "/Volumes/WD/Users/Applications"]
common_paths = []
# 먼저 절대 경로 확인
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"]:
if system == "Darwin": # Mac
for base in app_dirs:
common_paths.extend([
f"{base}/Google Chrome.app/Contents/MacOS/Google Chrome",
f"{base}/Chromium.app/Contents/MacOS/Chromium",
f"{base}/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
])
elif system == "Windows":
common_paths = [
os.path.expandvars(r"%ProgramFiles%\Google\Chrome\Application\chrome.exe"),
os.path.expandvars(r"%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe"),
os.path.expandvars(r"%LocalAppData%\Google\Chrome\Application\chrome.exe"),
]
else: # Linux/Other
common_paths = [
"/usr/bin/google-chrome",
"/usr/bin/google-chrome-stable",
"/usr/bin/chromium-browser",
"/usr/bin/chromium",
"/usr/lib/chromium-browser/chromium-browser",
]
# 존재하는 모든 후보들 반환
candidates = [p for p in common_paths if os.path.exists(p)]
# PATH에서 찾기 추가
for cmd in ["google-chrome", "google-chrome-stable", "chromium-browser", "chromium", "chrome", "microsoft-edge"]:
found = shutil.which(cmd)
if found:
return found
if found and found not in candidates:
candidates.append(found)
return None
return candidates
async def fetch_html(url: str, timeout: int = 60, browser_path: str = None) -> dict:
@@ -53,63 +71,112 @@ async def fetch_html(url: str, timeout: int = 60, browser_path: str = None) -> d
start_time = asyncio.get_event_loop().time()
browser = None
try:
# 실행 가능한 브라우저 찾기
exec_path = find_browser_executable(browser_path)
# 실행 가능한 브라우저 후보들 찾기
candidates = find_browser_executable(browser_path)
if not candidates:
return {"success": False, "error": "No browser executable found", "html": ""}
# 브라우저 시작
if exec_path:
# 사용자 데이터 디렉토리 설정 (Mac/Root 권한 이슈 대응)
import tempfile
uid = os.getuid() if hasattr(os, 'getuid') else 'win'
# 공통 브라우저 인자
browser_args = [
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-dev-shm-usage",
"--disable-gpu",
"--no-first-run",
"--no-service-autorun",
"--password-store=basic",
"--mute-audio",
"--disable-notifications",
"--disable-background-networking",
"--disable-background-timer-throttling",
"--disable-backgrounding-occluded-windows",
"--disable-breakpad",
"--disable-client-side-phishing-detection",
"--disable-default-apps",
"--disable-hang-monitor",
"--disable-popup-blocking",
"--disable-prompt-on-repost",
"--disable-sync",
"--disable-translate",
"--metrics-recording-only",
"--no-default-browser-check",
"--safebrowsing-disable-auto-update",
"--remote-allow-origins=*",
"--blink-settings=imagesEnabled=false",
]
last_error = "All candidates failed"
# 여러 브라우저 후보들 시도 (크롬이 이미 실행 중일 때 등의 상황 대비)
for exec_path in candidates:
browser = None
user_data_dir = os.path.join(tempfile.gettempdir(), f"zd_ohli_{uid}_{os.path.basename(exec_path).replace(' ', '_')}")
os.makedirs(user_data_dir, exist_ok=True)
try:
# 브라우저 시작
browser = await zd.start(
headless=True,
browser_executable_path=exec_path,
no_sandbox=True,
browser_args=["--no-sandbox", "--disable-setuid-sandbox", "--disable-dev-shm-usage", "--disable-gpu", "--no-first-run"]
)
else:
browser = await zd.start(
headless=True,
no_sandbox=True,
browser_args=["--no-sandbox", "--disable-setuid-sandbox", "--disable-dev-shm-usage", "--disable-gpu", "--no-first-run"]
user_data_dir=user_data_dir,
browser_args=browser_args
)
page = await browser.get(url)
# 페이지 로드 대기 - cdndania iframe 로딩될 때까지 폴링 (최대 15초)
max_wait = 15
poll_interval = 1
waited = 0
html = ""
while waited < max_wait:
await asyncio.sleep(poll_interval)
waited += poll_interval
html = await page.get_content()
page = await browser.get(url)
# cdndania iframe이 로드되었는지 확인
if "cdndania" in html or "fireplayer" in html:
break
elapsed = asyncio.get_event_loop().time() - start_time
if html and len(html) > 100:
result.update({
"success": True,
"html": html,
"elapsed": round(elapsed, 2)
})
else:
result["error"] = f"Short response: {len(html) if html else 0} bytes"
result["elapsed"] = round(elapsed, 2)
# 페이지 로드 대기 - 지능형 폴링 (최대 10초)
# 1. 리스트 페이지는 바로 반환, 2. 에피소드 페이지는 플레이어 로딩 대기
max_wait = 10
poll_interval = 0.2 # 1.0s -> 0.2s로 단축하여 반응속도 향상
waited = 0
html = ""
while waited < max_wait:
await asyncio.sleep(poll_interval)
waited += poll_interval
html = await page.get_content()
except Exception as e:
result["error"] = str(e)
result["elapsed"] = round(asyncio.get_event_loop().time() - start_time, 2)
finally:
if browser:
try:
# 리스트 페이지 마커 확인 (발견 즉시 탈출)
if "post-list" in html or "list-box" in html or "post-row" in html:
# log_debug(f"[Zendriver] List page detected in {waited:.1f}s")
break
# cdndania/fireplayer iframe이 로드되었는지 확인 (에피소드 페이지)
if "cdndania" in html or "fireplayer" in html:
# log_debug(f"[Zendriver] Player detected in {waited:.1f}s")
break
elapsed = asyncio.get_event_loop().time() - start_time
if html and len(html) > 100:
result.update({
"success": True,
"html": html,
"elapsed": round(elapsed, 2)
})
# 성공했으므로 루프 종료
await browser.stop()
except:
pass
return result
else:
last_error = f"Short response from {exec_path}: {len(html) if html else 0} bytes"
except Exception as e:
last_error = f"Failed with {exec_path}: {str(e)}"
finally:
if browser:
try:
await browser.stop()
except:
pass
result["error"] = last_error
result["elapsed"] = round(asyncio.get_event_loop().time() - start_time, 2)
return result
return result