#!/bin/bash
# strip-tags.sh - keep only the ID3v2 frames listed in $oktags, drop everything else.
# Needs eyeD3 >= 0.9 (sudo apt install eyed3). Run it from the top of your music tree.
# savvyadmin.com/strip-all-unwanted-mp3-id3-tags/ - 2026 edition of the 2014 script.
set -euo pipefail
oktags="TALB APIC TCON TPE1 TPE2 TPE3 TIT2 TRCK TYER TDRC TCOM TPOS"
present=$(find . -iname '*.mp3' -exec eyeD3 --no-color -v {} + 2>/dev/null | grep -oE '^[A-Z0-9]{4} \(' | cut -c1-4 | sort -u | tr '\n' ' ')
strip=""
for f in $present; do case " $oktags " in *" $f "*) ;; *) strip="$strip --remove-frame $f";; esac; done
echo "Frames present: $present"
echo "Frames to strip: ${strip:-none}"
read -rp "Press Enter to strip them, Ctrl-C to abort " _
find . -iname '*.mp3' -exec eyeD3 --quiet --preserve-file-times --to-v2.3 --remove-v1 --remove-all-comments --remove-all-unknown $strip {} +
echo "Done."
