#!/bin/bash shopt -s nullglob if test $@="--help"; then echo "flac2mp3" echo "Convert all FLACs in a directory to MP3s, using flac and lame. Matches all files in current directory with extension .flac. Passes all arguments along to lame. Preserves basic metadata." exit 0 fi if test ! `which flac`; then echo "This script requires flac." exit 127 fi if test ! `which lame`; then echo "This script requires lame." exit 127 fi for flac in *.flac do name=$(basename -s .flac "$flac") mp3="${name}.mp3" artist=$(metaflac --show-tag=ARTIST "$flac" | sed 's ....... ') album=$(metaflac --show-tag=ALBUM "$flac" | sed 's ...... ') title=$(metaflac --show-tag=TITLE "$flac" | sed 's ...... ') date=$(metaflac --show-tag=DATE "$flac" | sed 's ..... ') number=$(metaflac --show-tag=TRACKNUMBER "$flac" |sed 's ............ ') flac -c -d "$flac" | lame "$@" --tt "$title" --ta "$artist" --tl "$album" --ty "$date" --tn "$number" - "$mp3" done