Skip to content

Instantly share code, notes, and snippets.

@cletusw
Last active June 5, 2026 05:24
Show Gist options
  • Select an option

  • Save cletusw/a200aa0ff20b10507160554f4bd72e4e to your computer and use it in GitHub Desktop.

Select an option

Save cletusw/a200aa0ff20b10507160554f4bd72e4e to your computer and use it in GitHub Desktop.
Beets upload directory watcher
#!/usr/bin/with-contenv bash
WATCH_DIR="/downloads/move-here-after-upload"
export PATH="/lsiopy/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
# Runs beets when a file/folder is *moved* into WATCH_DIR. This way, users can upload a whole album (slow),
# then move it into the watched directory so beets processes whole albums together.
#
# Install (via your docker compose):
# environment:
# - DOCKER_MODS=linuxserver/mods:universal-package-install
# - INSTALL_PACKAGES=inotify-tools
# volumes:
# - /mnt/hot/apps/beets/custom-services.d:/custom-services.d
echo "[beets-watcher] Directory watcher service starting on $WATCH_DIR"
echo "[beets-watcher] BEETSDIR=$BEETSDIR"
echo "[beets-watcher] FPCALC=$FPCALC"
if [ ! -d "$WATCH_DIR" ]; then
echo "[beets-watcher] ERROR: Watch directory '$WATCH_DIR' does not exist. Exiting." >&2
s6-svc -d .
exit 1
fi
echo "[beets-watcher] Successfully attached to $WATCH_DIR. Starting inotify monitoring..."
# Listen for anything moved into the directory
inotifywait -m -e moved_to --format "%f" "$WATCH_DIR" | while read NEW_ITEM
do
ITEM_PATH="$WATCH_DIR/$NEW_ITEM"
if [ -d "$ITEM_PATH" ]; then
echo "[beets-watcher] Detected new folder: $NEW_ITEM. Launching album import..."
/lsiopy/bin/beet -v import -q "$ITEM_PATH"
else
echo "[beets-watcher] Detected single item: $NEW_ITEM. Launching singleton import (-s)..."
/lsiopy/bin/beet -v import -q -s "$ITEM_PATH"
fi
echo "[beets-watcher] Finished processing"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment