nix

configuration files that power my machines
Log | Files | Refs | README | LICENSE

commit 67c046dfcfbf2c789a96b0ab59943b8678b6c9b0
parent ede85018ce189314b7ba657833dd7138771de04e
Author: mtmn <miro@haravara.org>
Date:   Mon, 18 May 2026 15:37:20 +0200

givecover: run in parallel, recursively

Diffstat:
Mmodules/mixins/dotfiles/bin/givecover | 51++++++++++++++++++++++++++++-----------------------
1 file changed, 28 insertions(+), 23 deletions(-)

diff --git a/modules/mixins/dotfiles/bin/givecover b/modules/mixins/dotfiles/bin/givecover @@ -1,23 +1,35 @@ #!/bin/bash # Attach cover art to audio files using ffmpeg -SEARCH_DIR="${1:-.}" -COVER_NAMES=("cover.jpg" "Cover.jpg" "cover.png" "Cover.png") +process_file() { + local file="$1" + local COVER_NAMES=("cover.jpg" "Cover.jpg" "cover.png" "Cover.png") + local dir + dir=$(dirname "$file") + local cover="" + for name in "${COVER_NAMES[@]}"; do + if [ -f "$dir/$name" ]; then + cover="$dir/$name" + break + fi + done -cover="" -for name in "${COVER_NAMES[@]}"; do - if [ -f "$SEARCH_DIR/$name" ]; then - cover="$SEARCH_DIR/$name" - break + if [ -z "$cover" ]; then + echo "[—] $file (no cover found in $dir)" + return fi -done -if [ -z "$cover" ]; then - echo "No cover image found in $SEARCH_DIR" - exit 1 -fi + local tmpfile="${file}.givecover.tmp.${file##*.}" + if ffmpeg -nostdin -y -i "$file" -i "$cover" -map 0:a -map 1:0 -c copy -disposition:v:0 attached_pic "$tmpfile" 2>/dev/null; then + mv "$tmpfile" "$file" + echo "[✓] $file" + else + rm -f "$tmpfile" + echo "[✗] $file" + fi +} -echo "Using cover: $cover" +export -f process_file EXTENSIONS=("flac" "mp3" "m4a" "ogg" "wav" "aif" "aiff") @@ -29,13 +41,6 @@ for i in "${!EXTENSIONS[@]}"; do find_args+=(-iname "*.${EXTENSIONS[$i]}") done -while IFS= read -r -d '' file; do - tmpfile="${file}.givecover.tmp.${file##*.}" - if ffmpeg -nostdin -y -i "$file" -i "$cover" -map 0:a -map 1:0 -c copy -disposition:v:0 attached_pic "$tmpfile" 2>/dev/null; then - mv "$tmpfile" "$file" - echo "[✓] $file" - else - rm -f "$tmpfile" - echo "[✗] $file" - fi -done < <(find "$SEARCH_DIR" -type f \( "${find_args[@]}" \) -print0 | sort -z) +find "${1:-.}" -type f \( "${find_args[@]}" \) -print0 | + sort -z | + parallel -0 process_file {}