Files

35 lines
1.6 KiB
Bash
Raw Permalink 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.
#!/bin/bash
# fetch_course.sh — 下载 YouTube 课程视频 + 本地转写 + 组装教程
#
# 用法:
# ./fetch_course.sh <playlist_url或单个视频url> <输出目录>
#
# 环境变量(可选):
# PROXY 代理,默认 socks5://192.168.27.96:1080
# MODEL whisper 模型,默认 base.en(英文用 base.en/small.en,中文用 small)
# LANG 语言,默认 en(中文用 zh)
# JOBS 并行数,默认 4
# FMT yt-dlp 格式,默认 18(360p 渐进式,含音轨;见 README 画质说明)
set -uo pipefail
URL="${1:?用法: ./fetch_course.sh <url> <输出目录>}"
OUT="${2:?缺少输出目录}"
PROXY="${PROXY:-socks5://192.168.27.96:1080}"
MODEL="${MODEL:-base.en}"; LG="${LANG:-en}"; JOBS="${JOBS:-4}"; FMT="${FMT:-18}"
HERE="$(cd "$(dirname "$0")" && pwd)"
mkdir -p "$OUT/videos" "$OUT/transcripts" "$OUT/clean"
if [ ! -s "$OUT/manifest.txt" ]; then
echo "[*] 枚举视频列表..."
yt-dlp --proxy "$PROXY" --no-warnings --flat-playlist \
--print "%(playlist_index)s|%(id)s|%(title)s" "$URL" > "$OUT/_raw.txt" || { echo "枚举失败"; exit 1; }
python3 "$HERE/course_util.py" manifest "$OUT/_raw.txt" > "$OUT/manifest.txt"
fi
echo "[*] 待处理视频: $(grep -c . "$OUT/manifest.txt") 个 | 模型=$MODEL 并行=$JOBS"
export PROXY MODEL LANG="$LG" OUT HERE FMT
grep -v '^[[:space:]]*$' "$OUT/manifest.txt" | xargs -P "$JOBS" -I{} "$HERE/worker.sh" "{}"
python3 "$HERE/course_util.py" clean "$OUT"
echo "[*] 全部完成: $OUT"
echo "[*] 下一步: 在 $OUT/guides/ 放中文导读(<NN>.txt)后运行 course_util.py build $OUT"