A Rust CLI on the yt-dlp crate: `video-dl <url>` downloads the video (≤1080p H.264 mp4 by default), its audio (--audio), subtitles (--subs) or a playlist (--playlist --items), and prints where it landed. yt-dlp, ffmpeg (through the crate's LibraryInstaller) and deno are fetched on first run and yt-dlp is kept under 45 days old. `info`, `setup`, `update`; `--json` everywhere. install.sh installs the binary (Gitea release, checksum-verified, cargo fallback) and the Claude Code skill in skill/SKILL.md; scripts/release.sh builds static musl binaries with cargo-zigbuild (macOS natively on a Mac) and uploads them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
106 lines
4.7 KiB
Bash
Executable File
106 lines
4.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Build and publish a video-dl release on Gitea.
|
|
#
|
|
# scripts/release.sh # v<Cargo.toml version>: tag, build, upload
|
|
# scripts/release.sh --no-build # upload what's already in dist/<tag>/
|
|
#
|
|
# Builds what this machine can:
|
|
# Linux → video-dl-linux-x64, video-dl-linux-arm64 (static musl, cargo-zigbuild + zig)
|
|
# macOS → video-dl-macos-arm64, video-dl-macos-x64 (native cargo, both targets)
|
|
# and adds them to the release (created on first run, asset names replaced),
|
|
# then rewrites checksums.txt over every binary the release now has. Run it on
|
|
# the lab, then on a Mac, for one complete release.
|
|
#
|
|
# Needs a Gitea token: $GITEA_TOKEN, else ~/.config/homelab-gitea-token.
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
|
|
GITEA="${GITEA_URL:-https://git.gabvdl.xyz}"
|
|
REPO="${VIDEO_DL_REPO:-gabrielvidal/video-dl}"
|
|
TOKEN="${GITEA_TOKEN:-$(cat ~/.config/homelab-gitea-token 2>/dev/null || true)}"
|
|
[ -n "$TOKEN" ] || { echo "error: no Gitea token (GITEA_TOKEN or ~/.config/homelab-gitea-token)" >&2; exit 1; }
|
|
BUILD=1
|
|
[ "${1:-}" = "--no-build" ] && BUILD=0
|
|
|
|
ver=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1)
|
|
tag="v$ver"
|
|
dist="dist/$tag"
|
|
mkdir -p "$dist"
|
|
export PATH="$HOME/.cargo/bin:$HOME/.local/bin:$PATH"
|
|
# A small /tmp (RAM tmpfs) can't hold the build's scratch files.
|
|
export TMPDIR="${TMPDIR_RELEASE:-$PWD/target/tmp}"
|
|
mkdir -p "$TMPDIR"
|
|
|
|
if ! git diff --quiet || ! git diff --cached --quiet; then
|
|
echo "error: commit your changes first" >&2; exit 1
|
|
fi
|
|
if ! git rev-parse -q --verify "refs/tags/$tag" >/dev/null; then
|
|
git tag -a "$tag" -m "video-dl $tag"
|
|
fi
|
|
[ "$(git rev-parse "$tag^{commit}")" = "$(git rev-parse HEAD)" ] \
|
|
|| { echo "error: $tag doesn't point at HEAD — bump the version in Cargo.toml" >&2; exit 1; }
|
|
|
|
if [ "$BUILD" = 1 ]; then
|
|
case "$(uname -s)" in
|
|
Linux)
|
|
for pair in x86_64-unknown-linux-musl:linux-x64 aarch64-unknown-linux-musl:linux-arm64; do
|
|
t=${pair%%:*}; name=${pair##*:}
|
|
rustup target add "$t" >/dev/null
|
|
echo "building $name…"
|
|
cargo zigbuild --release --locked --target "$t"
|
|
cp "target/$t/release/video-dl" "$dist/video-dl-$name"
|
|
done ;;
|
|
Darwin)
|
|
for pair in aarch64-apple-darwin:macos-arm64 x86_64-apple-darwin:macos-x64; do
|
|
t=${pair%%:*}; name=${pair##*:}
|
|
rustup target add "$t" >/dev/null
|
|
echo "building $name…"
|
|
cargo build --release --locked --target "$t"
|
|
cp "target/$t/release/video-dl" "$dist/video-dl-$name"
|
|
done ;;
|
|
*) echo "error: build on Linux or macOS" >&2; exit 1 ;;
|
|
esac
|
|
fi
|
|
|
|
auth=(-H "Authorization: token $TOKEN")
|
|
api="$GITEA/api/v1/repos/$REPO"
|
|
|
|
# The tag must be on Gitea before the release can point at it.
|
|
git -c http.extraHeader="Authorization: token $TOKEN" push -q "$GITEA/$REPO.git" "refs/tags/$tag" 2>/dev/null || true
|
|
|
|
rel=$(curl -fsS "${auth[@]}" "$api/releases/tags/$tag" 2>/dev/null || true)
|
|
if [ -z "$rel" ]; then
|
|
# Release notes = this version's CHANGELOG section.
|
|
notes=$(awk -v v="## $tag" '$0 ~ "^## " { p = ($0 ~ "^" v) } p' CHANGELOG.md | tail -n +2)
|
|
body=$(python3 -c 'import json,sys; print(json.dumps({"tag_name":sys.argv[1],"name":"video-dl "+sys.argv[1],"body":sys.argv[2]}))' "$tag" "$notes")
|
|
rel=$(curl -fsS "${auth[@]}" -H 'Content-Type: application/json' -X POST -d "$body" "$api/releases")
|
|
fi
|
|
rel_id=$(printf '%s' "$rel" | python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])')
|
|
|
|
upload() { # upload FILE as its basename, replacing an asset of that name
|
|
local f=$1 name; name=$(basename "$1")
|
|
curl -fsS "${auth[@]}" "$api/releases/$rel_id/assets" \
|
|
| python3 -c 'import json,sys; [print(a["id"]) for a in json.load(sys.stdin) if a["name"]==sys.argv[1]]' "$name" \
|
|
| while read -r id; do curl -fsS "${auth[@]}" -X DELETE "$api/releases/$rel_id/assets/$id" >/dev/null; done
|
|
curl -fsS "${auth[@]}" -F "attachment=@$f" "$api/releases/$rel_id/assets?name=$name" >/dev/null
|
|
echo "uploaded $name"
|
|
}
|
|
|
|
for f in "$dist"/video-dl-*; do
|
|
[ -e "$f" ] && upload "$f"
|
|
done
|
|
|
|
# checksums.txt over every binary the release has (this machine's and earlier runs').
|
|
sums="$dist/checksums.txt"
|
|
: > "$sums"
|
|
curl -fsS "${auth[@]}" "$api/releases/$rel_id/assets" \
|
|
| python3 -c 'import json,sys; [print(a["name"], a["browser_download_url"]) for a in json.load(sys.stdin) if a["name"].startswith("video-dl-")]' \
|
|
| sort | while read -r name url; do
|
|
if [ -e "$dist/$name" ]; then f="$dist/$name"; else f="$dist/.remote-$name"; curl -fsSL -o "$f" "$url"; fi
|
|
if command -v sha256sum >/dev/null; then s=$(sha256sum "$f" | cut -d' ' -f1); else s=$(shasum -a 256 "$f" | cut -d' ' -f1); fi
|
|
echo "$s $name" >> "$sums"
|
|
done
|
|
rm -f "$dist"/.remote-*
|
|
upload "$sums"
|
|
echo "done: $GITEA/$REPO/releases/tag/$tag"
|