Files
SceneMarshal/scripts/media-rename
T
ali e66d082f31 chore: 项目更名为 SceneMarshal
- README/脚本注释/LICENSE/图标文件名统一改名
- 右键菜单注册项改为 SceneMarshal / SceneMarshalArchive
- media_archive 支持 SCENEMARSHAL_* 环境变量(保留旧变量兼容)
- README 补充 preflight/字幕/字体/归档等实际能力与 check 用法
2026-11-19 12:21:42 +08:00

75 lines
2.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# media-rename —— 宿主机代理,把参数透传进 python 容器执行 SceneMarshal
#
# 用法:
# media-rename # 处理当前目录
# media-rename auto # 指定 main.py 模式
# media-rename -p "/hdd/sda1/Quark-Down/苍兰诀 (2022)"
# media-rename -p 某目录 extract-subs
# media-rename -h # 透传 main.py 帮助
#
# 说明:
# - 未给 -p/--path 且不是 -h 时,默认取当前目录;
# - 路径会 realpath 展开,并限制在容器已挂载的范围内;
# - 有 TTY 时使用 docker exec -it(可交互确认/输入标题年份),无 TTY 时自动降级。
set -euo pipefail
CONTAINER="${MEDIA_RENAME_CONTAINER:-python}"
PYTHON_BIN="/python/media/bin/python"
SCRIPT="/python/media/src/main.py"
ALLOWED_PREFIXES=(/hdd/sda1 /python)
die() { printf '\033[0;31m❌ %s\033[0m\n' "$*" >&2; exit 1; }
args=()
path_found=0
target_path=""
want_help=0
i=1
while (( i <= $# )); do
arg="${!i}"
case "$arg" in
-h|--help)
want_help=1
args+=("$arg")
;;
-p|--path)
args+=("$arg")
path_found=1
i=$((i + 1))
(( i <= $# )) || die "$arg 后面缺少路径参数"
raw="${!i}"
target_path="$(realpath -e -- "$raw" 2>/dev/null)" || die "路径不存在或无法解析: $raw"
args+=("$target_path")
;;
*)
args+=("$arg")
;;
esac
i=$((i + 1))
done
if (( ! path_found && ! want_help )); then
target_path="$(pwd)"
args+=("-p" "$target_path")
fi
if [[ -n "$target_path" ]]; then
allowed=0
for prefix in "${ALLOWED_PREFIXES[@]}"; do
if [[ "$target_path" == "$prefix" || "$target_path" == "$prefix"/* ]]; then
allowed=1
break
fi
done
(( allowed )) || die "路径越界: $target_path 未挂载给容器(仅允许 ${ALLOWED_PREFIXES[*]})"
fi
exec_opts=(-u 1000:1000)
if [[ -t 0 && -t 1 ]]; then
exec_opts+=(-it)
fi
exec docker exec "${exec_opts[@]}" "$CONTAINER" "$PYTHON_BIN" "$SCRIPT" "${args[@]}"