bin: add music-copy

This commit is contained in:
frosty 2024-08-25 01:57:52 -04:00
parent 4f028154a4
commit f8e08d3e26

24
.local/bin/music-copy Executable file
View file

@ -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