Last active
October 7, 2020 00:58
-
-
Save werkkrew/5522b6ded30d77d3ea3d to your computer and use it in GitHub Desktop.
Process with Beets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#### Media file processing script for Beets | |
# This script gets triggered by some means (inotify, auditd, cron, etc.) and processes music files in some locations. | |
# | |
# Uses the already defined beets configuration for the user this script runs as. | |
command -v beet >/dev/null 2>&1 || { echo >&2 "I require beets but it's not installed or in my $PATH. Aborting."; exit 1; } | |
# Set up some logging | |
NOW=$(date +"%m%d%Y") | |
LOGDIR="/var/log/htpc" | |
LOGFILE="beets-wrapper-$NOW.log" | |
# Test if script is run interactively, do not log the output if so | |
if [ -v PS1 ] | |
then | |
exec 1>> $LOGDIR/$LOGFILE 2>&1 | |
echo "Logging to: ${LOGDIR}/${LOGFILE}" | |
# Delete old log files, comment this out if you just want to use logrotate or something | |
echo "Deleting log files older than 7 days..." | |
find $LOGDIR/ -name '*.log' -type f -mtime +7 -delete | |
fi | |
# path(s) to search for files to process | |
SEARCH_PATH=("/storage/downloads/completed/music" "/storage/downloads/seedbox/music") | |
echo "Start Processing - ${0} on $(date)" | |
for path in "${SEARCH_PATH[@]}"; do | |
echo "Running Beets in $path" | |
if find "$path" -mindepth 1 -print -quit | grep -q .; then | |
beet import -qpi $path | |
else | |
echo "$path is empty, moving on..." | |
fi | |
echo "Finished processing in $path" | |
done | |
echo "Finished Searching for files." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment