]> gitweb.hhaalo.de Git - albentohandy.git/commitdiff
add: flac to mp3 integration albumtohandy
authorBastian Dehn <hhaalo@arcor.de>
Sat, 5 Dec 2020 18:22:33 +0000 (19:22 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 5 Dec 2020 18:22:33 +0000 (19:22 +0100)
albentohandy

index cc0d412fe090320718846fefef2c4edec1d16bae..3cace97c764a5e5bf7f65be0f8a887913308ec61 100755 (executable)
@@ -12,10 +12,11 @@ NAME
     albumtohandy - konvertiert flac to mp3 von einer Sammlung
 
 SYNOPSIS
-    albentohandy [-i <inputfile] [-m <destfolder] [-r] [-h]
+    albentohandy [-3] [-i <inputfile] [-m <destfolder] [-r] [-h]
 
 OPTIONS
     -h                      show this help
+    -3                      convert to mp3
     -i <file>               input Datei default=albumlist
     -m <dest>               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"