From f8e08d3e2611b7809ac3b536e1d11b97d19a7401 Mon Sep 17 00:00:00 2001 From: frosty Date: Sun, 25 Aug 2024 01:57:52 -0400 Subject: [PATCH] bin: add music-copy --- .local/bin/music-copy | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 .local/bin/music-copy 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