]> gitweb.hhaalo.de Git - albentohandy.git/commitdiff
refactor write hex to file
authorBastian Dehn <hhaalo@arcor.de>
Fri, 18 Jul 2025 10:09:17 +0000 (12:09 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Fri, 18 Jul 2025 10:09:17 +0000 (12:09 +0200)
libs/voribs.sh

index e2295dcd7391f7ea956b5435266b06696bd8b052..09940dcd8a350a520f31f9c47d6de8a4a2a23342 100644 (file)
@@ -34,31 +34,40 @@ flac_to_vorbis()
        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)
-       local filesizehex=$(printf "%08x" "$filesize")
 
        # picture typ (jpg)
-       printf "%b" "\x0\x0\x0\x3" > $outputfile
+       write_hex_to_file "3" "$outputfile"
        # mime type (image/jpeg)
-       printf "%b%s" "\x0\x0\x0\xa" "image/jpeg" >> $outputfile
+       write_hex_to_file "10" "$outputfile"
+       printf "%s" "image/jpeg" >> $outputfile
        # description length (zero)
-       printf "%b" "\x0\x0\x0\x0" >> $outputfile
-       # Width (zero)
-       printf "%b" "\x0\x0\x0\x0" >> $outputfile
-       # Heigth (zero)
-       printf "%b" "\x0\x0\x0\x0" >> $outputfile
-       # Color depth (zero)
-       printf "%b" "\x0\x0\x0\x0" >> $outputfile
-       # Color Count (zero)
-       printf "%b" "\x0\x0\x0\x0" >> $outputfile
-       # File Size
-       for i in {0..6..2}; do
-               printf "%b" "\x${filesizehex:$i:2}" >> $outputfile
-       done
+       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
 }
 
@@ -70,6 +79,7 @@ convert_flac_to_ogg()
        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 \