-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsmart_convert.command
More file actions
89 lines (77 loc) · 2.78 KB
/
Copy pathsmart_convert.command
File metadata and controls
89 lines (77 loc) · 2.78 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
#!/bin/bash
# ============================================
# 账号文件智能转换工具 (macOS)
# ============================================
export LANG=en_US.UTF-8
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# 获取脚本所在目录
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# 检查 python3 是否存在
if ! command -v python3 &> /dev/null; then
echo -e "${RED}错误:未找到 Python 3,请先安装 Python 3${NC}"
echo " brew install python3 或访问 https://www.python.org/"
read -p "按 Enter 关闭..." < /dev/tty
exit 1
fi
# 检查 convert_accounts.py 是否存在
if [[ ! -f "$SCRIPT_DIR/convert_accounts.py" ]]; then
echo -e "${RED}错误:未找到 convert_accounts.py,请确保脚本与 convert_accounts.py 在同一目录${NC}"
read -p "按 Enter 关闭..." < /dev/tty
exit 1
fi
# 无参数时显示帮助
if [[ $# -eq 0 ]]; then
echo -e "${CYAN}============================================${NC}"
echo -e "${CYAN} 账号文件智能转换工具${NC}"
echo -e "${CYAN}============================================${NC}"
echo ""
echo "用法: 将文件或文件夹拖放到此 .command 文件上"
echo " 支持同时拖拽多个文件/文件夹进行批量转换"
echo ""
echo " 拖入文件夹 → 自动识别为 cliProxyAPI 格式,转换为 sub2api"
echo " 拖入JSON文件 → 自动识别格式并转换为另一种格式"
echo ""
echo "命令行: ./smart_convert.command <路径1> [路径2] [路径3] ..."
echo -e "${CYAN}============================================${NC}"
read -p "按 Enter 继续..." < /dev/tty
exit 0
fi
# 多文件循环处理,统计成功/失败
total=0
success=0
fail=0
for input_path in "$@"; do
((total++))
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}正在处理 [$total]: ${NC}$input_path"
echo -e "${BLUE}========================================${NC}"
python3 "$SCRIPT_DIR/convert_accounts.py" auto "$input_path"
if [[ $? -eq 0 ]]; then
((success++))
echo -e "${GREEN}[$total] 处理成功${NC}"
else
((fail++))
echo -e "${RED}[$total] 处理失败${NC}"
fi
done
# 汇总统计
echo ""
echo -e "${CYAN}========================================${NC}"
echo -e "${CYAN} 批量处理完成${NC}"
echo -e "${CYAN}========================================${NC}"
echo " 总计: $total 个"
echo -e " 成功: ${GREEN}$success${NC} 个"
if [[ $fail -gt 0 ]]; then
echo -e " 失败: ${RED}$fail${NC} 个"
else
echo " 失败: $fail 个"
fi
echo -e "${CYAN}========================================${NC}"
read -p "按 Enter 关闭窗口..." < /dev/tty