Pick-an-album Script

The reason why

Let’s put it mildly, I’m not a radio listener, never have been, probably never will be. I detest the pathetic games they play with their listeners over the phone. I also hate the blabbing of the DJ’s who prefer to hear themselves talk rather than play some records. Giel Beelen for instance is a famous radio DJ here in the Netherlands, who manages to blab so much that there’s only time for about 6 records in an hour, and he's payed from our tax money too. He ehm also ehm says ehm just ehm about ehm every ehm word ehm he ehm says. Call me ignorant, but I thought DJ is an abbreviation of Disc Jockey, not blab mouth.
And to make matters worse, radio stations rather play heavily plugged records than a good record, for which they have to pay royalties. The result is that they play Ego from Willy William, Sofia from Alvaro Soler and Cake by the ocean by DNCE about 3 times a day, every day, for months on end, on the radio at work. To name but a few far too often played, super annoying, songs.

It appears that some people use iTunes to manage their music collection. I don’t, I can’t and I won’t. I don’t know, but I guess I’m too clever to get my head around the concept of iTunes. I have never seen such a crappy piece of software, perhaps not counting Outlook. Fortunately I can’t even run iTunes, even if I wanted to, as it is not available for Linux.

The solution

Over time I have collected quite a substantial music collection. Everything neatly ordered in folders. All albums of each particular artist or group are collected in their own folder, named after the artist or group.

The main problem is: How do I select an album, at random, to play.

Normally I tend to play the artists I love the most. This means that the less known artists or records are rarely played, so they remain unknown. So I need some help to pick an album from my collection at random. And that is just what this short script does.
It simply picks a random album from a random artist out of my music collection. Then, when I’m at work, I can download that particular album from my server at home and play it, freeing me from having to listen that hideous child lover, Michael Jackson.

The Script

#! /bin/bash
# Pick a random album from a random artist.
# Albums are saved grouped by artist in separate folders.

cd ~/Music/Albums

# Get a random artis
ARTIST=$(ls | sort -R | head -n 1)
cd "$ARTIST"

# Get a random album
ALBUM=$(ls | sort -R | head -n 1)
echo "$ALBUM"

All my music is stored in the folder ~/Music/Albums. What we need to do is simply get a directory listing and then sort that listing in a random order. Finally pick the first line of the resulting random list.
That gives us the folder of the artist or group. Then I go into that folder and repeat the process again to get a random album from that artist or group. That’s all there’s to it. Eat that bloated iTunes crap!

You may have to change the script in case your albums are stored at a different location.

Here’s an example of the output of the script:

user@mint ~ $ pickalbum.sh
Nena - The Stripes
user@mint ~ $ pickalbum.sh
Lynsey De Paul - Sugar And Beyond Anthology
user@mint ~ $ pickalbum.sh
Belinda Carlisle - The Best Of Volume 1
user@mint ~ $ pickalbum.sh
The Stranglers - No More Heros
user@mint ~ $ pickalbum.sh
Lenka - Shadows
user@mint ~ $ pickalbum.sh
Kate Bush - This Woman's Work
user@mint ~ $ pickalbum.sh
The Rolling Stones - Beggars Banquet
user@mint ~ $ pickalbum.sh
Zombies - The Decca Stereo Anthology
user@mint ~ $ pickalbum.sh
Tubeway Army - Replicas
user@mint ~ $ pickalbum.sh
Dido - Odds And Ends
user@mint ~ $ pickalbum.sh
Vanessa Mae - Original Four Seasons
user@mint ~ $ pickalbum.sh
Alquin - Best Kept Secret

Enjoy the music the way it’s supposed to be enjoyed.