Here's what I've done. It seemed to work (but sadly bpm-tag was not accurate enough for lots of songs...).
#!/bin/bash
cd /path/to/my/library
while IFS= read -r -d '' FILE; do
BPM=$(bpm-tag -f -n "$FILE" 2>&1 | sed "s/.mp3:/%/" | cut -d'%' -f2 | sed "s/ BPM//" | sed "s/^ //" | cut -d'.' -f1)
#bpm-tag has its output in stderr, so I use 2>&1 to redirect it to stdout, then format it with sed and cut
if [ "$BPM" -le 130 ]
then cp "$FILE" /path/to/my/library/Slow/
elif [ "$BPM" -le 180 ]
then cp "$FILE" /path/to/my/library/Medium/
else cp "$FILE" /path/to/my/library/Fast/
fi
done < <(find . -type f -name '*.mp3' -print0)
Here doing
while IFS= read -r -d '' FILE; do
echo "$FILE"
done < <(find . -type f -name '*.mp3' -print0)
prints all the files (-type f) ending in .mp3 (-name '*.mp3') that are in the folder or one of its subfolders. As I understand it, the -print0 and -r -d '' options are for formatting purposes, but I don't really get how it works.