]> gitweb.hhaalo.de Git - albentohandy.git/commitdiff
add implement mp3 encode
authorBastian Dehn <hhaalo@arcor.de>
Fri, 25 Sep 2026 18:09:46 +0000 (20:09 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Fri, 25 Sep 2026 18:09:46 +0000 (20:09 +0200)
src/lib/mp3.sh

index b2e195e98b3cee8481b3fcf6be7f5c8a7caec74d..05a709a17e648d6d2f91ffdb92ab779bc964b79b 100644 (file)
@@ -25,4 +25,105 @@ mp3_check_programs()
                || return $?
 }
 
-mp3_check_programs || return $?
\ No newline at end of file
+mp3_flacmetadata_to_mp3_tag()
+{
+       local flac="$1"
+       local mp3="$2"
+       local path=${flac%/*}
+       local artist=
+       local title=
+       local album=
+       local genre=
+       local genre=
+       local trackno=
+       local date=
+       local rrl=
+       local rtg=
+       local rtp=
+       local rag=
+       local rap=
+
+       # get the tags from flac file
+       title=$(metaflac --show-tag=TITLE "$flac")
+       artist=$(metaflac --show-tag=ARTIST "$flac")
+       album=$(metaflac --show-tag=ALBUM "$flac")
+       date=$(metaflac --show-tag=DATE "$flac")
+       trackno=$(metaflac --show-tag=TRACKNUMBER "$flac")
+       genre=$(metaflac --show-tag=GENRE "$flac")
+
+       rrl=$(metaflac --show-tag=REPLAYGAIN_REFERENCE_LOUDNESS "$flac")
+       rtg=$(metaflac --show-tag=REPLAYGAIN_TRACK_GAIN "$flac")
+       rtp=$(metaflac --show-tag=REPLAYGAIN_TRACK_PEAK "$flac")
+       rag=$(metaflac --show-tag=REPLAYGAIN_ALBUM_GAIN "$flac")
+       rap=$(metaflac --show-tag=REPLAYGAIN_ALBUM_PEAK "$flac")
+
+       artist=${artist/*=/}
+       title=${title/*=/}
+       album=${album/*=/}
+       genre=${genre/*=/}
+       genre=${genre:=12}
+       trackno=${trackno/*=/}
+       trackno=${trackno:=0}
+       date=${date/*=/}
+
+       rrl=${rrl/=/:}
+       rtg=${rtg/=/:}
+       rtp=${rtp/=/:}
+       rag=${rag/=/:}
+       rap=${rap/=/:}
+       # --------------------------------------------------
+
+       # ID3v2.3 tagging with cover and without cover
+       eyeD3 --v2 \
+               --to-v2.3 \
+               --title="$title" \
+               --artist="$artist" \
+               --album="$album" \
+               --recording-date="$date" \
+               --track="$trackno" \
+               --genre="$genre" \
+               --user-text-frame="$rrl" \
+               --user-text-frame="$rtg" \
+               --user-text-frame="$rtp" \
+               --user-text-frame="$rag" \
+               --user-text-frame="$rap" \
+               --add-image="$path/cover.jpg":FRONT_COVER \
+               "$mp3" > /dev/null 2>&1
+}
+
+mp3_encode_flac()
+{
+       local flac="$1"
+       local mp3="${flac/.flac/.mp3}"
+       BITRATE=${BITRATE:-"192"}
+
+       nice --adjustment=10 flac \
+               --totally-silent \
+               --stdout \
+               --decode \
+               "$flac" \
+               | nice --adjustment=15 lame \
+               --silent \
+               -b "$BITRATE" \
+               -t \
+               --noreplaygain \
+               - "$mp3"
+       mp3_flacmetadata_to_mp3_tag "$flac" "$mp3"
+}
+
+mp3_encode()
+{
+       local work_path="$1"
+       find "$work_path" -name '*.flac' \
+               | sort \
+               | parallel \
+               --will-cite \
+               --ungroup \
+               --eta \
+               --progress \
+               mp3_encode_flac {}
+}
+
+mp3_check_programs || return $?
+export -f mp3_encode_flac
+export -f mp3_flacmetadata_to_mp3_tag
\ No newline at end of file