diff --git a/.local/bin/music-copy b/.local/bin/music-copy new file mode 100755 index 0000000..bea10ed --- /dev/null +++ b/.local/bin/music-copy @@ -0,0 +1,24 @@ +#!/bin/sh + +SRC_DIR="$HOME/music" +DEST_DIR="/run/media/$USER/F967-1B77/Music" + +die() { + printf '%s: %s\n' "${0##*/}" "$1" >&2 + exit 1 +} + +# Check source and destination directories +[ -d "$SRC_DIR" ] || die "no such directory: $SRC_DIR" +[ -d "$DEST_DIR" ] || die "no such directory: $DEST_DIR" + +# Sync directories and artwork +rsync -a --include '*/' --exclude '*.flac' "$SRC_DIR/" "$DEST_DIR/" + +# Transcode audio +find "$SRC_DIR" -type f -name '*.flac' | while read -r src_file; do + rel_path="${src_file#"$SRC_DIR"/}" + dest_path="$DEST_DIR/${rel_path%.*}.opus" + + [ -f "$dest_path" ] || ffmpeg -nostdin -i "$src_file" -c:a libopus -b:a 96k "$dest_path" +done