#!/usr/bin/env bash set -euo pipefail REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" MANIFEST="${MANIFEST:-$REPO_ROOT/content/audio.yaml}" SRC_DIR="${SRC_DIR:-$REPO_ROOT/content/images}" OUT_DIR="${OUT_DIR:-$REPO_ROOT/web/static/images}" MAX_SIZE="${MAX_SIZE:-1200}" QUALITY="${QUALITY:-80}" for tool in yq magick; do if ! command -v "$tool" >/dev/null; then echo "error: $tool not in PATH (try: nix develop)" >&2 exit 1 fi done mkdir -p "$OUT_DIR" encoded=0 skipped=0 missing=0 failed=0 NUM_ARTISTS=$(yq '.artists | length' "$MANIFEST") for ((a=0; a src_mt )); then printf ' %-45s up to date\n' "$OUT_NAME" skipped=$((skipped + 1)) continue fi fi printf ' %-45s converting ...\n' "$OUT_NAME" if magick "$SRC_PATH" \ -auto-orient \ -strip \ -resize "${MAX_SIZE}x${MAX_SIZE}>" \ -quality "$QUALITY" \ "$OUT_PATH"; then size=$(du -h "$OUT_PATH" | cut -f1) printf ' %-45s done (%s)\n' "$OUT_NAME" "$size" encoded=$((encoded + 1)) else printf ' %-45s FAILED\n' "$OUT_NAME" >&2 failed=$((failed + 1)) fi done done printf '\n%d converted · %d up-to-date · %d missing sources · %d failed\n' \ "$encoded" "$skipped" "$missing" "$failed" if (( failed > 0 )); then exit 1 fi