Skip to content

Instantly share code, notes, and snippets.

@BobbyRyterski
Last active December 27, 2015 10:39
Show Gist options
  • Save BobbyRyterski/7312272 to your computer and use it in GitHub Desktop.
Save BobbyRyterski/7312272 to your computer and use it in GitHub Desktop.
ffp.sh

ffp.sh

A BASH script to generate FLAC fingerprint files.

Usage

./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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment