sync-music: scan ~/Music recursively so nested folders sync too
This commit is contained in:
+10
-11
@@ -6,10 +6,10 @@
|
|||||||
# How it works:
|
# How it works:
|
||||||
# 1. Ensures the NAS SMB share is mounted at /Volumes/data (uses your keychain
|
# 1. Ensures the NAS SMB share is mounted at /Volumes/data (uses your keychain
|
||||||
# credentials; falls back to a clear error if it can't mount).
|
# credentials; falls back to a clear error if it can't mount).
|
||||||
# 2. Imports every audio file in ~/Music into beets via
|
# 2. Imports every audio file anywhere under ~/Music (recursively) into beets
|
||||||
# `beet import --noautotag --move --quiet`, which moves each file into the
|
# via `beet import --noautotag --move --singletons`, which moves each file
|
||||||
# library and removes it from ~/Music. Files already in the library are
|
# into the library and removes it from ~/Music. Files already in the
|
||||||
# skipped by beets (left in place). Safe to re-run any time.
|
# library are skipped (left in place). Safe to re-run any time.
|
||||||
#
|
#
|
||||||
# Why a manual script (not the old daemon)? The daemon kept dying because
|
# Why a manual script (not the old daemon)? The daemon kept dying because
|
||||||
# launchd/WezTerm spawn a minimal PATH that lacks /opt/homebrew/bin (where
|
# launchd/WezTerm spawn a minimal PATH that lacks /opt/homebrew/bin (where
|
||||||
@@ -61,13 +61,11 @@ fi
|
|||||||
# $LIBRARY_DIR/beets/beets_library.db (per ~/.config/beets/config.yaml).
|
# $LIBRARY_DIR/beets/beets_library.db (per ~/.config/beets/config.yaml).
|
||||||
log "sync-music: scanning $WATCH_DIR -> $LIBRARY_DIR"
|
log "sync-music: scanning $WATCH_DIR -> $LIBRARY_DIR"
|
||||||
|
|
||||||
shopt -s nullglob nocaseglob
|
# Recursively collect every audio file under $WATCH_DIR.
|
||||||
files=()
|
files=()
|
||||||
for f in "$WATCH_DIR"/*; do
|
while IFS= read -r -d '' f; do
|
||||||
[ -f "$f" ] || continue
|
|
||||||
[[ "${f##*.}" =~ ^($AUDIO_EXT)$ ]] && files+=("$f")
|
[[ "${f##*.}" =~ ^($AUDIO_EXT)$ ]] && files+=("$f")
|
||||||
done
|
done < <(find "$WATCH_DIR" -type f -print0 2>/dev/null)
|
||||||
shopt -u nocaseglob nullglob
|
|
||||||
|
|
||||||
total=${#files[@]}
|
total=${#files[@]}
|
||||||
log "Found $total audio file(s)."
|
log "Found $total audio file(s)."
|
||||||
@@ -86,9 +84,10 @@ for f in "${files[@]}"; do
|
|||||||
|
|
||||||
bn=$(basename "$f")
|
bn=$(basename "$f")
|
||||||
|
|
||||||
# Pre-check: has beets already imported this file? Match by path or title.
|
# Pre-check: has beets already imported this file? Match by exact path, or
|
||||||
|
# by a title guess derived from the filename ("03 - Artist - Title").
|
||||||
existing="$(beet ls --path "$f" 2>/dev/null || true)"
|
existing="$(beet ls --path "$f" 2>/dev/null || true)"
|
||||||
stripped="$(echo "$bn" | sed 's/\.flac$//; s/\.mp3$//')"
|
stripped="$(echo "$bn" | sed 's/\.[A-Za-z0-9]*$//' | sed -E 's/^[0-9]+ - [^ -]+ - //' )"
|
||||||
if [ -n "$existing" ] || [ -n "$(beet ls "$stripped" 2>/dev/null || true)" ]; then
|
if [ -n "$existing" ] || [ -n "$(beet ls "$stripped" 2>/dev/null || true)" ]; then
|
||||||
log " already in library (skipped): $bn"
|
log " already in library (skipped): $bn"
|
||||||
ok=$((ok + 1))
|
ok=$((ok + 1))
|
||||||
|
|||||||
Reference in New Issue
Block a user