Last active
June 17, 2026 19:45
-
-
Save leogdion/b3f344edfbf237b46864a8bf1dedd51b to your computer and use it in GitHub Desktop.
Rename Podcast Clips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| # Usage: ./rename.sh "EAS-207. " [--apply] | |
| # Dry-run by default; pass --apply to actually rename. | |
| prefix="" | |
| apply=0 | |
| for arg in "$@"; do | |
| case "$arg" in | |
| --apply) apply=1 ;; | |
| *) prefix="$arg" ;; | |
| esac | |
| done | |
| if [[ -z "$prefix" ]]; then | |
| echo "Usage: $0 \"EAS-207. \" [--apply]" >&2 | |
| exit 1 | |
| fi | |
| if ! command -v ffprobe >/dev/null 2>&1; then | |
| echo "ABORT: ffprobe not found (needed to detect orientation)." >&2 | |
| exit 1 | |
| fi | |
| shopt -s nullglob | |
| # Matches the Riverside exports, including " (1)" duplicate markers that | |
| # distinguish a second orientation exported to the same base name. | |
| for f in riverside_*_empower-apps.mp4 riverside_*_empower-apps\ \(*\).mp4; do | |
| base="${f%.mp4}" | |
| base="${base#riverside_}" | |
| base=$(printf '%s' "$base" | sed -E 's/ \([0-9]+\)$//') # drop trailing " (N)" | |
| base="${base%_empower-apps}" | |
| base="${base//_/ }" | |
| title=$(printf '%s' "$base" \ | |
| | awk '{for(i=1;i<=NF;i++){$i=toupper(substr($i,1,1)) substr($i,2)}}1') | |
| # TODO: add a substitution step for common terms that title-casing gets wrong, | |
| # e.g. "Ai" -> "AI", "Ios" -> "iOS", "Api" -> "API", "Swiftui" -> "SwiftUI". | |
| # Detect orientation from the video stream's dimensions. | |
| dims=$(ffprobe -v error -select_streams v:0 \ | |
| -show_entries stream=width,height -of csv=p=0 "$f") | |
| w="${dims%%,*}" | |
| h="${dims##*,}" | |
| if (( h > w )); then | |
| orient="Vertical" | |
| else | |
| orient="Horizontal" | |
| fi | |
| new="${prefix}${title} - ${orient}.mp4" | |
| if [[ "$f" == "$new" ]]; then | |
| continue | |
| fi | |
| if [[ -e "$new" ]]; then | |
| echo "ABORT: target already exists: $new (from $f)" >&2 | |
| echo "Resolve this conflict manually, then re-run." >&2 | |
| exit 1 | |
| fi | |
| if (( apply )); then | |
| mv -- "$f" "$new" | |
| echo "renamed: $f -> $new" | |
| else | |
| printf '%s -> %s\n' "$f" "$new" | |
| fi | |
| done | |
| if (( ! apply )); then | |
| echo | |
| echo "(dry-run — re-run with --apply to rename)" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment