Skip to content

Instantly share code, notes, and snippets.

@takeyourhatoff
Created January 15, 2014 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takeyourhatoff/8446811 to your computer and use it in GitHub Desktop.
Save takeyourhatoff/8446811 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
# spectro.sh: creates forum code with spectrograms of a directory's flac files
# Deps: sox, optipng and curl
# Usage: spectro.sh location/of/album/
APIKEY="6bf8cf819aff12a"
SOXARGS=(
"remix 1 spectrogram -x 3000 -y 513 -w Kaiser"
"remix 1 spectrogram -x 3000 -y 513 -w Kaiser -S 0:40 -d 0:04"
)
if [ $# -gt 0 ]; then
cd "$@"
fi
function create_spectrogram {
sox "$2" -n $1 -h -t "$2" -o "$2.spectrogram.png"
optipng -quiet "$2.spectrogram.png"
response=$(curl -H "Authorization: CLIENT-ID $APIKEY" -F "image=@$2.spectrogram.png" \
https://api.imgur.com/3/image.xml 2>/dev/null)
url=$(echo $response | sed -r 's/.*<link>(.*)<\/link>.*/\1/')
rm "$2.spectrogram.png"
echo "$url"
}
echo "[hide=Spectrograms]"
for f in *.flac; do
echo " $f:"
for soxarg in "${SOXARGS[@]}"; do
echo " [img]"$(create_spectrogram "$soxarg" "$f")"[/img]"
done
done
echo "[/hide]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment