A BASH script to generate FLAC fingerprint files.
./ffp.sh DIR
| #!/usr/bin/env bash | |
| metaflac=${metaflac:-metaflac} | |
| ffp_filename=${ffp_filename:-ffp.txt} | |
| if [[ $# -ne 1 ]]; then | |
| cat <<EOF | |
| Usage: ./ffp.sh DIR | |
| Generates FLAC fingerprint files for all folders containing FLAC files in or under DIR. | |
| EOF | |
| exit 1 | |
| fi | |
| echo "Finding FLAC files in ${1}" | |
| _IFS=$IFS; IFS=$'\n'; | |
| dirs=($(find "$1" -type f -name *.flac -printf "%h\n" | sort -u)) | |
| count="${#dirs[*]}" | |
| if [[ $count -eq 0 ]]; then | |
| echo "No FLAC files found" | |
| exit | |
| fi | |
| echo "Creating fingerprints for ${count} folder(s)" | |
| i=0 | |
| for d in ${dirs[@]}; do | |
| i=$(( i + 1 )) | |
| printf "[%0*d/%d] %s " ${#count} ${i} ${count} "${d}" | |
| # use pushd so the ffp file only has filenames, no full path | |
| pushd "${d}" > /dev/null | |
| if [[ -e "$ffp_filename" ]] && [[ -s "$ffp_filename" ]]; then | |
| echo "exists" | |
| continue | |
| fi | |
| $metaflac --show-md5sum *.flac &> "$ffp_filename" \ | |
| && echo "created" \ | |
| || echo "failed" | |
| popd > /dev/null | |
| done | |
| IFS=$_IFS |