]> gitweb.hhaalo.de Git - albentohandy.git/commitdiff
change libs with default execute interface
authorBastian Dehn <hhaalo@arcor.de>
Sat, 19 Jul 2025 08:13:12 +0000 (10:13 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 19 Jul 2025 08:13:12 +0000 (10:13 +0200)
albentohandy
libs/flac.sh
libs/mp3.sh
libs/opus.sh
libs/vorbis.sh [new file with mode: 0644]
libs/voribs.sh [deleted file]

index 1c43c71df5e1849563c009f0b823eaa53923969c..ea43af15b076711719b0a2e177578217139da224 100755 (executable)
@@ -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"
index 8772bb111b4c11937be5d89f87e13f03a3492eda..a39019dd01a34d585fca9e159fcc12fa46d52fbe 100644 (file)
@@ -18,4 +18,11 @@ check_flac_programs()
                || return $?
 }
 
+execute()
+{
+       local workdir="$1"
+
+       picture_to_flac "$workdir" || return $?
+}
+
 check_flac_programs
index f8f0d4f5de429cb9874dc22953657e10981c77b9..b419465d5bd985c805bd3c9aa03c89565730904d 100644 (file)
@@ -102,4 +102,11 @@ check_mp3_programs()
                || return $?
 }
 
+execute()
+{
+       local workdir="$1"
+
+       convert_flac_to_mp3 "$workdir" || return $?
+}
+
 check_mp3_programs
index 81a954bafff6eaf95b62ae21c29bf9bb17425747..19a2a917ec6b02449c79007c198d3e35aa054b5b 100644 (file)
@@ -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 (file)
index 0000000..98af34c
--- /dev/null
@@ -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 (file)
index 673cf8d..0000000
+++ /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