forked from jxxghp/MoviePilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoviepilot
More file actions
executable file
·481 lines (434 loc) · 11.8 KB
/
moviepilot
File metadata and controls
executable file
·481 lines (434 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
#!/usr/bin/env bash
set -euo pipefail
show_help() {
cat <<'EOF'
Usage: moviepilot [BOOTSTRAP COMMAND] | [RUNTIME COMMAND]
moviepilot help [COMMAND ...]
moviepilot commands
Bootstrap Commands:
moviepilot install deps [--python PYTHON] [--venv PATH] [--recreate] [--config-dir PATH]
moviepilot install frontend [--version latest] [--node-version 20.12.1] [--config-dir PATH]
moviepilot install resources [--resources-repo PATH] [--resource-dir PATH] [--config-dir PATH]
moviepilot init [--skip-resources] [--force-token] [--wizard] [--superuser NAME] [--superuser-password PASSWORD] [--config-dir PATH]
moviepilot setup [--python PYTHON] [--venv PATH] [--recreate] [--frontend-version latest] [--node-version 20.12.1] [--wizard] [--superuser NAME] [--superuser-password PASSWORD] [--config-dir PATH]
moviepilot uninstall [--venv PATH] [--config-dir PATH]
moviepilot update {backend|frontend|all} [OPTIONS]
moviepilot startup {enable|disable|status} [--venv PATH] [--config-dir PATH]
moviepilot agent [OPTIONS] MESSAGE...
Runtime Commands:
moviepilot start|stop|restart|status|logs|version
moviepilot config ...
moviepilot tool ...
moviepilot scheduler ...
Discovery Commands:
moviepilot help
moviepilot help config
moviepilot help install
moviepilot help uninstall
moviepilot help update
moviepilot help startup
moviepilot commands
Examples:
moviepilot install deps
moviepilot install frontend
moviepilot install resources
moviepilot setup --wizard
moviepilot uninstall
moviepilot update all
moviepilot startup enable
moviepilot agent 帮我分析最近一次搜索失败
moviepilot help config
moviepilot config keys
moviepilot start
moviepilot tool list
EOF
}
show_commands() {
cat <<'EOF'
Bootstrap Commands
install deps
install frontend
install resources
init
setup
uninstall
update backend
update frontend
update all
startup enable
startup disable
startup status
agent
Runtime Commands
start
stop
restart
status
logs
version
config path
config list
config get
config set
config keys
config describe
tool list
tool show
tool run
scheduler list
scheduler run
Discovery Commands
help
commands
EOF
}
show_install_help() {
cat <<'EOF'
Usage:
moviepilot install deps [OPTIONS]
moviepilot install frontend [OPTIONS]
moviepilot install resources [OPTIONS]
Options:
deps:
--python PYTHON 用于创建虚拟环境的 Python 解释器,默认自动选择本地 3.11+ 版本
--venv PATH 虚拟环境目录,默认 ./venv
--recreate 删除并重建虚拟环境
--config-dir PATH 指定配置目录
frontend:
--version TAG 前端版本,默认 latest
--node-version VER 本地 Node 运行时版本,默认 20.12.1
--config-dir PATH 指定配置目录
resources:
--resources-repo PATH 本地 MoviePilot-Resources 仓库路径
--resource-dir PATH 直接指定 resources.v2 目录
--config-dir PATH 指定配置目录
-h, --help 显示帮助
EOF
}
show_init_help() {
cat <<'EOF'
Usage: moviepilot init [OPTIONS]
Options:
--skip-resources 跳过资源同步
--force-token 强制重置 API_TOKEN
--wizard 启动交互式初始化向导
--superuser NAME 预设超级管理员用户名
--superuser-password PWD 预设超级管理员密码
--config-dir PATH 指定配置目录
-h, --help 显示帮助
EOF
}
show_setup_help() {
cat <<'EOF'
Usage: moviepilot setup [OPTIONS]
Options:
--python PYTHON 用于创建虚拟环境的 Python 解释器,默认自动选择本地 3.11+ 版本
--venv PATH 虚拟环境目录,默认 ./venv
--recreate 删除并重建虚拟环境
--frontend-version TAG 前端版本,默认 latest
--node-version VER 本地 Node 运行时版本,默认 20.12.1
--skip-resources 跳过资源同步
--force-token 强制重置 API_TOKEN
--wizard 安装完成后启动交互式初始化向导
--superuser NAME 预设超级管理员用户名
--superuser-password PWD 预设超级管理员密码
--config-dir PATH 指定配置目录
-h, --help 显示帮助
EOF
}
show_uninstall_help() {
cat <<'EOF'
Usage: moviepilot uninstall [OPTIONS]
Options:
--venv PATH 虚拟环境目录,默认 ./venv
--config-dir PATH 指定配置目录,默认使用当前安装配置
-h, --help 显示帮助
说明:
- 默认保留配置目录,过程中会询问是否删除
- 卸载时会进行两次确认
- 源码目录不会被删除
EOF
}
show_update_help() {
cat <<'EOF'
Usage:
moviepilot update backend [OPTIONS]
moviepilot update frontend [OPTIONS]
moviepilot update all [OPTIONS]
Options:
--ref REF 后端 Git 版本,默认 latest
--frontend-version TAG 前端版本,默认 latest
--node-version VER 本地 Node 运行时版本,默认 20.12.1
--python PYTHON 用于安装后端依赖的 Python 解释器,默认自动选择本地 3.11+ 版本
--venv PATH 虚拟环境目录,默认 ./venv
--recreate 删除并重建虚拟环境
--skip-resources 更新 all 时跳过资源同步
--config-dir PATH 指定配置目录
-h, --help 显示帮助
EOF
}
show_startup_help() {
cat <<'EOF'
Usage:
moviepilot startup enable [OPTIONS]
moviepilot startup disable [OPTIONS]
moviepilot startup status [OPTIONS]
Options:
--venv PATH 虚拟环境目录,默认 ./venv
--config-dir PATH 指定配置目录,默认使用当前安装配置
-h, --help 显示帮助
说明:
- macOS 使用 LaunchAgent
- Linux 优先使用 systemd --user,不可用时回退到 XDG autostart
- Windows 使用当前用户的 Startup 启动目录
EOF
}
show_agent_help() {
cat <<'EOF'
Usage:
moviepilot agent [OPTIONS] MESSAGE...
Options:
--session ID 指定会话 ID
--new-session 强制创建新会话
--user-id ID 智能体上下文中的用户 ID,默认 cli
--config-dir PATH 指定配置目录
-h, --help 显示帮助
EOF
}
python_version_ok() {
local python_bin="$1"
"$python_bin" - <<'PY' >/dev/null 2>&1
import sys
raise SystemExit(0 if sys.version_info >= (3, 11) else 1)
PY
}
try_python_candidate() {
local candidate="$1"
local python_path=""
python_path="$(command -v "$candidate" 2>/dev/null || true)"
if [ -n "$python_path" ] && python_version_ok "$python_path"; then
printf '%s\n' "$python_path"
return 0
fi
return 1
}
find_system_python() {
local minor
local uv_bin
local uv_python
for minor in 20 19 18 17 16 15 14 13 12 11; do
if try_python_candidate "python3.$minor"; then
return 0
fi
done
if try_python_candidate python3; then
return 0
fi
if try_python_candidate python; then
return 0
fi
for uv_bin in "$(command -v uv 2>/dev/null || true)" "$HOME/.local/bin/uv"; do
if [ -n "$uv_bin" ] && [ -x "$uv_bin" ]; then
for minor in 20 19 18 17 16 15 14 13 12 11; do
uv_python="$("$uv_bin" python find "3.$minor" 2>/dev/null || true)"
if [ -n "$uv_python" ] && python_version_ok "$uv_python"; then
printf '%s\n' "$uv_python"
return 0
fi
done
fi
done
return 1
}
require_bootstrap_python() {
if [ -n "$BOOTSTRAP_PYTHON" ]; then
return 0
fi
echo "未找到可用的 Python 3.11+ 解释器,请先安装 Python 3.11 或更高版本" >&2
exit 1
}
default_config_dir() {
case "$(uname -s)" in
Darwin)
printf '%s\n' "$HOME/Library/Application Support/MoviePilot"
;;
*)
printf '%s\n' "${XDG_CONFIG_HOME:-$HOME/.config}/moviepilot"
;;
esac
}
legacy_config_exists() {
local legacy_dir="$ROOT/config"
[[ -f "$legacy_dir/app.env" ]] || [[ -f "$legacy_dir/user.db" ]] || [[ -d "$legacy_dir/logs" ]] || [[ -d "$legacy_dir/temp" ]] || [[ -d "$legacy_dir/cache" ]] || [[ -d "$legacy_dir/cookies" ]] || [[ -d "$legacy_dir/sites" ]]
}
run_runtime_cli() {
if [ ! -x "$VENV_PYTHON" ]; then
echo "未找到项目虚拟环境,请先执行 moviepilot install deps 或 moviepilot setup" >&2
exit 1
fi
exec "$VENV_PYTHON" -m app.cli "$@"
}
show_command_help() {
case "${1:-}" in
""|-h|--help|help)
show_help
exit 0
;;
install)
shift
case "${1:-}" in
""|deps|-h|--help)
show_install_help
exit 0
;;
frontend)
show_install_help
exit 0
;;
resources)
show_install_help
exit 0
;;
*)
echo "仅支持:moviepilot help install、moviepilot help install deps、moviepilot help install frontend、moviepilot help install resources" >&2
exit 1
;;
esac
;;
init)
show_init_help
exit 0
;;
setup)
show_setup_help
exit 0
;;
uninstall)
show_uninstall_help
exit 0
;;
agent)
show_agent_help
exit 0
;;
update)
show_update_help
exit 0
;;
startup)
show_startup_help
exit 0
;;
commands)
show_commands
exit 0
;;
*)
run_runtime_cli "$@" --help
;;
esac
}
SOURCE="${BASH_SOURCE[0]}"
while [ -L "$SOURCE" ]; do
SOURCE_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
SOURCE_TARGET="$(readlink "$SOURCE")"
if [[ "$SOURCE_TARGET" != /* ]]; then
SOURCE="$SOURCE_DIR/$SOURCE_TARGET"
else
SOURCE="$SOURCE_TARGET"
fi
done
ROOT="$(cd -P "$(dirname "$SOURCE")" && pwd)"
VENV_PYTHON="$ROOT/venv/bin/python"
SETUP_SCRIPT="$ROOT/scripts/local_setup.py"
if [ -z "${CONFIG_DIR:-}" ] && [ -f "$ROOT/.moviepilot.env" ]; then
# shellcheck disable=SC1090
. "$ROOT/.moviepilot.env"
fi
if [ -z "${CONFIG_DIR:-}" ]; then
if legacy_config_exists; then
CONFIG_DIR="$ROOT/config"
else
CONFIG_DIR="$(default_config_dir)"
fi
fi
export CONFIG_DIR
BOOTSTRAP_PYTHON=""
if [ -x "$VENV_PYTHON" ]; then
BOOTSTRAP_PYTHON="$VENV_PYTHON"
else
BOOTSTRAP_PYTHON="$(find_system_python || true)"
fi
cd "$ROOT"
case "${1:-}" in
""|-h|--help|help)
if [ "${1:-}" = "help" ]; then
shift
show_command_help "$@"
fi
show_help
exit 0
;;
commands)
show_commands
exit 0
;;
install)
shift
require_bootstrap_python
case "${1:-}" in
deps)
shift
exec "$BOOTSTRAP_PYTHON" "$SETUP_SCRIPT" install-deps "$@"
;;
frontend)
shift
exec "$BOOTSTRAP_PYTHON" "$SETUP_SCRIPT" install-frontend "$@"
;;
resources)
shift
exec "$BOOTSTRAP_PYTHON" "$SETUP_SCRIPT" install-resources "$@"
;;
*)
echo "支持的命令:moviepilot install deps|frontend|resources" >&2
exit 1
;;
esac
;;
init)
shift
require_bootstrap_python
exec "$BOOTSTRAP_PYTHON" "$SETUP_SCRIPT" init "$@"
;;
setup)
shift
require_bootstrap_python
exec "$BOOTSTRAP_PYTHON" "$SETUP_SCRIPT" setup "$@"
;;
uninstall)
shift
require_bootstrap_python
COMMAND_PATH="$(command -v moviepilot 2>/dev/null || true)"
MOVIEPILOT_LAUNCH_PATH="$0" MOVIEPILOT_COMMAND_PATH="$COMMAND_PATH" exec "$BOOTSTRAP_PYTHON" "$SETUP_SCRIPT" uninstall "$@"
;;
update)
shift
require_bootstrap_python
exec "$BOOTSTRAP_PYTHON" "$SETUP_SCRIPT" update "$@"
;;
startup)
shift
require_bootstrap_python
exec "$BOOTSTRAP_PYTHON" "$SETUP_SCRIPT" startup "$@"
;;
agent)
shift
require_bootstrap_python
exec "$BOOTSTRAP_PYTHON" "$SETUP_SCRIPT" agent "$@"
;;
esac
if [ ! -x "$VENV_PYTHON" ]; then
echo "未找到项目虚拟环境,请先执行 moviepilot install deps 或 moviepilot setup" >&2
exit 1
fi
exec "$VENV_PYTHON" -m app.cli "$@"