mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-11-05 14:48:40 +08:00
refactor backend module architecture
This commit is contained in:
@@ -9,7 +9,7 @@ from types import SimpleNamespace
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(PROJECT_ROOT))
|
||||
|
||||
from app.core.context import MediaInfo, TorrentInfo
|
||||
from app.domain.context import MediaInfo, TorrentInfo
|
||||
from app.modules.filter import FilterModule
|
||||
from app.modules.filter.RuleParser import RuleParser
|
||||
|
||||
|
||||
@@ -9,9 +9,12 @@ from typing import Any, Callable, Optional
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(PROJECT_ROOT))
|
||||
|
||||
from app.core import metainfo as metainfo_module
|
||||
from app.core.meta import MetaAnime, MetaMusic
|
||||
from app.core.metainfo import MetaInfo, MetaInfoPath
|
||||
from app.domain import metainfo as metainfo_module
|
||||
from app.domain.meta.metaanime import MetaAnime
|
||||
from app.domain.meta.metamusic import MetaMusic
|
||||
from app.domain.meta.runtime import get_audio_extensions
|
||||
from app.domain.metainfo import MetaInfo, MetaInfoPath
|
||||
from app.infrastructure import rust as rust_accel
|
||||
from tests.cases.meta import meta_cases
|
||||
|
||||
|
||||
@@ -84,7 +87,6 @@ def selected_meta_parser(use_rust: bool):
|
||||
"find_metainfo",
|
||||
"parse_metamusic",
|
||||
)
|
||||
rust_accel = metainfo_module.rust_accel
|
||||
original_parsers = {
|
||||
name: getattr(rust_accel, name)
|
||||
for name in parser_names
|
||||
@@ -251,7 +253,6 @@ def benchmark_suite(
|
||||
|
||||
def validate_rust_runtime() -> None:
|
||||
"""确认 Rust 总开关和音乐扩展入口可用,拒绝静默回退形成伪基准。"""
|
||||
rust_accel = metainfo_module.rust_accel
|
||||
if not rust_accel.is_enabled():
|
||||
raise RuntimeError("Rust 加速未启用或 moviepilot-rust 扩展不可用")
|
||||
if not callable(getattr(rust_accel, "parse_metamusic", None)):
|
||||
|
||||
@@ -9,10 +9,10 @@ from types import SimpleNamespace
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(PROJECT_ROOT))
|
||||
|
||||
from app.helper import rss as rss_module
|
||||
from app.helper.rss import RssHelper
|
||||
from app.utils import rust_accel
|
||||
from app.utils.http import RequestUtils
|
||||
from app.infrastructure import rss as rss_module
|
||||
from app.infrastructure.rss import RssHelper
|
||||
from app.infrastructure import rust as rust_accel
|
||||
from app.foundation.http import RequestUtils
|
||||
|
||||
|
||||
class FakeRequestUtils:
|
||||
|
||||
@@ -8,7 +8,7 @@ from pathlib import Path
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from app.helper.package import PackageInstallRequest, build_package_install_strategies
|
||||
from app.infrastructure.package import PackageInstallRequest, build_package_install_strategies
|
||||
|
||||
|
||||
def sample(name: str, request: PackageInstallRequest) -> None:
|
||||
|
||||
@@ -7,7 +7,7 @@ import ast
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from app.helper.market import extract_plugin_market_repos_from_wiki
|
||||
from app.integrations.market import extract_plugin_market_repos_from_wiki
|
||||
|
||||
|
||||
OFFICIAL_PLUGIN_MARKET = "https://github.com/jxxghp/MoviePilot-Plugins"
|
||||
|
||||
@@ -28,7 +28,7 @@ from typing import Any, Optional
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
LEGACY_CONFIG_DIR = ROOT / "config"
|
||||
HELPER_DIR = ROOT / "app" / "helper"
|
||||
SITE_RESOURCE_DIR = ROOT / "app" / "infrastructure"
|
||||
PUBLIC_DIR = ROOT / "public"
|
||||
RUNTIME_DIR = ROOT / ".runtime"
|
||||
NODE_DIR = RUNTIME_DIR / "node"
|
||||
@@ -999,8 +999,10 @@ def install_frontend(frontend_version: str, node_version: str) -> dict[str, str]
|
||||
|
||||
|
||||
def local_resource_status() -> bool:
|
||||
return (HELPER_DIR / f"user.sites.{RESOURCE_VERSION_FLAG}.bin").exists() and bool(
|
||||
list(HELPER_DIR.glob("sites*"))
|
||||
return (
|
||||
SITE_RESOURCE_DIR / f"user.sites.{RESOURCE_VERSION_FLAG}.bin"
|
||||
).exists() and bool(
|
||||
list(SITE_RESOURCE_DIR.glob("sites*"))
|
||||
)
|
||||
|
||||
|
||||
@@ -1012,13 +1014,13 @@ def copy_resource_files(source_dir: Path) -> list[str]:
|
||||
for source in sorted(source_dir.iterdir()):
|
||||
if source.is_dir():
|
||||
continue
|
||||
target = HELPER_DIR / source.name
|
||||
target = SITE_RESOURCE_DIR / source.name
|
||||
shutil.copy2(source, target)
|
||||
copied.append(source.name)
|
||||
|
||||
if not copied:
|
||||
raise RuntimeError(f"资源目录中未找到可复制文件:{source_dir}")
|
||||
print_step(f"已同步资源文件到 {HELPER_DIR}")
|
||||
print_step(f"已同步资源文件到 {SITE_RESOURCE_DIR}")
|
||||
return copied
|
||||
|
||||
|
||||
@@ -2125,7 +2127,7 @@ def _load_auth_site_definitions_inner() -> dict[str, Any]:
|
||||
if str(ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from app.helper.sites import SitesHelper # noqa
|
||||
from app.infrastructure.sites import SitesHelper # noqa
|
||||
|
||||
auth_sites = SitesHelper().get_authsites() or {}
|
||||
definitions: dict[str, Any] = {}
|
||||
@@ -2462,7 +2464,7 @@ def _apply_local_system_config_inner(config_payload: dict[str, Any]) -> None:
|
||||
):
|
||||
system_config.set(SystemConfigKey.UserSiteAuthParams, site_auth_item)
|
||||
try:
|
||||
from app.helper.sites import SitesHelper # noqa
|
||||
from app.infrastructure.sites import SitesHelper # noqa
|
||||
|
||||
status, msg = SitesHelper().check_user(
|
||||
site_auth_item.get("site"), site_auth_item.get("params")
|
||||
@@ -2494,8 +2496,8 @@ def _ensure_superuser_account_inner() -> None:
|
||||
if str(ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from app.core.config import settings
|
||||
from app.core.security import get_password_hash
|
||||
from app.platform.config import settings
|
||||
from app.security.access import get_password_hash
|
||||
from app.db.user_oper import UserOper
|
||||
|
||||
username = str(settings.SUPERUSER or "").strip()
|
||||
@@ -2545,7 +2547,7 @@ def _ensure_superuser_account_inner() -> None:
|
||||
|
||||
|
||||
def _prepare_superuser_password_for_bootstrap() -> Optional[str]:
|
||||
from app.core.config import settings
|
||||
from app.platform.config import settings
|
||||
from app.db.user_oper import UserOper
|
||||
|
||||
username = str(settings.SUPERUSER or "").strip()
|
||||
@@ -3436,7 +3438,7 @@ def _remove_installed_resource_files() -> list[Path]:
|
||||
removed: list[Path] = []
|
||||
seen: set[Path] = set()
|
||||
for pattern in RESOURCE_FILE_PATTERNS:
|
||||
for path in sorted(HELPER_DIR.glob(pattern)):
|
||||
for path in sorted(SITE_RESOURCE_DIR.glob(pattern)):
|
||||
if path in seen or not path.exists() or path.is_dir():
|
||||
continue
|
||||
_remove_path(path)
|
||||
@@ -3487,7 +3489,10 @@ def uninstall_local(
|
||||
print(f" - 删除虚拟环境:{venv_dir}")
|
||||
print(f" - 删除前端运行时目录:{PUBLIC_DIR}")
|
||||
print(f" - 删除本地 Node 运行时目录:{RUNTIME_DIR}")
|
||||
print(f" - 删除资源文件:{HELPER_DIR}/sites*、{HELPER_DIR}/user.sites*.bin")
|
||||
print(
|
||||
f" - 删除资源文件:{SITE_RESOURCE_DIR}/sites*、"
|
||||
f"{SITE_RESOURCE_DIR}/user.sites*.bin"
|
||||
)
|
||||
if linked_cli_paths:
|
||||
print(" - 删除全局 CLI 软链接:")
|
||||
for path in linked_cli_paths:
|
||||
@@ -3668,7 +3673,7 @@ def run_agent_request(
|
||||
try:
|
||||
from app.db.init import init_db, update_db
|
||||
from app.agent import MoviePilotAgent
|
||||
from app.core.config import settings
|
||||
from app.platform.config import settings
|
||||
except ModuleNotFoundError as exc:
|
||||
raise RuntimeError(
|
||||
"当前环境尚未安装 MoviePilot 运行依赖,请先执行 moviepilot install deps 或 moviepilot setup"
|
||||
@@ -3732,7 +3737,7 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
)
|
||||
|
||||
resources_parser = subparsers.add_parser(
|
||||
"install-resources", help="下载资源文件并同步到 app/helper"
|
||||
"install-resources", help="下载资源文件并同步到 app/infrastructure"
|
||||
)
|
||||
resources_parser.add_argument(
|
||||
"--resources-repo", help="本地 MoviePilot-Resources 仓库路径"
|
||||
|
||||
@@ -148,7 +148,7 @@ def fetch_titles(site_keys: list[str], max_pages: int) -> list[tuple[str, str]]:
|
||||
|
||||
def recognize_one(module, title: str) -> dict:
|
||||
"""对单条标题执行与识别测试页相同的解析+识别链路,并给出失败归因。"""
|
||||
from app.core.meta import MetaMusic
|
||||
from app.domain.meta.metamusic import MetaMusic
|
||||
|
||||
row = {"title": title}
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user