From a24aa76459de6b378b425dc69c37f910ca882cd8 Mon Sep 17 00:00:00 2001 From: projectdx Date: Sat, 3 Jan 2026 20:52:39 +0900 Subject: [PATCH] v0.5.5: Automate Zendriver system browser installation and dependency check --- info.yaml | 2 +- mod_ohli24.py | 85 +++++++++++++++ .../anime_downloader_ohli24_setting.html | 102 +++++++++++++++++- 3 files changed, 187 insertions(+), 2 deletions(-) diff --git a/info.yaml b/info.yaml index 4ad62a5..a3dc606 100644 --- a/info.yaml +++ b/info.yaml @@ -1,5 +1,5 @@ title: "애니 다운로더" -version: "0.5.4" +version: "0.5.5" package_name: "anime_downloader" developer: "projectdx" description: "anime downloader" diff --git a/mod_ohli24.py b/mod_ohli24.py index e038655..c68ac1f 100644 --- a/mod_ohli24.py +++ b/mod_ohli24.py @@ -229,6 +229,85 @@ class LogicOhli24(AnimeModuleBase): except Exception as e: return {"success": False, "error": str(e)} + @classmethod + def system_check(cls) -> Dict[str, Any]: + """시스템 의존성 확인 (브라우저 등)""" + import shutil + import platform + + res = { + "browser_found": False, + "browser_path": "", + "os": platform.system(), + "dist": "", + "can_install": False, + "install_cmd": "apt-get update && apt-get install -y chromium-browser" + } + + # 브라우저 찾기 + manual_path = P.ModelSetting.get("ohli24_zendriver_browser_path") + if manual_path and os.path.exists(manual_path): + res["browser_found"] = True + res["browser_path"] = manual_path + else: + for cmd in ["google-chrome", "google-chrome-stable", "chromium-browser", "chromium"]: + found = shutil.which(cmd) + if found: + res["browser_found"] = True + res["browser_path"] = found + break + + # OS 및 설치 가능 여부 확인 + if res["os"] == "Linux": + try: + if os.path.exists("/etc/debian_version"): + res["dist"] = "debian/ubuntu" + res["can_install"] = True + except: + pass + + return res + + @classmethod + def install_system_browser(cls) -> Dict[str, Any]: + """시스템 브라우저 자동 설치 (Ubuntu/Debian 전용)""" + import subprocess as sp + + check = cls.system_check() + if not check["can_install"]: + return {"ret": "error", "msg": "자동 설치가 지원되지 않는 OS 환경입니다. 안내된 명령어를 터미널에서 직접 실행해 주세요."} + + try: + logger.info("[Zendriver] Starting system browser installation...") + # apt-get update + sp.run(["apt-get", "update"], capture_output=True, text=True, timeout=300) + + # apt-get install + process = sp.run( + ["apt-get", "install", "-y", "chromium-browser"], + capture_output=True, + text=True, + timeout=600 + ) + + if process.returncode == 0: + logger.info("[Zendriver] System browser installed successfully") + # 설치 후 다시 찾기 + new_check = cls.system_check() + if new_check["browser_found"]: + P.ModelSetting.set("ohli24_zendriver_browser_path", new_check["browser_path"]) + return {"ret": "success", "msg": "브라우저 설치 및 경로 설정이 완료되었습니다.", "path": new_check["browser_path"]} + return {"ret": "success", "msg": "설치는 완료되었으나 경로를 자동으로 찾지 못했습니다. 직접 입력해 주세요."} + else: + logger.error(f"[Zendriver] Installation failed: {process.stderr}") + return {"ret": "error", "msg": f"설치 중 오류가 발생했습니다: {process.stderr[:200]}"} + + except sp.TimeoutExpired: + return {"ret": "error", "msg": "설치 시간이 초과되었습니다. 네트워크 상태를 확인하거나 터미널에서 직접 실행해 주세요."} + except Exception as e: + logger.error(f"[Zendriver] Install exception: {e}") + return {"ret": "error", "msg": f"설치 중 예외가 발생했습니다: {str(e)}"} + def __init__(self, P: Any) -> None: self.name: str = name @@ -432,6 +511,12 @@ class LogicOhli24(AnimeModuleBase): logger.error(traceback.format_exc()) return jsonify({"error": str(e)}), 500 + elif sub == "system_check": + return jsonify(self.system_check()) + + elif sub == "install_browser": + return jsonify(self.install_system_browser()) + elif sub == "stream_video": # 비디오 스트리밍 (MP4 파일 직접 서빙) try: diff --git a/templates/anime_downloader_ohli24_setting.html b/templates/anime_downloader_ohli24_setting.html index e78c0ab..30d20fa 100644 --- a/templates/anime_downloader_ohli24_setting.html +++ b/templates/anime_downloader_ohli24_setting.html @@ -78,9 +78,37 @@ {{ macros.setting_buttons([['global_one_execute_btn', '1회 실행']], left='1회 실행' ) }}
{{ macros.setting_buttons([['global_reset_db_btn', 'DB 초기화']], left='DB정리' ) }} +
+ +
시스템 상태 및 의존성
+
+
+ Chromium/Chrome: + 확인 중... +
+
+ +
+
Zendriver 설정
- {{ macros.setting_input_text('ohli24_zendriver_browser_path', '브라우저 경로', value=arg.get('ohli24_zendriver_browser_path', ''), desc=['Zendriver가 사용할 Chrome/Chromium 실행 파일 경로입니다.', 'Docker 환경에서 자동 탐지에 실패할 경우 직접 입력하세요.', '예: /usr/bin/chromium-browser']) }} + {{ macros.setting_input_text('ohli24_zendriver_browser_path', '브라우저 경로', value=arg.get('ohli24_zendriver_browser_path', ''), desc=['Zendriver가 사용할 Chrome/Chromium 실행 파일 경로입니다.', '위의 시스템 상태에서 자동으로 찾은 경우 비워두셔도 됩니다 (수동 설정 시 우선 적용).']) }} {{ macros.m_tab_content_end() }} @@ -567,6 +595,78 @@ function escapeHtml(text) { return div.innerHTML; } +// ====================================== +// 시스템 체크 및 브라우저 설치 +// ====================================== +function runSystemCheck() { + $.ajax({ + url: '/' + package_name + '/ajax/' + sub + '/system_check', + type: 'POST', + success: function(ret) { + if (ret.browser_found) { + $('#browser_status_badge').removeClass('badge-secondary badge-danger').addClass('badge-success').text('발견됨'); + $('#browser_path_display').text('경로: ' + ret.browser_path); + $('#install_guide_section').hide(); + } else { + $('#browser_status_badge').removeClass('badge-secondary badge-success').addClass('badge-danger').text('미설치'); + $('#browser_path_display').text(''); + $('#install_guide_section').show(); + $('#manual_install_cmd').val(ret.install_cmd); + if (ret.can_install) { + $('#auto_install_div').show(); + } else { + $('#auto_install_div').hide(); + } + } + } + }); +} + +// 자동 설치 버튼 +$('#auto_install_btn').on('click', function() { + if (!confirm('시스템 브라우저 설치를 시작하시겠습니까?\n(Ubuntu/Debian 기반 도커 환경에서만 작동합니다)')) return; + + var btn = $(this); + btn.prop('disabled', true).html('설치 중 (최대 10분 소요)...'); + + $.ajax({ + url: '/' + package_name + '/ajax/' + sub + '/install_browser', + type: 'POST', + success: function(ret) { + if (ret.ret === 'success') { + $.notify(ret.msg, {type: 'success'}); + if (ret.path) { + $('#ohli24_zendriver_browser_path').val(ret.path); + } + runSystemCheck(); + } else { + $.notify(ret.msg, {type: 'danger'}); + } + }, + error: function() { + $.notify('설치 요청 중 오류가 발생했습니다.', {type: 'danger'}); + }, + complete: function() { + btn.prop('disabled', false).html('자동 설치 (Ubuntu/Docker)'); + } + }); +}); + +// 명령어 복사 버튼 +$('#copy_cmd_btn').on('click', function() { + var copyText = document.getElementById("manual_install_cmd"); + copyText.select(); + copyText.setSelectionRange(0, 99999); + document.execCommand("copy"); + $.notify('명령어가 복사되었습니다.', {type: 'info'}); +}); + +// 초기 실행 +$(document).ready(function() { + // Action 탭이 활성화될 때 체크 (또는 그냥 로딩 시 한 번) + runSystemCheck(); +}); + {% endblock %} \ No newline at end of file