From: Bastian Dehn Date: Sat, 5 Dec 2020 18:22:33 +0000 (+0100) Subject: add: flac to mp3 integration albumtohandy X-Git-Tag: v1.0.0^2~67 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=45777402499443ba3dd9df676c02f38683144333;p=albentohandy.git add: flac to mp3 integration albumtohandy --- diff --git a/albentohandy b/albentohandy index cc0d412..3cace97 100755 --- a/albentohandy +++ b/albentohandy @@ -12,10 +12,11 @@ NAME albumtohandy - konvertiert flac to mp3 von einer Sammlung SYNOPSIS - albentohandy [-i input Datei default=albumlist -m kopiert das Arbeitsverzeichnis in das angegeben Zielverzeichnis @@ -26,6 +27,98 @@ OPTIONS EOF } +ReadFlacToMp3Tags() +{ + local readonly INPUTFILE="$1" + local readonly OUTPUTFILE="$2" + local readonly INPUTFILEDIR=${INPUTFILE%/*} + + # get the tags from flac file + local readonly ARTIST=$(metaflac "$INPUTFILE" \ + --show-tag=ARTIST | sed s/.*=//g) + local readonly TITLE=$(metaflac "$INPUTFILE" \ + --show-tag=TITLE | sed s/.*=//g) + local readonly ALBUM=$(metaflac "$INPUTFILE" \ + --show-tag=ALBUM | sed s/.*=//g) + local readonly GENRE=$(metaflac "$INPUTFILE" \ + --show-tag=GENRE | sed s/.*=//g) + local readonly TRACKNUMBER=$(metaflac "$INPUTFILE" \ + --show-tag=TRACKNUMBER | sed s/.*=//g) + local readonly DATE=$(metaflac "$INPUTFILE" \ + --show-tag=DATE | sed s/.*=//g) + local readonly RRL=$(metaflac "$INPUTFILE" \ + --show-tag=REPLAYGAIN_REFERENCE_LOUDNESS | tr '=' ':') + local readonly RTG=$(metaflac "$INPUTFILE" \ + --show-tag=REPLAYGAIN_TRACK_GAIN | tr '=' ':') + local readonly RTP=$(metaflac "$INPUTFILE" \ + --show-tag=REPLAYGAIN_TRACK_PEAK | tr '=' ':') + local readonly RAG=$(metaflac "$INPUTFILE" \ + --show-tag=REPLAYGAIN_ALBUM_GAIN | tr '=' ':') + local readonly RAP=$(metaflac "$INPUTFILE" \ + --show-tag=REPLAYGAIN_ALBUM_PEAK | tr '=' ':') + + # -------------------------------------------------- + + # ID3v2.3 tagging with cover and without cover + local eyed3Command="eyeD3 --v2 --to-v2.3 \ + --artist=\"$ARTIST\" \ + --title=\"$TITLE\" \ + --album=\"$ALBUM\" \ + --genre=\"${GENRE:-12}\" \ + --track=\"${TRACKNUMBER:-0}\" --recording-date=\"$DATE\" \ + --user-text-frame=\"$RRL\" \ + --user-text-frame=\"$RTG\" \ + --user-text-frame=\"$RTP\" \ + --user-text-frame=\"$RAG\" \ + --user-text-frame=\"$RAP\"" + + # add cover picture to command + if [ -f $INPUTFILEDIR/cover.jpg ]; then + local eyed3Command+=" \ + --add-image=\"$INPUTFILEDIR/cover.jpg\":FRONT_COVER" + fi + + # finally command end + local eyed3Command+=" \"$OUTPUTFILE\" > /dev/null 2>&1" + + # execute eyeD3 command + eval $eyed3Command +} + +EncodingFlacToMp3() +{ + local readonly INPUTFILE="$1" + local readonly OUTPUTFILE="$2" + + # stream flac into the lame encoder + nice --adjustment=10 flac --silent --stdout --decode "$INPUTFILE" \ + | nice --adjustment=15 lame --silent \ + -b 192 --noreplaygain - "$OUTPUTFILE" +} + +FlacToMp3() +{ + local readonly INPUTFILE="$1" + local readonly OUTPUTFILE="${INPUTFILE[@]/%flac/mp3}" + + EncodingFlacToMp3 "$INPUTFILE" "$OUTPUTFILE" + ReadFlacToMp3Tags "$INPUTFILE" "$OUTPUTFILE" +} + +ConvertFlacToMp3() +{ + local readonly workdir="$1" + local readonly paralleopts="$2" + + export -f FlacToMp3 + export -f EncodingFlacToMp3 + export -f ReadFlacToMp3Tags + find $workdir -name '*.flac' \ + | sort \ + | parallel --will-cite --ungroup --eta --progress \ + --sshlogin $parallelopts FlacToMp3 {} +} + MakeSymlinksToWork() { local readonly workdir="$1" @@ -172,7 +265,8 @@ LoadConfig() ExistsBasicProgramms() { local exists=true - local programms=("vorbiscomment" "flac" "oggenc" "parallel") + local programms=("vorbiscomment" "flac" "oggenc" "parallel" "lame" \ + "eyeD3") for programm in $programms; do if [ ! -f /usr/bin/$programm ]; then @@ -192,14 +286,18 @@ SetDefaultVariables() parallelopts=":" curphase=1 phase=3 + mp3=false removework=false cptodest=false } ReadArguments() { - while getopts "hi:m:rw:" optname; do + while getopts "3hi:m:rw:" optname; do case "$optname" in + "3") + mp3=true; + ;; "h") Usage exit 0 @@ -247,9 +345,16 @@ ConvertProcess() printf "create symlinks of flac's in %s\n" "$WORK" MakeSymlinksToWork "$WORK" "$MUSICPATH" "$albumlist" - printf "\nPhase %02d of %02d: flac -> ogg\n" $((curphase++)) $phase - ConvertCoverToMeta "$WORK" "$parallelopts" "$SCRIPTPATH" - ConvertFlacToOgg "$WORK" "$parallelopts" "$SCRIPTPATH" + if [ ! $mp3 == true ]; then + printf "\nPhase %02d of %02d: flac -> ogg\n" \ + $((curphase++)) $phase + ConvertCoverToMeta "$WORK" "$parallelopts" + ConvertFlacToOgg "$WORK" "$parallelopts" + else + printf "\nPhase %02d of %02d: flac -> mp3\n" \ + $((curphase++)) $phase + ConvertFlacToMp3 "$WORK" "$parallelopts" + fi printf "\nPhase %02d of %02d: " $((curphase++)) $phase printf "remove flac's\n\n"