20230522-ara.md (2263B)
1 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. 2 3 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. 4 5 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](https://cmus.github.io/){target="_blank" rel="noreferrer"}. Behold, `ara` 6 ``` 7 #!/bin/bash 8 # ██████ ██████ ██████ 9 # ░░░░░░██ ░░██░░█ ░░░░░░██ 10 # ███████ ░██ ░ ███████ 11 # ██░░░░██ ░██ ██░░░░██ 12 # ░░████████░███ ░░████████ 13 # ░░░░░░░░ ░░░ ░░░░░░░░ 14 # a d d r a n d o m a l b u m 15 16 # default to adding one album 17 [ $# -eq 0 ] && num=1 || num=$1 18 19 # set path to music and read into array 20 library_dir="$HOME/lib/music/" 21 readarray -d '' library < <(find ${library_dir} -mindepth 2 -maxdepth 2 -type d -print0) 22 23 # get some randomness 24 RANDOM=$$$(date +%s) 25 26 # add _n_ random albums to cmus library 27 for n in $(seq 1 ${num}) ; do 28 random_album=${library[$RANDOM % ${#library[@]}]} 29 cmus-remote -C "add ${random_album}" 30 done 31 ``` 32 33 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`. 34 35 The `find` command uses `-mindepth 2 -maxdepth 2` on the basis that my music library directory is organised as 36 ``` 37 artist 38 └── album 39 ``` 40 41 I can then add as many random albums as I like, defaulting to one if no number is specified 42 ``` 43 ara 8 44 ``` 45 46 You can view the script on my [git server](https://git.pyratebeard.net/dotfiles/file/cmus/bin/ara.html){target="_blank" rel="noreferrer"} or incant 47 ``` 48 curl -L git.pyratebeard.net/pub/dotfiles/cmus/bin/ara 49 ``` 50 51 For those following my [#weeklymusictoot](https://harbour.cafe/tags/weeklymusictoot){target="_blank" rel="noreferrer"} on the fediverse, this week's listening may be a bit weird.