#!/bin/sh #flac2mp3 error(){ echo $@ 1>&2; exit 1; } r=0 rem(){ if [ $r -eq 1 ]; then rm "$1" fi } flac2mp3(){ data=$1 echo " -----------------------Working on $data" if [ -d "$data" ]; then for file in "$data"*; do if [ -d "$file" ]; then file="$file"/ fi flac2mp3 "$file" wait done elif [[ "$data" == *.flac ]]; then flac -d --stdout "$data" > temp.wav wait echo " ---------------------------------$data to wav done" lame temp.wav "$data".mp3 wait echo " ---------------------------------$data to $data.mp3 done" rm temp.wav rem "$data" fi } if [ $# -eq 0 ]; then error "Wrong arguments" fi echo ============================================================ if [ $# -eq 1 ]; then flac2mp3 "$1" elif [ $# -eq 2 ] && [ $1 == "-r" ]; then r=1 flac2mp3 "$2" else error "Wrong arguments!" fi
flac2mp3 yourMusicFolder/
flac2mp3 -r yourMusicFolder/
#!/bin/bash if [ "${1}" == '' ]; then shellDir="$PWD" else shellDir="${1}" fi prefix=/home/share/music/_mp3 find "${shellDir}" -name '*.flac' -print | while read fn; do ARTIST=`metaflac "$fn" --show-tag=ARTIST | sed s/.*=//g` TITLE=`metaflac "$fn" --show-tag=TITLE | sed s/.*=//g` ALBUM=`metaflac "$fn" --show-tag=ALBUM | sed s/.*=//g` GENRE=`metaflac "$fn" --show-tag=GENRE | sed s/.*=//g` TRACKNUMBER=`metaflac "$fn" --show-tag=TRACKNUMBER | sed s/.*=//g` DATE=`metaflac "$fn" --show-tag=DATE | sed s/.*=//g` newpath="${prefix}/$ARTIST/$ALBUM" newfile=${TITLE}.mp3 echo $newfile mkdir -p "${newpath}" flac -c -d "${fn}" | lame -mj -q 0 --vbr-new -V 0 -s 44.1 - "${newpath}/${newfile}" id3 -t "$TITLE" -T "${TRACKNUMBER:-0}" -a "$ARTIST" -A "$ALBUM" -y "$DATE" -g "${GENRE:-12}" "${newpath}/${newfile}" done
Source: https://habr.com/ru/post/148171/
All Articles