mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-11-28 23:16:35 +08:00
refactor: move site collector releases and sources to independent repository
This commit is contained in:
@@ -1,99 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ORIGINAL_DIR="$PWD"
|
||||
SCRIPT_DIR=""
|
||||
PROJECT_ROOT=""
|
||||
PYTHON_BIN=""
|
||||
COLLECTOR_PATH=""
|
||||
|
||||
# 判断候选 Python 是否满足 3.14 最低版本。
|
||||
python_version_ok() {
|
||||
"$1" - <<'PY' >/dev/null 2>&1
|
||||
import sys
|
||||
raise SystemExit(0 if sys.version_info >= (3, 14) else 1)
|
||||
PY
|
||||
}
|
||||
|
||||
# 从当前源码目录、环境变量或脚本位置查找 MoviePilot 根目录。
|
||||
find_project_root() {
|
||||
local candidate=""
|
||||
local source_path="${BASH_SOURCE[0]:-}"
|
||||
if [[ -n "$source_path" && -f "$source_path" ]]; then
|
||||
SCRIPT_DIR="$(cd "$(dirname "$source_path")" && pwd)"
|
||||
fi
|
||||
for candidate in "${MOVIEPILOT_ROOT:-}" "$ORIGINAL_DIR" "${SCRIPT_DIR:+$SCRIPT_DIR/..}"; do
|
||||
if [[ -n "$candidate" && -f "$candidate/scripts/site_adapter_collector.py" ]]; then
|
||||
PROJECT_ROOT="$(cd "$candidate" && pwd)"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# 查找可用的项目虚拟环境或系统 Python。
|
||||
find_python() {
|
||||
local candidate=""
|
||||
local resolved=""
|
||||
for candidate in \
|
||||
"${PROJECT_ROOT:+$PROJECT_ROOT/venv/bin/python}" \
|
||||
"${PROJECT_ROOT:+$PROJECT_ROOT/.venv/bin/python}" \
|
||||
"${VIRTUAL_ENV:+$VIRTUAL_ENV/bin/python}" \
|
||||
python3.14 python3; do
|
||||
[[ -n "$candidate" ]] || continue
|
||||
if [[ "$candidate" == */* ]]; then
|
||||
resolved="$candidate"
|
||||
else
|
||||
resolved="$(command -v "$candidate" 2>/dev/null || true)"
|
||||
fi
|
||||
if [[ -n "$resolved" && -x "$resolved" ]] && python_version_ok "$resolved"; then
|
||||
PYTHON_BIN="$resolved"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# 判断 Python 是否已具备独立采集器所需的最小运行依赖。
|
||||
project_runtime_ready() {
|
||||
PYTHONPATH="$PROJECT_ROOT${PYTHONPATH:+:$PYTHONPATH}" "$PYTHON_BIN" - <<'PY' >/dev/null 2>&1
|
||||
import requests
|
||||
import websocket
|
||||
from bs4 import BeautifulSoup
|
||||
PY
|
||||
}
|
||||
|
||||
# 让脚本始终从终端安全读取交互输入。
|
||||
restore_terminal_input() {
|
||||
if [[ -r /dev/tty ]]; then
|
||||
exec </dev/tty
|
||||
else
|
||||
echo "需要可交互终端读取站点地址并等待浏览器采集确认。" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 定位本地项目运行环境后启动随发行包提供的采集器。
|
||||
main() {
|
||||
if ! find_project_root; then
|
||||
echo "未找到本地 MoviePilot 源码或安装目录,请在 MoviePilot 目录中运行此脚本。" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! find_python; then
|
||||
echo "未找到 Python 3.11 或更高版本,请先安装 Python。" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! project_runtime_ready; then
|
||||
echo "本地 Python 环境缺少采集器依赖,请下载采集器独立 Release:https://github.com/jxxghp/MoviePilot/releases?q=tag%3Asite-adapter-collector-v1&expanded=true" >&2
|
||||
exit 1
|
||||
fi
|
||||
COLLECTOR_PATH="$PROJECT_ROOT/scripts/site_adapter_collector.py"
|
||||
|
||||
restore_terminal_input
|
||||
cd "$ORIGINAL_DIR"
|
||||
PYTHONPATH="$PROJECT_ROOT${PYTHONPATH:+:$PYTHONPATH}" "$PYTHON_BIN" "$COLLECTOR_PATH" "$@"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1 +0,0 @@
|
||||
"""站点采集器的独立发布工具。"""
|
||||
@@ -1,116 +0,0 @@
|
||||
"""比较采集器发布输入,按独立 Release 递增版本并写入构建副本。"""
|
||||
|
||||
import argparse
|
||||
import re
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
TAG_PREFIX = "site-adapter-collector-v"
|
||||
RELEASE_PATHS = (
|
||||
"scripts/site_adapter_collector.py",
|
||||
"scripts/site_adapter_collector.spec",
|
||||
"scripts/site_adapter_collector_requirements.txt",
|
||||
"scripts/start-site-adapter-collector.command",
|
||||
"scripts/collect-site-adapter.sh",
|
||||
"scripts/collector",
|
||||
".github/workflows/site-adapter-collector.yml",
|
||||
)
|
||||
VERSION_PATTERN = re.compile(r"(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)")
|
||||
SOURCE_VERSION_PATTERN = re.compile(r'^COLLECTOR_VERSION = "([\d.]+)"$', re.MULTILINE)
|
||||
|
||||
|
||||
def _version_parts(version: str) -> tuple[int, int, int]:
|
||||
"""校验独立版本,避免外部标签进入 Git 参数或构建源码。"""
|
||||
match = VERSION_PATTERN.fullmatch(version)
|
||||
if not match:
|
||||
raise ValueError(f"无效采集器版本:{version}")
|
||||
return tuple(int(part) for part in match.groups())
|
||||
|
||||
|
||||
def latest_release_tag(tags: list[str]) -> Optional[str]:
|
||||
"""从已正式发布的标签中选取采集器最高版本,忽略后端版本。"""
|
||||
collector_tags = [
|
||||
tag for tag in tags
|
||||
if tag.startswith(TAG_PREFIX) and VERSION_PATTERN.fullmatch(tag[len(TAG_PREFIX):])
|
||||
]
|
||||
return max(collector_tags, key=lambda tag: _version_parts(tag[len(TAG_PREFIX):]), default=None)
|
||||
|
||||
|
||||
def release_plan(repository: Path, previous_tag: Optional[str]) -> dict[str, str]:
|
||||
"""仅比较采集器输入;未变化时跳过发布,首次沿用源码版本。"""
|
||||
source = repository / "scripts/site_adapter_collector.py"
|
||||
source_match = SOURCE_VERSION_PATTERN.search(source.read_text(encoding="utf-8"))
|
||||
if not source_match:
|
||||
raise ValueError("采集器源码缺少唯一版本声明")
|
||||
source_version = source_match.group(1)
|
||||
source_parts = _version_parts(source_version)
|
||||
source_sha = subprocess.check_output(
|
||||
["git", "rev-parse", "HEAD"], cwd=repository, text=True,
|
||||
).strip()
|
||||
changed = True
|
||||
version = source_version
|
||||
if previous_tag:
|
||||
previous_parts = _version_parts(previous_tag.removeprefix(TAG_PREFIX))
|
||||
result = subprocess.run(
|
||||
["git", "diff", "--quiet", previous_tag, "HEAD", "--", *RELEASE_PATHS],
|
||||
cwd=repository, check=False,
|
||||
)
|
||||
if result.returncode not in (0, 1):
|
||||
raise RuntimeError(f"无法比较采集器 Release:{previous_tag}")
|
||||
changed = result.returncode == 1
|
||||
if changed:
|
||||
next_parts = max(source_parts, (*previous_parts[:2], previous_parts[2] + 1))
|
||||
version = ".".join(str(part) for part in next_parts)
|
||||
else:
|
||||
version = previous_tag[len(TAG_PREFIX):]
|
||||
return {
|
||||
"changed": str(changed).lower(),
|
||||
"version": version,
|
||||
"tag": f"{TAG_PREFIX}{version}",
|
||||
"previous_tag": previous_tag or "",
|
||||
"source_sha": source_sha,
|
||||
}
|
||||
|
||||
|
||||
def stamp_version(source: Path, version: str) -> None:
|
||||
"""只修改 Runner 构建副本,使程序及脱敏包版本与独立 Release 一致。"""
|
||||
_version_parts(version)
|
||||
content, count = SOURCE_VERSION_PATTERN.subn(
|
||||
f'COLLECTOR_VERSION = "{version}"', source.read_text(encoding="utf-8"),
|
||||
)
|
||||
if count != 1:
|
||||
raise ValueError("采集器源码缺少唯一版本声明")
|
||||
source.write_text(content, encoding="utf-8")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""供工作流选择独立发布版本或给构建副本写入版本。"""
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
commands = parser.add_subparsers(dest="command", required=True)
|
||||
plan_parser = commands.add_parser("plan")
|
||||
plan_parser.add_argument("--tags-file", type=Path, required=True)
|
||||
plan_parser.add_argument("--output", type=Path, required=True)
|
||||
stamp_parser = commands.add_parser("stamp")
|
||||
stamp_parser.add_argument("--version", required=True)
|
||||
args = parser.parse_args()
|
||||
repository = Path(__file__).resolve().parents[2]
|
||||
if args.command == "stamp":
|
||||
stamp_version(repository / "scripts/site_adapter_collector.py", args.version)
|
||||
return
|
||||
tags = args.tags_file.read_text(encoding="utf-8").splitlines()
|
||||
previous_tag = latest_release_tag(tags)
|
||||
if previous_tag:
|
||||
subprocess.run(
|
||||
["git", "fetch", "--no-tags", "origin", f"refs/tags/{previous_tag}:refs/tags/{previous_tag}"],
|
||||
cwd=repository, check=True,
|
||||
)
|
||||
plan = release_plan(repository, previous_tag)
|
||||
with args.output.open("a", encoding="utf-8") as output:
|
||||
for name, value in plan.items():
|
||||
output.write(f"{name}={value}\n")
|
||||
print(f"采集器版本:{plan['version']};输入变化:{plan['changed']}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,41 +0,0 @@
|
||||
# -*- mode: python ; coding: utf-8 -*-
|
||||
"""将站点适配采集器构建为不依赖本地 Python 的单文件程序。"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
PROJECT_ROOT = Path(SPECPATH).resolve().parent
|
||||
ENTRYPOINT = PROJECT_ROOT / "scripts" / "site_adapter_collector.py"
|
||||
analysis = Analysis(
|
||||
[str(ENTRYPOINT)],
|
||||
pathex=[str(PROJECT_ROOT)],
|
||||
binaries=[],
|
||||
datas=[],
|
||||
hiddenimports=[],
|
||||
hookspath=[],
|
||||
hooksconfig={},
|
||||
runtime_hooks=[],
|
||||
excludes=[],
|
||||
noarchive=False,
|
||||
optimize=0,
|
||||
)
|
||||
python_archive = PYZ(analysis.pure)
|
||||
|
||||
executable = EXE(
|
||||
python_archive,
|
||||
analysis.scripts,
|
||||
analysis.binaries,
|
||||
analysis.datas,
|
||||
[],
|
||||
name="moviepilot-site-collector",
|
||||
debug=False,
|
||||
bootloader_ignore_signals=False,
|
||||
strip=False,
|
||||
upx=False,
|
||||
console=True,
|
||||
disable_windowed_traceback=False,
|
||||
argv_emulation=False,
|
||||
target_arch=None,
|
||||
codesign_identity=None,
|
||||
entitlements_file=None,
|
||||
)
|
||||
@@ -1,4 +0,0 @@
|
||||
beautifulsoup4~=4.15.0
|
||||
PyInstaller>=6.14,<7.0
|
||||
requests>=2.32,<3.0
|
||||
websocket-client~=1.9.0
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -u
|
||||
|
||||
# 从解压目录启动 macOS 单文件采集器,并在结束后保留终端窗口供用户查看结果。
|
||||
main() {
|
||||
local script_dir=""
|
||||
local collector_path=""
|
||||
local status=0
|
||||
|
||||
script_dir="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
||||
collector_path="$script_dir/moviepilot-site-collector-macos"
|
||||
if [[ ! -f "$collector_path" ]]; then
|
||||
echo "未找到 moviepilot-site-collector-macos,请完整解压 ZIP 后再双击启动。" >&2
|
||||
status=1
|
||||
else
|
||||
chmod +x "$collector_path"
|
||||
cd "$script_dir" || status=1
|
||||
if [[ "$status" -eq 0 ]]; then
|
||||
"$collector_path" || status=$?
|
||||
fi
|
||||
fi
|
||||
|
||||
echo
|
||||
read -r -p "按回车关闭窗口..." _
|
||||
exit "$status"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user