balance-folders.sh (394B)
1 #!/usr/bin/env bash 2 3 root="$(pwd)" 4 5 oldIFS="$IFS" 6 IFS=$'\n' 7 dirs=( $(find "$1" -type d) ) 8 IFS="$oldIFS" 9 10 for dir in "${dirs[@]}"; do 11 # Only leaf dirs, in theory should be no music in non-leaf dirs 12 if [ "$(find "$dir" -type d | wc -l)" -gt 2 ]; then 13 continue 14 fi 15 cd "$dir" 16 if [[ "$(ls | head -n 1)" == *".m4a" ]]; then 17 aacgain -c -r -m 1 *.m4a 18 else 19 rsgain easy . 20 fi 21 cd "$root" 22 done