forked from op7418/Youtube-clipper-skill
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_as_skill.sh
More file actions
352 lines (303 loc) · 11.8 KB
/
Copy pathinstall_as_skill.sh
File metadata and controls
352 lines (303 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
#!/bin/bash
##############################################################################
# YouTube Clipper - Claude Code Skill 安装脚本
#
# 功能:
# 1. 自动创建 Skill 目录
# 2. 复制所有必要文件
# 3. 安装 Python 依赖
# 4. 检测系统依赖(yt-dlp、FFmpeg)
#
# 使用方法:
# bash install_as_skill.sh
##############################################################################
set -e # 遇到错误立即退出
# 颜色输出
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 打印函数
print_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
print_success() {
echo -e "${GREEN}✅ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
}
print_header() {
echo ""
echo "========================================"
echo "$1"
echo "========================================"
echo ""
}
# 检查命令是否存在
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# 主函数
main() {
print_header "YouTube Clipper - Claude Code Skill 安装"
# 1. 确定 Skill 目录
SKILL_DIR="$HOME/.claude/skills/youtube-clipper"
print_info "目标目录: $SKILL_DIR"
# 2. 检查是否已存在
if [ -d "$SKILL_DIR" ]; then
print_warning "Skill 目录已存在: $SKILL_DIR"
read -p "是否覆盖安装?(y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_info "安装已取消"
exit 0
fi
print_info "删除旧版本..."
rm -rf "$SKILL_DIR"
fi
# 3. 创建目录
print_info "创建 Skill 目录..."
mkdir -p "$SKILL_DIR"
print_success "目录已创建"
# 4. 复制文件
print_info "复制项目文件..."
# 获取当前脚本所在目录(即项目根目录)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# 复制所有必要文件
cp -r "$SCRIPT_DIR"/* "$SKILL_DIR/"
# 排除不需要的文件
if [ -d "$SKILL_DIR/.git" ]; then
rm -rf "$SKILL_DIR/.git"
fi
if [ -d "$SKILL_DIR/venv" ]; then
rm -rf "$SKILL_DIR/venv"
fi
if [ -d "$SKILL_DIR/__pycache__" ]; then
rm -rf "$SKILL_DIR/__pycache__"
fi
if [ -d "$SKILL_DIR/youtube-clips" ]; then
rm -rf "$SKILL_DIR/youtube-clips"
fi
if [ -f "$SKILL_DIR/.env" ]; then
rm "$SKILL_DIR/.env"
fi
print_success "文件复制完成"
# 5. 检查 Python
print_info "检查 Python 环境..."
if ! command_exists python3; then
print_error "未找到 Python 3,请先安装 Python 3.8+"
exit 1
fi
PYTHON_VERSION=$(python3 --version)
print_success "Python 已安装: $PYTHON_VERSION"
# 6. 检查 pip
if ! command_exists pip3 && ! command_exists pip; then
print_error "未找到 pip,请先安装 pip"
exit 1
fi
print_success "pip 已安装"
# 7. 安装 Python 依赖
print_info "安装 Python 依赖..."
cd "$SKILL_DIR"
# 尝试使用 pip3,如果不存在则使用 pip
if command_exists pip3; then
pip3 install -q yt-dlp pysrt python-dotenv
else
pip install -q yt-dlp pysrt python-dotenv
fi
print_success "Python 依赖安装完成(yt-dlp、pysrt、python-dotenv)"
# 8. 安装 PO Token Provider(可选,用于绕过 YouTube 验证)
print_header "安装 PO Token Provider(可选)"
print_info "PO Token Provider 用于绕过 YouTube 的反爬虫验证"
print_info "这是一个可选依赖,但推荐安装以提高下载成功率"
# 安装 Python 包
print_info "安装 bgutil-ytdlp-pot-provider..."
if command_exists pip3; then
pip3 install -q bgutil-ytdlp-pot-provider 2>/dev/null || print_warning "PO Token Provider 安装失败,将在使用时自动安装"
else
pip install -q bgutil-ytdlp-pot-provider 2>/dev/null || print_warning "PO Token Provider 安装失败,将在使用时自动安装"
fi
# 检查 Node.js(PO Token Provider 需要)
print_info "检查 Node.js..."
if command_exists node; then
NODE_VERSION=$(node --version)
print_success "Node.js 已安装: $NODE_VERSION"
# 检查版本是否 >= 20
NODE_MAJOR=$(echo "$NODE_VERSION" | cut -d'v' -f2 | cut -d'.' -f1)
if [ "$NODE_MAJOR" -ge 20 ]; then
print_success "Node.js 版本符合要求 (>= 20)"
else
print_warning "Node.js 版本过低 ($NODE_VERSION),建议升级到 20+"
print_info "PO Token Provider 需要 Node.js 20 或更高版本"
fi
# 提示下载 PO Token Provider 服务
print_info ""
print_info "PO Token Provider 服务启动方法:"
print_info " 1. 克隆服务代码:"
print_info " git clone --single-branch --branch 1.3.1 https://github.com/Brainicism/bgutil-ytdlp-pot-provider.git"
print_info " 2. 启动服务:"
print_info " cd bgutil-ytdlp-pot-provider/server"
print_info " npm ci && npx tsc && node build/main.js"
else
print_warning "Node.js 未安装,PO Token Provider 服务无法启动"
print_info ""
print_info "Node.js 是运行 PO Token Provider 服务的必需依赖"
print_info "推荐安装方法(使用 nvm):"
print_info ""
print_info " # 1. 下载并安装 nvm"
print_info ' curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash'
print_info ""
print_info " # 2. 加载 nvm(或重新打开终端)"
print_info ' export NVM_DIR="$HOME/.nvm"'
print_info ' [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"'
print_info ""
print_info " # 3. 下载并安装 Node.js 24"
print_info " nvm install 24"
print_info ""
print_info " # 4. 验证安装"
print_info " node -v # 应输出 v24.x.x"
print_info " npm -v # 应输出 11.x.x"
print_info ""
print_info "其他安装方法: https://nodejs.org/"
fi
# 9. 安装 Whisper(可选,用于无字幕视频转录)
print_header "安装 Whisper(可选)"
print_info "Whisper 用于为没有字幕的视频自动生成字幕"
print_info "这是一个可选依赖,默认使用 CPU 运行"
# 检查 CUDA(仅提示,不强制要求)
if command_exists nvidia-smi; then
GPU_INFO=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | head -n 1)
if [ -n "$GPU_INFO" ]; then
print_success "检测到 GPU: $GPU_INFO"
print_info "如需 GPU 加速,请手动安装 CUDA 版本的 PyTorch"
print_info "详见: https://pytorch.org/get-started/locally/"
fi
fi
# 安装 faster-whisper
print_info "安装 faster-whisper(CPU 版本)..."
if command_exists pip3; then
pip3 install -q faster-whisper 2>/dev/null || print_warning "faster-whisper 安装失败,将在使用时自动安装"
else
pip install -q faster-whisper 2>/dev/null || print_warning "faster-whisper 安装失败,将在使用时自动安装"
fi
# 10. 检查 yt-dlp
print_info "检查 yt-dlp..."
if command_exists yt-dlp; then
YT_DLP_VERSION=$(yt-dlp --version)
print_success "yt-dlp 已安装: $YT_DLP_VERSION"
else
print_warning "yt-dlp 命令行工具未安装"
print_info "安装方法:"
print_info " macOS: brew install yt-dlp"
print_info " Ubuntu: sudo apt-get install yt-dlp"
print_info " 或: pip3 install -U yt-dlp"
fi
# 11. 检查 FFmpeg(关键:需要 libass 支持)
print_header "检查 FFmpeg(字幕烧录需要)"
FFMPEG_FOUND=false
LIBASS_SUPPORTED=false
# 检查 ffmpeg-full(macOS 推荐)
if [ -f "/opt/homebrew/opt/ffmpeg-full/bin/ffmpeg" ]; then
print_success "ffmpeg-full 已安装(Apple Silicon)"
FFMPEG_FOUND=true
LIBASS_SUPPORTED=true
elif [ -f "/usr/local/opt/ffmpeg-full/bin/ffmpeg" ]; then
print_success "ffmpeg-full 已安装(Intel Mac)"
FFMPEG_FOUND=true
LIBASS_SUPPORTED=true
elif [ -f "/usr/bin/ffmpeg" ] || [ -f "/usr/local/bin/ffmpeg" ] || [ -f "/snap/bin/ffmpeg" ]; then
# Linux 路径检查
FFMPEG_PATH=""
for path in "/usr/bin/ffmpeg" "/usr/local/bin/ffmpeg" "/snap/bin/ffmpeg"; do
if [ -f "$path" ]; then
FFMPEG_PATH="$path"
break
fi
done
if [ -z "$FFMPEG_PATH" ]; then
FFMPEG_PATH="ffmpeg"
fi
FFMPEG_VERSION=$($FFMPEG_PATH -version | head -n 1)
print_success "FFmpeg 已安装: $FFMPEG_VERSION"
FFMPEG_FOUND=true
# 检查 libass 支持
if $FFMPEG_PATH -filters 2>&1 | grep -q "subtitles"; then
print_success "FFmpeg 支持 libass(字幕烧录可用)"
LIBASS_SUPPORTED=true
else
print_warning "FFmpeg 不支持 libass(字幕烧录不可用)"
fi
elif command_exists ffmpeg; then
FFMPEG_VERSION=$(ffmpeg -version | head -n 1)
print_success "FFmpeg 已安装: $FFMPEG_VERSION"
FFMPEG_FOUND=true
# 检查 libass 支持
if ffmpeg -filters 2>&1 | grep -q "subtitles"; then
print_success "FFmpeg 支持 libass(字幕烧录可用)"
LIBASS_SUPPORTED=true
else
print_warning "FFmpeg 不支持 libass(字幕烧录不可用)"
fi
fi
if [ "$FFMPEG_FOUND" = false ]; then
print_error "FFmpeg 未安装"
print_info "安装方法:"
print_info " macOS: brew install ffmpeg-full # 推荐,包含 libass"
print_info " Ubuntu: sudo apt-get install ffmpeg libass-dev"
print_info " CentOS: sudo dnf install ffmpeg libass"
print_info " Arch: sudo pacman -S ffmpeg libass"
elif [ "$LIBASS_SUPPORTED" = false ]; then
print_warning "FFmpeg 缺少 libass 支持,字幕烧录功能将不可用"
print_info "解决方法:"
print_info " macOS: brew uninstall ffmpeg && brew install ffmpeg-full"
print_info " Ubuntu: sudo apt-get install ffmpeg libass-dev"
print_info " CentOS: sudo dnf install ffmpeg libass"
print_info " Arch: sudo pacman -S ffmpeg libass"
fi
# 12. 创建 .env 文件
print_header "配置环境变量"
if [ -f "$SKILL_DIR/.env.example" ]; then
print_info "创建 .env 文件..."
cp "$SKILL_DIR/.env.example" "$SKILL_DIR/.env"
print_success ".env 文件已创建"
echo ""
print_info "配置文件位置: $SKILL_DIR/.env"
print_info "如需自定义配置,可编辑:"
print_info " nano $SKILL_DIR/.env"
print_info " 或"
print_info " code $SKILL_DIR/.env"
else
print_warning "未找到 .env.example 文件"
fi
# 13. 完成
print_header "安装完成!"
print_success "YouTube Clipper 已成功安装为 Claude Code Skill"
echo ""
print_info "安装位置: $SKILL_DIR"
echo ""
# 检查依赖状态
if [ "$FFMPEG_FOUND" = false ] || [ "$LIBASS_SUPPORTED" = false ]; then
print_warning "系统依赖不完整,部分功能可能不可用"
echo ""
fi
print_info "使用方法:"
print_info " 在 Claude Code 中输入:"
print_info " \"剪辑这个 YouTube 视频:https://youtube.com/watch?v=VIDEO_ID\""
echo ""
print_info "详细文档:"
print_info " - Skill 使用指南: $SKILL_DIR/SKILL.md"
print_info " - 项目文档: $SKILL_DIR/README.md"
print_info " - 技术说明: $SKILL_DIR/TECHNICAL_NOTES.md"
echo ""
print_success "祝使用愉快! 🎉"
echo ""
}
# 错误处理
trap 'print_error "安装过程中发生错误"; exit 1' ERR
# 运行主函数
main