|| return $?
}
+vorbis_write_number_to_byte()
+{
+ local number="$1"
+ local hex_number=
+ hex_number=$(printf "%08x" "$number")
+
+ for i in {0..6..2}; do
+ printf "%b" "\x${hex_number:$i:2}"
+ done
+}
+
+vorbis_cover_to_metadata()
+{
+ local cover="$1"
+ local covermetadata="${cover/.jpg/.txt}"
+ local filesize=$(wc --bytes "$cover")
+ filesize=${filesize/ */}
+
+ {
+ # picture typ (jpg)
+ vorbis_write_number_to_byte "3"
+ # mime type (image/jpeg)
+ vorbis_write_number_to_byte "10"
+ printf "%s" "image/jpeg"
+ # description length (zero)
+ vorbis_write_number_to_byte "0"
+ # width (zero)
+ vorbis_write_number_to_byte "0"
+ # heigth (zero)
+ vorbis_write_number_to_byte "0"
+ # color depth (zero)
+ vorbis_write_number_to_byte "0"
+ # color count (zero)
+ vorbis_write_number_to_byte "0"
+ # file size
+ vorbis_write_number_to_byte "$filesize"
+ cat "$cover"
+ } > "$covermetadata"
+}
+
+vorbis_encode()
+{
+ local work_path="$1"
+ find "$work_path" -name '*.jpg' \
+ | sort \
+ | parallel --will-cite --ungroup \
+ vorbis_cover_to_metadata {}
+}
+
vorbis_check_programs || return $?
\ No newline at end of file
setup() {
bats_load_library 'bats-support'
bats_load_library 'bats-assert'
+ mkdir --parents "build/tests/output"
source "src/lib/vorbis.sh"
}
+teardown() {
+ rm --recursive --force "build"
+}
+
# bats test_tags=vorbis:check_programs
@test "failed: check programs missing flac" {
command() {
assert_failure
assert_line --index 0 "❌ ERROR: command parallel not found"
+}
+
+# bats test_tags=vorbis:covermetadata
+@test "success: cover to metdata file" {
+ echo "testfile" > "build/tests/output/test.jpg"
+ {
+ printf "\x00\x00\x00\x03"
+ printf "\x00\x00\x00\x0a"
+ printf "image/jpeg"
+ printf "\x00\x00\x00\x00"
+ printf "\x00\x00\x00\x00"
+ printf "\x00\x00\x00\x00"
+ printf "\x00\x00\x00\x00"
+ printf "\x00\x00\x00\x00"
+ printf "\x00\x00\x00\x09"
+ printf "testfile\n"
+ } > "build/tests/output/expectedcover.txt"
+
+ run vorbis_cover_to_metadata "build/tests/output/test.jpg"
+
+ diff "build/tests/output/test.txt" "build/tests/output/expectedcover.txt"
}
\ No newline at end of file