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.
#Generate a playlist of all songs from the CWD
#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
#Delete conflicting playlists before generating
if [ -f "$artist.m3u" ]; then
#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
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
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.