bin-utils/flac2mp3.sh

63 lines
1.3 KiB
Bash
Raw Normal View History

2016-07-02 09:07:14 +00:00
#!/usr/bin/env bash
2015-05-30 16:42:42 +00:00
# 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
2016-12-09 21:26:39 +00:00
lame_opts=" --vbr-new -V 2 -B 256 "
2015-05-30 16:42:42 +00:00
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"
2016-12-09 21:26:39 +00:00
flac -c -d "$FLAC" | lame ${lame_opts} - "$OUTFILE"
2015-05-30 16:42:42 +00:00
id3v2 \
-a "$ARTIST" \
-A "$ALBUM" \
-t "$TITLE" \
-c "$COMMENT" \
-g "$GENRE" \
-y "$DATE" \
-T "$TRACKNUMBER" \
"$OUTFILE"
done