#!/bin/bash # from http://www.linuxtutorialblog.com/post/solution-converting-flac-to-mp3 OUT_DIR=${OUT_DIR:="$HOME/tmp/mp3"} [ ! -d ${OUT_DIR} ] && mkdir -p ${OUT_DIR} # modify the lame options to your # preference lame_opts=" --vbr-new -V 2 -B 256 " for x in "${@}" do FLAC=${x} MP3=`basename "${FLAC%.flac}.mp3"` [ -r "$FLAC" ] || { echo can not read file \"$FLAC\" >&1 ; exit 1 ; } ; TITLE="" TRACKNUMBER="" GENRE="" DATE="" COMMENT="" ARTIST="" ALBUM="" Title="" Tracknumber="" Genre="" Date="" Comment="" Artist="" Album="" metaflac --export-tags-to=- "$FLAC" | sed 's/=\(.*\)/="\1"/' > $OUT_DIR/tmp.tmp . $OUT_DIR/tmp.tmp rm $OUT_DIR/tmp.tmp [ -z "$TITLE" ] && TITLE="$Title" [ -z "$TRACKNUMBER" ] && TRACKNUMBER="$Tracknumber" [ -z "$GENRE" ] && GENRE="$Genre" [ -z "$DATE" ] && DATE="$Date" [ -z "$COMMENT" ] && COMMENT="$Comment" [ -z "$ARTIST" ] && ARTIST="$Artist" [ -z "$ALBUM" ] && ALBUM="$Album" echo "Converting ${FLAC} to MP3 format" OUTFILE="${OUT_DIR}/$ARTIST/${DATE}_$ALBUM/$MP3" mkdir -p "${OUT_DIR}/$ARTIST/${DATE}_$ALBUM" flac -c -d "$FLAC" | lame ${lame_opts} - "$OUTFILE" id3v2 \ -a "$ARTIST" \ -A "$ALBUM" \ -t "$TITLE" \ -c "$COMMENT" \ -g "$GENRE" \ -y "$DATE" \ -T "$TRACKNUMBER" \ "$OUTFILE" done