It is Monday and I am in one of those rare moods when I can’t decide what music to listen to while I work.
This happens every so often although I can usually find something from my digital collection, but today I can’t settle on anything. Metal, synth, Spanish guitar, even chiptune; nothing is quenching my ear thirst.
In a moment of desperation (or madness?), I threw together a script to pick an album at random from my digital library and add it to cmus. Behold, ara
#!/bin/bash
# ██████ ██████ ██████
# ░░░░░░██ ░░██░░█ ░░░░░░██
# ███████ ░██ ░ ███████
# ██░░░░██ ░██ ██░░░░██
# ░░████████░███ ░░████████
# ░░░░░░░░ ░░░ ░░░░░░░░
# a d d r a n d o m a l b u m
# default to adding one album
[ $# -eq 0 ] && num=1 || num=$1
# set path to music and read into array
library_dir="$HOME/lib/music/"
readarray -d '' library < <(find ${library_dir} -mindepth 2 -maxdepth 2 -type d -print0)
# get some randomness
RANDOM=$$$(date +%s)
# add _n_ random albums to cmus library
for n in $(seq 1 ${num}) ; do
random_album=${library[$RANDOM % ${#library[@]}]}
cmus-remote -C "add ${random_album}"
done
The script is simple enough. Find albums in my music library path, add them to an array, then select one or more albums and add them to my cmus
library using cmus-remote
.
The find
command uses -mindepth 2 -maxdepth 2
on the basis that my music library directory is organised as
artist
└── album
I can then add as many random albums as I like, defaulting to one if no number is specified
ara 8
You can view the script on my git server or incant
curl -L git.pyratebeard.net/pub/dotfiles/cmus/bin/ara
For those following my #weeklymusictoot on the fediverse, this week’s listening may be a bit weird.