return $lastexit
}
+flac_add_picture()
+{
+ local work_path="$1"
+ local flacs=
+ mapfile -t flacs < <(find "$work_path" -name '*.flac' | sort)
+
+ local output=
+ local filepath=
+ local flac=
+ for flac in "${flacs[@]}"; do
+ output=${flac/.flac/-out.flac}
+ filepath=${flac%/*}
+ metaflac \
+ --import-picture-from="3|image/jpeg|||$filepath/cover.jpg" \
+ --output-name="$output" \
+ "$flac"
+ mv "$output" "$flac"
+ done
+}
+
flac_check_programs()
{
command -v metaflac > /dev/null \
flac_encode()
{
local work_path="$1"
-
[ -n "$work_path" ] \
|| flac_errlog "missing work path" \
|| return $?
+ flac_add_picture "$work_path"
}
flac_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"
+ export METAFLAC_LOG="build/metaflac.log"
source "src/lib/flac.sh"
}
+teardown() {
+ rm --recursive --force "build"
+ rm --force "$METAFLAC_LOG"
+ unset METAFLAG_LOG
+}
+
# bats test_tags=flac:check_programs
@test "failed: check programs missing metaflac" {
command() {
assert_failure
assert_line --index 0 "❌ ERROR: missing work path"
+}
+
+# bats test_tags=flac:addpicture
+@test "success: add picture to flac" {
+ echo "testfile" > "build/tests/output/file.flac"
+ metaflac() {
+ {
+ printf "%s\n" "${#@}"
+ printf "%s\n" "${@}"
+ } > "$METAFLAC_LOG"
+ local file="$3"
+ cp "$file" "${file/.flac/-out.flac}"
+ }
+
+ run flac_encode "build/tests/output"
+
+ assert_success
+ assert_equal "$(awk 'NR==1 {print; exit}' "$METAFLAC_LOG")" "3"
+ assert_equal "$(awk 'NR==2 {print; exit}' "$METAFLAC_LOG")" "--import-picture-from=3|image/jpeg|||build/tests/output/cover.jpg"
+ assert_equal "$(awk 'NR==3 {print; exit}' "$METAFLAC_LOG")" "--output-name=build/tests/output/file-out.flac"
+ assert_equal "$(awk 'NR==4 {print; exit}' "$METAFLAC_LOG")" "build/tests/output/file.flac"
+ [ ! -f "build/tests/output/file-out.flac" ]
+ [ -f "build/tests/output/file.flac" ]
}
\ No newline at end of file