search term playlists

Published 2020-12-13, last edit 2022-07-09

This is a brief overview of how I manage a local music collection in $current_year. I use Music Player Daemon (MPD) and youtube-dl to index and add music to big “local music” folder. Over the years structure is totally scattered, but at least for the import folder (youtube-dl) things always look like this: ${musicdir}/import/<channel>/<title>. MPD has many clients, but now I use a script that operates atop the mpc client.

For quite sometime, my music playing looked like this:

mpc clear
mpc listall | sort -R | head -n 1000 | mpc add

As you might imagine, this can lead to some jarring transitions and inconsistency with the 𝓜𝓞𝓞𝓓.

MPD has a notion of saving and loading playlists, but you have to add files individually to them/it’s a very tedious experience if you want to incorporate many kinds of vibes.

Enter my version of playlist files.

Playlist files are files where every line is a comment, except for lines starting with + or -. At the moment, here is my jazz_piano playlist:

# artists
+ryo fukui
+gabor szabo
+hitotaka izumi
+Minoru Muraoka
+alice coltrane

# albums
+flight to brazil

# generic

# channel
+marcel the drunkard

# edd ed eddy is actually pretty jazzy
+ed, edd

# random

-05 My Sick Piano.m4a
-Mario Basanov & Vidis  - I'll Be Gone (ft. Jazzu) _ Chill_Deep-6zaOfkd84Z0.m4a
-Dubmood - Bored at the piano-vQUlWsU_yZ4.m4a

Lines that start with a + are search terms against the current music collection (with a lenient grep against mpc listall) and lines that start with - are to remove search matches from the current mpc playlist. Removal is necessary because some search terms are so generic (here, piano). I then give music a function to process all the search matches. The advantage to this approach is whenever I add new stuff from an above artist or YouTube channel, it will automatically get added to the playlist!

The script may be found here. Here are it’s current options:

$ music
music options:
add        : add a url to library, fallback on clipboard content
append     : append some search term to the current playlist
artist     : play songs by an artist
bl         : blacklist the currently playing song from the current playlist
del        : delete the currently playing song
filter     : filter the current playlist by some shell function acting on music files
info       : display the current audio progress bar and playlist length
now        : fuzzy search for a song, play it now
playlist   : select a search term based playlist to play
remove     : remove some search match from the playlist
shuffle    : reshuffle current selection from all

And an example of a fetch-like status (bar created with mkb):

$ music info
Hiromi Uehara 2006 Love and Laughter
playlist: jazz_piano | 60h 35m 13s

∗ ∗ ∗

After some times passed with the above system, I found myself sometimes wanting more flexibility in playlist composition. Did you know you that - and + are valid function names in bash? Oh yes, we’re going to get dumb:

+ () { append "$@"; }
- () { remove "$@"; }
@ () { artist "$@"; }
. "/path/to/playlist"

Sourcing the playlist means the blend between music script and playlist is total, because playlists are now just shell scripts eval’d in the `music` context. What follows is my vaporwave playlist, where you can see I’m doing something silly and effective with widechars:


# get any song with a widechar in its name
for x in a b c d e f g h i j k l m n o p q r s t u v q x y z A B C D E F G H I J K L M N O P Q R S T U V Q X Y Z; do
   append $x

# artists
@ windows96
@ lucien hughes
@ Macintosh Plus
@ haircuts for men
@ blank banshee

# search terms
+ vaporwave
+ vapor
+ E m o t i o n a l T o k y o

# youtube channel
+ elfamosodemon

# give us stuff longer than 15min
filter is_long

- lazerhawk
- saint pepsi
- lofi
- synthwave

This degree of control is fun because I can do things like “make a playlist of songs not listed in any other playlists” in addition to just being selective about broad searches.

Have fun with it! 🐨