]> gitweb.hhaalo.de Git - albentohandy.git/commitdiff
refactor mp3
authorBastian Dehn <hhaalo@arcor.de>
Mon, 14 Jul 2025 17:48:30 +0000 (19:48 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Mon, 14 Jul 2025 17:48:30 +0000 (19:48 +0200)
albentohandy

index a89f07e91626601871a01e1d900a290005b643f1..bcaf8812972ec4bb5d92d0c9a5e031cffc4fb4ac 100755 (executable)
@@ -38,98 +38,92 @@ OPTIONS
 
 #### BEGIN MP3 ####
 
-ReadFlacToMp3Tags()
+read_flac_to_mp3_tags()
 {
-       local readonly INPUTFILE="$1"
-       local readonly OUTPUTFILE="$2"
-       local readonly INPUTFILEDIR=${INPUTFILE%/*}
+       local inputfile="$1"
+       local outputfile="$2"
+       local inputfiledir=${inputfile%/*}
 
        # get the tags from flac file
-       local readonly ARTIST=$(metaflac "$INPUTFILE" \
+       local readonly ARTIST=$(metaflac "$inputfile" \
                --show-tag=ARTIST | sed s/.*=//g)
-       local readonly TITLE=$(metaflac "$INPUTFILE" \
+       local readonly TITLE=$(metaflac "$inputfile" \
                --show-tag=TITLE | sed s/.*=//g)
-       local readonly ALBUM=$(metaflac "$INPUTFILE" \
+       local readonly ALBUM=$(metaflac "$inputfile" \
                --show-tag=ALBUM | sed s/.*=//g)
-       local readonly GENRE=$(metaflac "$INPUTFILE" \
+       local readonly GENRE=$(metaflac "$inputfile" \
                --show-tag=GENRE | sed s/.*=//g)
-       local readonly TRACKNUMBER=$(metaflac "$INPUTFILE" \
+       local readonly TRACKNUMBER=$(metaflac "$inputfile" \
                --show-tag=TRACKNUMBER | sed s/.*=//g)
-       local readonly DATE=$(metaflac "$INPUTFILE" \
+       local readonly DATE=$(metaflac "$inputfile" \
                --show-tag=DATE | sed s/.*=//g)
-       local readonly RRL=$(metaflac "$INPUTFILE" \
+       local readonly RRL=$(metaflac "$inputfile" \
                --show-tag=REPLAYGAIN_REFERENCE_LOUDNESS | tr '=' ':')
-       local readonly RTG=$(metaflac "$INPUTFILE" \
+       local readonly RTG=$(metaflac "$inputfile" \
                --show-tag=REPLAYGAIN_TRACK_GAIN | tr '=' ':')
-       local readonly RTP=$(metaflac "$INPUTFILE" \
+       local readonly RTP=$(metaflac "$inputfile" \
                --show-tag=REPLAYGAIN_TRACK_PEAK | tr '=' ':')
-       local readonly RAG=$(metaflac "$INPUTFILE" \
+       local readonly RAG=$(metaflac "$inputfile" \
                --show-tag=REPLAYGAIN_ALBUM_GAIN | tr '=' ':')
-       local readonly RAP=$(metaflac "$INPUTFILE" \
+       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\""
-
-       if [ -z $replaygainapply ]; then
-               local eyed3Command="$eyed3Command --user-text-frame=\"$RRL\" \
-               --user-text-frame=\"$RTG\" \
-               --user-text-frame=\"$RTP\" \
-               --user-text-frame=\"$RAG\" \
-               --user-text-frame=\"$RAP\""
-       fi
-
-       # 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
+       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-image="$inputfiledir/cover.jpg":FRONT_COVER \
+               "$outputfile" > /dev/null 2>&1
 }
 
-EncodingFlacToMp3()
+encoding_flac_to_mp3()
 {
-       local readonly INPUTFILE="$1"
-       local readonly OUTPUTFILE="$2"
+       local readonly inputfile="$1"
+       local readonly outputfile="$2"
 
-       # stream flac into the lame encoder
        nice --adjustment=10 flac --totally-silent --stdout --decode \
-               $replaygainapply "$INPUTFILE" \
+               "$inputfile" \
                | nice --adjustment=15 lame --silent \
-               -b 192 --noreplaygain - "$OUTPUTFILE"
+               -b 192 \
+               --noreplaygain \
+               - "$outputfile"
 }
 
-FlacToMp3()
+flac_to_mp3()
 {
-       local readonly INPUTFILE="$1"
-       local readonly OUTPUTFILE="${INPUTFILE[@]/%flac/mp3}"
+       local inputfile="$1"
+       local outputfile="${inputfile/.flac/.mp3}"
 
-       EncodingFlacToMp3 "$INPUTFILE" "$OUTPUTFILE"
-       ReadFlacToMp3Tags "$INPUTFILE" "$OUTPUTFILE"
+       encoding_flac_to_mp3 "$inputfile" "$outputfile"
+       read_flac_to_mp3_tags "$inputfile" "$outputfile"
 }
 
-ConvertFlacToMp3()
+convert_flac_to_mp3()
 {
-       local readonly WORKDIR="$1"
+       local workdir="$1"
 
-       declare -xf FlacToMp3
-       declare -xf EncodingFlacToMp3
-       declare -xf ReadFlacToMp3Tags
-       find $WORKDIR -name '*.flac' \
+       export -f flac_to_mp3
+       export -f encoding_flac_to_mp3
+       export -f read_flac_to_mp3_tags
+       find $workdir -name '*.flac' \
                | sort \
-               | parallel --will-cite --ungroup --eta --progress FlacToMp3 {}
+               | parallel --will-cite \
+               --ungroup \
+               --eta \
+               --progress \
+               flac_to_mp3 {}
 }
 
 #### END MP3 ####
@@ -408,7 +402,11 @@ convert_process()
                || return $?
 
        case "$format" in
-       "mp3") ;;
+       "mp3")
+               convert_flac_to_mp3 "$workdir"
+               cleanup_flac "$workdir"
+               cleanup_cover "$workdir"
+               ;;
        "flac")
                picture_to_flac "$workdir"
                cleanup_cover "$workdir"