#!/usr/bin/env bash root="${1:-.}" mode="${2:-}" THRESHOLD=40 find "$root" \( -iname '*.mp3' -o -iname '*.m4a' -o -iname '*.m4b' \) -print0 | while IFS= read -r -d '' f; do comment=$(ffprobe -v error \ -show_entries format_tags=comment \ -of default=nw=1:nk=1 \ -- "$f") description=$(ffprobe -v error \ -show_entries format_tags=description \ -of default=nw=1:nk=1 \ -- "$f") # trim comment comment="${comment#"${comment%%[![:space:]]*}"}" comment="${comment%"${comment##*[![:space:]]}"}" # ---- DELETE MODE ---- if [[ "$mode" == "--delete" && -n "$comment" && ${#comment} -lt $THRESHOLD ]]; then tmp=$(mktemp -p "$(dirname -- "$f")" ".fftmp.XXXXXX.${f##*.}") || continue echo "Removing short comment: $f" echo " comment: $comment" ffmpeg -nostdin -v error -y \ -i "$f" \ -map 0 \ -map_metadata 0 \ -c copy \ -metadata comment= \ "$tmp" && mv -f -- "$tmp" "$f" || { echo "FAILED: $f" >&2 rm -f -- "$tmp" } continue fi # ---- SCAN MODE ---- # only show short non-empty tags (<20 chars) for tag in comment description; do value="${!tag}" value="${value#"${value%%[![:space:]]*}"}" value="${value%"${value##*[![:space:]]}"}" if [[ -n "$value" && ${#value} -lt $THRESHOLD ]]; then printf "%s\n %s: %s\n\n" "$f" "$tag" "$value" fi done done