From e6c4d6a3cf48c2c84eb8d3c9bd18afd78bb75827 Mon Sep 17 00:00:00 2001 From: ziadarafat Date: Thu, 26 Nov 2026 03:51:23 -0700 Subject: [PATCH] music-audit: sequential Stage B runner Runs album-level beets imports over a queue of folders, one at a time: beets writes a single SQLite library, so concurrent imports collide. Waits for any import already in flight, logs each folder separately, and records completed folders in /var/lib/beets/stageb-done.txt so a re-run skips them. Pink Floyd (first folder): 193 of 245 files now carry a musicbrainz_albumid and 27 tracks gained disc numbers > 1, i.e. multi-disc sets are being split properly. Nine albums were declined and are worth a manual pass: The Wall disc 2, Dark Side of the Moon, Piper 40th, Echoes disc 2, Zabriskie Point disc 2 and others. --- tools/music-audit/stageb-runner.sh | 68 ++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 tools/music-audit/stageb-runner.sh diff --git a/tools/music-audit/stageb-runner.sh b/tools/music-audit/stageb-runner.sh new file mode 100755 index 0000000..0147548 --- /dev/null +++ b/tools/music-audit/stageb-runner.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +# Run Stage B (album-level beets imports) over a list of folders, one at a time. +# +# Serialised on purpose: beets writes a single SQLite library, and two concurrent +# imports collide on it. Each folder gets its own log, and the runner waits for +# any import already in flight before starting the next. +# +# ./stageb-runner.sh # the default queue +# ./stageb-runner.sh "dir1" "dir2" # an explicit queue + +set -uo pipefail + +BEET=/opt/beets-venv/bin/beet +CONF=/etc/beets/config-stageb.yaml +LIB=/mnt/MediaDisk/Music/MyLibrary +LOGDIR=/var/log +QUEUE_MARK=/var/lib/beets/stageb-done.txt + +DEFAULT_QUEUE=( + "$LIB/Johnny Cash Discography" + "$LIB/Jimi Hendrix" + "$LIB/Queen Discography @ 320Kbps [Aufseher]" + "$LIB/Van Halen - Studio Discography 1978 - 2012 [FLAC] [h33t] - Kitlope" + "$LIB/Nine Inch Nails - Discography (1989 - 2008) [FLAC] [h33t] - Kitlope" + "$LIB/Styx [Discography]" + "$LIB/Leonard Cohen - Studio Discography (1967 - 2012) [Mp3 320]" + "$LIB/DLMusic" + "$LIB/Flac Zips" +) + +if [ "$#" -gt 0 ]; then + QUEUE=("$@") +else + QUEUE=("${DEFAULT_QUEUE[@]}") +fi + +mkdir -p "$(dirname "$QUEUE_MARK")" +touch "$QUEUE_MARK" + +log() { echo "$(date -u +%H:%M:%SZ) $*"; } + +for dir in "${QUEUE[@]}"; do + [ -d "$dir" ] || { log "SKIP (missing): $dir"; continue; } + if grep -qxF "$dir" "$QUEUE_MARK"; then + log "SKIP (already done): $dir" + continue + fi + + # Never run two imports at once. + while pgrep -f "[b]eet.*import" >/dev/null; do + log "waiting for the running import to finish before $dir" + sleep 30 + done + + slug=$(basename "$dir" | tr -c 'A-Za-z0-9' '-' | cut -c1-48) + logfile="$LOGDIR/beets-stageB-$slug.log" + log "importing: $dir" + "$BEET" -c "$CONF" import -q "$dir" > "$logfile" 2>&1 + rc=$? + skipped=$(grep -c "Skipping" "$logfile" 2>/dev/null || echo 0) + items=$(grep -cE "Importing|Applied" "$logfile" 2>/dev/null || echo 0) + log "done: $dir exit=$rc applied_markers=$items albums_skipped=$skipped log=$logfile" + if [ "$rc" -eq 0 ]; then + echo "$dir" >> "$QUEUE_MARK" + fi +done + +log "stage B queue finished"