(λ (x) (create x) '(knowledge))

Random Script: mkplaylist.sh

Generating playlists for mocp · January 19th, 2023

This is a short and sweet one, I just wanted to share a simple script I put together to generate playlists for mocp. It's not meant to be any fancy, or even optimized. It's just something I wrote in my spare time so I could better leverage my ever growing library of music.

You see, I recently upgraded the disc in my Droid4 to a 128gb Samsung SD card! And ever since then I've been delighted using it as a little MP3 player that I can control via ssh. I even wrote a little "what's playing" program in Nim for just that purpose, and it works great! But I've always just been utter trash about organizing my music, so I'm actually trying in whatever over engineered way I can manage to do that.

Anyways here's the script, literally just if and for statements to iterate over directories and switch context depending on whether I'm in the root music directory or if I'm in an artists directory.


#!/bin/bash
#Generate a playlist of all songs from the CWD

cwd=$(pwd)

#If we're in the root music directory, make a mix tape!
if [ "$cwd" == "/home/durrendal/Documents/Music" ]; then
	find $cwd/* -name '*.opus' > mixtape.m3u
else
	artist=$(basename $cwd)

	#Delete conflicting playlists before generating
	if [ -f "$artist.m3u" ]; then
		rm $artist.m3u
	fi

	touch $artists.m3u

	#For each album the artists has
	for album in $(ls -d */); do
		#Gather up all the opus tracks, and create a playlist
		for track in $album*.opus; do
			printf "$cwd/$track\n" >> $artist.m3u
		done
	done
fi
  

The resulting playlists get spit out as either mixtape.m3u if you're in the root, or as $artist.m3u if you're in an artists directory. I also make zero attempts currently to try and figure out the time length info that mocp provides when you save a playlist, so the content of these files looks like this.


/home/durrendal/Documents/Music/Deichkind/Aufstand_im_Schlaraffendland/Aufstand im Schlaraffenland.opus
/home/durrendal/Documents/Music/Deichkind/Aufstand_im_Schlaraffendland/Jüjük.opus
/home/durrendal/Documents/Music/Deichkind/Aufstand_im_Schlaraffendland/Papillion.opus
/home/durrendal/Documents/Music/Deichkind/Aufstand_im_Schlaraffendland/Prost.opus
  

Yes essentially just a massive list of file paths is all mocp really needs/wants for a playlist. I really wish I had bothered to figure that out years ago, because boy, sometimes you just want to shuffle everything you've got and let it play!

And just because I like when other people do this, if you're curious about what I've been listening to since doubling down on my droid as an mp3 player, here's all of the artists I've got currently in my Music directory. Definitely not everything I listen to, but a very eclectic smattering for sure.


21_Savage
Blaqk_Audio
Bullet_For_My_Valentine
Caamp
Chunk_No_Captain_Chunk
DaBaby
Deichkind
Dizzee_Rascal
Elderbrook
Flux_Pavillion
Foo_Fighters
Four_Year_Strong
Gregory_And_The_Hawk
JID
Jax_Jones
Julia_Nunes
Killswitch_Engage
Linkin_Park
Mac_Miller
Machine_Gun_Kelly
Malaa
Meshuggah
Modest_Mouse
NIN
Porter_Robinson
Soilworks
Stand_Atlantic
Sting
Sum41
The_Kooks
Tove_Lo
Vince_Staples
Wage_War
With_Confidence
flor
mixtape.m3u
  

Bio

(defparameter *Will_Sinatra* '((Age . 31) (Occupation . DevOps Engineer) (FOSS-Dev . true) (Locale . Maine) (Languages . ("Lisp" "Fennel" "Lua" "Go" "Nim")) (Certs . ("LFCS"))))

"Very little indeed is needed to live a happy life." - Aurelius