Skip to content

Instantly share code, notes, and snippets.

@kmullin
Last active December 18, 2015 14:39
Show Gist options
  • Save kmullin/5798418 to your computer and use it in GitHub Desktop.
Save kmullin/5798418 to your computer and use it in GitHub Desktop.
Flac to MP3 script
#!/bin/sh
for a in *.flac; do
OUTF=${a%.flac}.mp3
ARTIST=`metaflac "$a" --show-tag=ARTIST | sed s/.*=//g`
TITLE=`metaflac "$a" --show-tag=TITLE | sed s/.*=//g`
ALBUM=`metaflac "$a" --show-tag=ALBUM | sed s/.*=//g`
GENRE=`metaflac "$a" --show-tag=GENRE | sed s/.*=//g`
TRACKNUMBER=`metaflac "$a" --show-tag=TRACKNUMBER | sed s/.*=//g`
DATE=`metaflac "$a" --show-tag=DATE | sed s/.*=//g`
flac -c -d "$a" | lame --noreplaygain --preset extreme \
--add-id3v2 --pad-id3v2 --ignore-tag-errors --tt "$TITLE" --tn "${TRACKNUMBER:-0}" \
--ta "$ARTIST" --tl "$ALBUM" --ty "$DATE" --tg "${GENRE:-12}" \
- "$OUTF"
RESULT=$?
if [ "$1" ] && [ "$1" = "-d" ] && [ $RESULT -eq 0 ]; then
rm "$a"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment