From: Bastian Dehn Date: Sat, 19 Jul 2025 08:13:12 +0000 (+0200) Subject: change libs with default execute interface X-Git-Tag: v1.0.0^2~42 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=5cccdcb5532631dc55b31bd06b9207eed6a22c81;p=albentohandy.git change libs with default execute interface --- diff --git a/albentohandy b/albentohandy index 1c43c71..ea43af1 100755 --- a/albentohandy +++ b/albentohandy @@ -103,6 +103,21 @@ check_programms() || return $? } +execute_program() +{ + local lib="$1" + local workdir="$2" + + [ -f "$LIBS/$lib" ] \ + || errlog "file $LIBS/$lib does not exists" \ + || return $? + + mkdir -p "$workdir" + make_symlinks_to_work "albumlist" "$workdir" "$MUSICPATH" || return $? + source "$LIBS/$lib" || return $? + execute "$workdir" || return $? +} + convert_process() { local format="$1" @@ -112,39 +127,11 @@ convert_process() || errlog "file albumlist does not exists" \ || return $? - mkdir -p $workdir - make_symlinks_to_work "albumlist" "$workdir" $MUSICPATH \ - || return $? - case "$format" in - "mp3") - [ -f "$LIBS/mp3.sh" ] \ - || errlog "file $LIBS/mp3.sh does not exists" \ - || return $? - source "$LIBS/mp3.sh" || return $? - convert_flac_to_mp3 "$workdir" || return $? - ;; - "flac") - [ -f "$LIBS/flac.sh" ] \ - || errlog "file $LIBS/mp3.sh does not exists" \ - || return $? - source "$LIBS/flac.sh" || return $? - picture_to_flac "$workdir" - ;; - "opus") - [ -f "$LIBS/opus.sh" ] \ - || errlog "file $LIBS/mp3.sh does not exists" \ - || return $? - source "$LIBS/opus.sh" || return $? - convert_flac_to_opus "$workdir" - ;; - *) - [ -f "$LIBS/voribs.sh" ] \ - || errlog "file $LIBS/mp3.sh does not exists" \ - || return $? - source "$LIBS/voribs.sh" || return $? - convert_flac_to_ogg "$workdir" || return $? - ;; + "mp3") execute_program "mp3.sh" "$workdir" || return $? ;; + "flac") execute_program "flac.sh" "$workdir" || return $? ;; + "opus") execute_program "opus.sh" "$workdir" || return $? ;; + *) execute_program "vorbis.sh" "$workdir" || return $? ;; esac cleanup_cover "$workdir" diff --git a/libs/flac.sh b/libs/flac.sh index 8772bb1..a39019d 100644 --- a/libs/flac.sh +++ b/libs/flac.sh @@ -18,4 +18,11 @@ check_flac_programs() || return $? } +execute() +{ + local workdir="$1" + + picture_to_flac "$workdir" || return $? +} + check_flac_programs diff --git a/libs/mp3.sh b/libs/mp3.sh index f8f0d4f..b419465 100644 --- a/libs/mp3.sh +++ b/libs/mp3.sh @@ -102,4 +102,11 @@ check_mp3_programs() || return $? } +execute() +{ + local workdir="$1" + + convert_flac_to_mp3 "$workdir" || return $? +} + check_mp3_programs diff --git a/libs/opus.sh b/libs/opus.sh index 81a954b..19a2a91 100644 --- a/libs/opus.sh +++ b/libs/opus.sh @@ -32,4 +32,11 @@ check_opus_programs() || return $? } +execute() +{ + local workdir="$1" + + convert_flac_to_opus "$workdir" || return $? +} + check_opus_programs diff --git a/libs/vorbis.sh b/libs/vorbis.sh new file mode 100644 index 0000000..98af34c --- /dev/null +++ b/libs/vorbis.sh @@ -0,0 +1,119 @@ +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" +} + +write_hex_to_file() +{ + local number="$1" + local outputfile="$2" + local hex_number=$(printf "%08x" "$number") + + for i in {0..6..2}; do + printf "%b" "\x${hex_number:$i:2}" >> $outputfile + done +} + +cover_to_metadata() +{ + local inputfile="$1" + local outputfile="${inputfile/.jpg/.txt}" + local filesize=$(cat $inputfile | wc -c) + + # picture typ (jpg) + write_hex_to_file "3" "$outputfile" + # mime type (image/jpeg) + write_hex_to_file "10" "$outputfile" + printf "%s" "image/jpeg" >> $outputfile + # description length (zero) + write_hex_to_file "0" "$outputfile" + # width (zero) + write_hex_to_file "0" "$outputfile" + # heigth (zero) + write_hex_to_file "0" "$outputfile" + # color depth (zero) + write_hex_to_file "0" "$outputfile" + # color count (zero) + write_hex_to_file "0" "$outputfile" + # file size + write_hex_to_file "$filesize" "$outputfile" + cat $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 + export -f cover_to_metadata + export -f write_hex_to_file + find $workdir -name '*.jpg' \ + | sort \ + | parallel --will-cite --ungroup \ + cover_to_metadata {} + find $workdir -name '*.flac' \ + | sort \ + | parallel --will-cite --ungroup --eta --progress \ + flac_to_vorbis "{}" +} + +check_vorbis_programs() +{ + command -v flac > /dev/null \ + || errlog "command flac not found" \ + || return $? + command -v metaflac > /dev/null \ + || errlog "command metaflac not found" \ + || return $? + command -v oggenc > /dev/null \ + || errlog "command oggenc not found" \ + || return $? + command -v vorbiscomment > /dev/null \ + || errlog "command vorbiscomment not found" \ + || return $? + command -v parallel > /dev/null \ + || errlog "command parallel not found" \ + || return $? +} + +execute() +{ + local workdir="$1" + + convert_flac_to_ogg "$workdir" || return $? +} + +check_vorbis_programs diff --git a/libs/voribs.sh b/libs/voribs.sh deleted file mode 100644 index 673cf8d..0000000 --- a/libs/voribs.sh +++ /dev/null @@ -1,112 +0,0 @@ -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" -} - -write_hex_to_file() -{ - local number="$1" - local outputfile="$2" - local hex_number=$(printf "%08x" "$number") - - for i in {0..6..2}; do - printf "%b" "\x${hex_number:$i:2}" >> $outputfile - done -} - -cover_to_metadata() -{ - local inputfile="$1" - local outputfile="${inputfile/.jpg/.txt}" - local filesize=$(cat $inputfile | wc -c) - - # picture typ (jpg) - write_hex_to_file "3" "$outputfile" - # mime type (image/jpeg) - write_hex_to_file "10" "$outputfile" - printf "%s" "image/jpeg" >> $outputfile - # description length (zero) - write_hex_to_file "0" "$outputfile" - # width (zero) - write_hex_to_file "0" "$outputfile" - # heigth (zero) - write_hex_to_file "0" "$outputfile" - # color depth (zero) - write_hex_to_file "0" "$outputfile" - # color count (zero) - write_hex_to_file "0" "$outputfile" - # file size - write_hex_to_file "$filesize" "$outputfile" - cat $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 - export -f cover_to_metadata - export -f write_hex_to_file - find $workdir -name '*.jpg' \ - | sort \ - | parallel --will-cite --ungroup \ - cover_to_metadata {} - find $workdir -name '*.flac' \ - | sort \ - | parallel --will-cite --ungroup --eta --progress \ - flac_to_vorbis "{}" -} - -check_vorbis_programs() -{ - command -v flac > /dev/null \ - || errlog "command flac not found" \ - || return $? - command -v metaflac > /dev/null \ - || errlog "command metaflac not found" \ - || return $? - command -v oggenc > /dev/null \ - || errlog "command oggenc not found" \ - || return $? - command -v vorbiscomment > /dev/null \ - || errlog "command vorbiscomment not found" \ - || return $? - command -v parallel > /dev/null \ - || errlog "command parallel not found" \ - || return $? -} - -check_vorbis_programs