From: Bastian Dehn Date: Tue, 15 Jul 2025 16:06:55 +0000 (+0200) Subject: change voribs to lib X-Git-Tag: v1.0.0^2~52^2~4 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=9011029fabdc94d3372d468eb4a1e8caa6e1baf9;p=albentohandy.git change voribs to lib --- diff --git a/albentohandy b/albentohandy index 6239699..77f40c0 100755 --- a/albentohandy +++ b/albentohandy @@ -30,6 +30,18 @@ OPTIONS EOF } +load_libraries() +{ + [ -n "$BASHLIBS" ] \ + || errlog "missing BASHLIBS" \ + || return $? + [ -f "$BASHLIBS/voribs.sh" ] \ + || errlog "library vorbis.sh not found" \ + || return $? + + source "$BASHLIBS/voribs.sh" +} + #### BEGIN MP3 #### read_flac_to_mp3_tags() @@ -164,97 +176,6 @@ picture_to_flac() } #### END FLAC #### -#### BEGIN VORBIS #### - -read_flac_to_ogg_tags() -{ - local inputfile="$1" - local outputfile="$2" - local coverfile="${inputfile%/*}/cover.txt" - - metaflac --export-tags-to=- $inputfile \ - | vorbiscomment --commentfile - --write $outputfile - - [ -f $coverfile ] \ - || return 0 - - echo "METADATA_BLOCK_PICTURE=$(base64 --wrap 0 $coverfile)" \ - | vorbiscomment --commentfile - --raw --append $outputfile -} - -encoding_flac_to_ogg() -{ - local inputfile="$1" - local outputfile="$2" - - nice --adjustment=10 flac --totally-silent --stdout --decode \ - "$inputfile" \ - | nice --adjustment=15 oggenc --quiet --quality 6 \ - --output "$outputfile" - -} - -flac_to_vorbis() -{ - local inputfile="$1" - local outputfile="${inputfile/.flac/.ogg}" - - encoding_flac_to_ogg "$inputfile" "$outputfile" - read_flac_to_ogg_tags "$inputfile" "$outputfile" -} - -convert_flac_to_ogg() -{ - local workdir="$1" - - export -f flac_to_vorbis - export -f encoding_flac_to_ogg - export -f read_flac_to_ogg_tags - find $workdir -name '*.flac' \ - | sort \ - | parallel --will-cite --ungroup --eta --progress \ - flac_to_vorbis "{}" -} - -cover_to_metadata() -{ - local inputfile="$1" - local outputfile="${inputfile/.jpg/.txt}" - - # Picture Typ - printf "0: %.8x" 3 | xxd -r -g0 > $outputfile - # Mime type - printf "0: %.8x" $(printf "image/jpeg" | wc -c) \ - | xxd -r -g0 >> $outputfile - printf "image/jpeg" >> $outputfile - # Description - printf "0: %.8x" 0 | xxd -r -g0 >> $outputfile - # Width - printf "0: %.8x" 0 | xxd -r -g0 >> $outputfile - # Heigth - printf "0: %.8x" 0 | xxd -r -g0 >> $outputfile - # Color depth - printf "0: %.8x" 0 | xxd -r -g0 >> $outputfile - # Color Count - printf "0: %.8x" 0 | xxd -r -g0 >> $outputfile - # File Size - printf "0: %.8x" $(wc -c "$inputfile" \ - | cut --delimiter=' ' --fields=1) \ - | xxd -r -g0 >> $outputfile - cat $inputfile >> $outputfile -} - -convert_cover_to_metadata() -{ - local workdir="$1" - local covers=$(find $workdir -name '*.jpg' | sort) - - local cover= - for cover in $covers; do - cover_to_metadata "$cover" - done -} - -#### END VORBIS #### cleanup_flac() { @@ -379,6 +300,7 @@ main() { local format= + load_libraries || return $? check_programms || return $? load_config || return $? diff --git a/libs/voribs.sh b/libs/voribs.sh new file mode 100644 index 0000000..ed20fc6 --- /dev/null +++ b/libs/voribs.sh @@ -0,0 +1,87 @@ +read_flac_to_ogg_tags() +{ + local inputfile="$1" + local outputfile="$2" + local coverfile="${inputfile%/*}/cover.txt" + + metaflac --export-tags-to=- $inputfile \ + | vorbiscomment --commentfile - --write $outputfile + + [ -f $coverfile ] \ + || return 0 + + echo "METADATA_BLOCK_PICTURE=$(base64 --wrap 0 $coverfile)" \ + | vorbiscomment --commentfile - --raw --append $outputfile +} + +encoding_flac_to_ogg() +{ + local inputfile="$1" + local outputfile="$2" + + nice --adjustment=10 flac --totally-silent --stdout --decode \ + "$inputfile" \ + | nice --adjustment=15 oggenc --quiet --quality 6 \ + --output "$outputfile" - +} + +flac_to_vorbis() +{ + local inputfile="$1" + local outputfile="${inputfile/.flac/.ogg}" + + encoding_flac_to_ogg "$inputfile" "$outputfile" + read_flac_to_ogg_tags "$inputfile" "$outputfile" +} + +convert_flac_to_ogg() +{ + local workdir="$1" + + export -f flac_to_vorbis + export -f encoding_flac_to_ogg + export -f read_flac_to_ogg_tags + find $workdir -name '*.flac' \ + | sort \ + | parallel --will-cite --ungroup --eta --progress \ + flac_to_vorbis "{}" +} + +cover_to_metadata() +{ + local inputfile="$1" + local outputfile="${inputfile/.jpg/.txt}" + + # Picture Typ + printf "0: %.8x" 3 | xxd -r -g0 > $outputfile + # Mime type + printf "0: %.8x" $(printf "image/jpeg" | wc -c) \ + | xxd -r -g0 >> $outputfile + printf "image/jpeg" >> $outputfile + # Description + printf "0: %.8x" 0 | xxd -r -g0 >> $outputfile + # Width + printf "0: %.8x" 0 | xxd -r -g0 >> $outputfile + # Heigth + printf "0: %.8x" 0 | xxd -r -g0 >> $outputfile + # Color depth + printf "0: %.8x" 0 | xxd -r -g0 >> $outputfile + # Color Count + printf "0: %.8x" 0 | xxd -r -g0 >> $outputfile + # File Size + printf "0: %.8x" $(wc -c "$inputfile" \ + | cut --delimiter=' ' --fields=1) \ + | xxd -r -g0 >> $outputfile + cat $inputfile >> $outputfile +} + +convert_cover_to_metadata() +{ + local workdir="$1" + local covers=$(find $workdir -name '*.jpg' | sort) + + local cover= + for cover in $covers; do + cover_to_metadata "$cover" + done +}