#!/usr/bin/env zsh # # Copyright (C) 2009 Nick Bowler # # Adds replaygain tags to the flac files in a directory. Assumes that all # the tracks from a CD are located in the same directory. Unless the -f flag # is specified, directories already containing replaygain tags will not be # processed. # # License WTFPL2: Do What The Fuck You Want To Public License, version 2. # This is free software: you are free to do what the fuck you want to. # There is NO WARRANTY, to the extent permitted by law. alias flactags='metaflac --export-tags-to=-' is_disc_dir() { local files [[ -d $1 ]] || return 1 files=($1/*.flac(N)) [[ $#files > 0 ]] || return 1 } has_replay_gain() { local files files=($1/*.flac(N)) for i in $files; do (flactags $i | grep -q REPLAYGAIN_REFERENCE) || return 1 done } force=0 while getopts 'f' opt $@; do case $opt in f) force=1 ;; \?) exit 1 ;; esac done shift $((OPTIND-1)) if [[ $# == 0 ]]; then printf 'usage: %s [-f] directory [directory ...]\n' $0 exit 1 fi for dir in $@; do printf '%s: ' $dir if ! is_disc_dir $dir; then printf 'not an album directory, skipping.\n' continue fi if [[ $force == 0 ]] && has_replay_gain $dir; then printf 'already done, skipping.\n' continue fi metaflac --add-replay-gain $dir/*.flac printf 'done.\n' done