From 046d2eae47367ed300ecf5d3599b64929cd10f1f Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Tue, 15 Jul 2025 18:09:17 +0200 Subject: [PATCH] change mp3 to lib --- albentohandy | 95 +++------------------------------------------------- libs/mp3.sh | 87 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 91 deletions(-) create mode 100644 libs/mp3.sh diff --git a/albentohandy b/albentohandy index 77f40c0..eb7ebb1 100755 --- a/albentohandy +++ b/albentohandy @@ -38,101 +38,14 @@ load_libraries() [ -f "$BASHLIBS/voribs.sh" ] \ || errlog "library vorbis.sh not found" \ || return $? + [ -f "$BASHLIBS/mp3.sh" ] \ + || errlog "library mp3.sh not found" \ + || return $? source "$BASHLIBS/voribs.sh" + source "$BASHLIBS/mp3.sh" } -#### BEGIN MP3 #### - -read_flac_to_mp3_tags() -{ - local inputfile="$1" - local outputfile="$2" - local 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 - 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 -} - -encoding_flac_to_mp3() -{ - local readonly inputfile="$1" - local readonly outputfile="$2" - - nice --adjustment=10 flac --totally-silent --stdout --decode \ - "$inputfile" \ - | nice --adjustment=15 lame --silent \ - -b 192 \ - --noreplaygain \ - - "$outputfile" -} - -flac_to_mp3() -{ - local inputfile="$1" - local outputfile="${inputfile/.flac/.mp3}" - - encoding_flac_to_mp3 "$inputfile" "$outputfile" - read_flac_to_mp3_tags "$inputfile" "$outputfile" -} - -convert_flac_to_mp3() -{ - local workdir="$1" - - 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 \ - flac_to_mp3 {} -} - -#### END MP3 #### #### BEGIN OPUS #### flac_to_opus() diff --git a/libs/mp3.sh b/libs/mp3.sh new file mode 100644 index 0000000..c8e7be0 --- /dev/null +++ b/libs/mp3.sh @@ -0,0 +1,87 @@ +read_flac_to_mp3_tags() +{ + local inputfile="$1" + local outputfile="$2" + local 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 + 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 +} + +encoding_flac_to_mp3() +{ + local readonly inputfile="$1" + local readonly outputfile="$2" + + nice --adjustment=10 flac --totally-silent --stdout --decode \ + "$inputfile" \ + | nice --adjustment=15 lame --silent \ + -b 192 \ + --noreplaygain \ + - "$outputfile" +} + +flac_to_mp3() +{ + local inputfile="$1" + local outputfile="${inputfile/.flac/.mp3}" + + encoding_flac_to_mp3 "$inputfile" "$outputfile" + read_flac_to_mp3_tags "$inputfile" "$outputfile" +} + +convert_flac_to_mp3() +{ + local workdir="$1" + + 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 \ + flac_to_mp3 {} +} -- 2.47.3