I spent 4 hours yesterday setting up a quick way to take my MPD playlists (which are in simple M3U) and burn them to a number of audio CDs in K3B (which only accepts extended M3U). I use Slackware, so I had KDE preinstalled, which is why I used the programs I did. I might eventually adapt the following script to work with other programs as well.

Required programs include the following (most of which come stock in Slackware):

Independent Packages

From KDE

You need to set save_absolute_paths_in_playlists to "yes" in mpd.conf for this script to work. It also assumes You follow FreeDesktop’s XDG User Directories defaults and keep Your music in ~/Music.

I straight up lifted the current-playlist-to-extm3u-markup oneliner from here.

This script does create a file in the CWD, but it also asks if You’d like to remove it. I did this because, at times, I may want to keep the generated playlist for importing into other. If this bothers You, You’ll have to modify the flow of the script.

You can also download the script from my github repo.

#!/usr/bin/env bash

echo "Opening Current MPD playlist in k3b for burning...";

currtime=$(date +"%F_%T");

echo \#EXTM3U > $currtime-mpdburn-playlist.m3u;

mpc -f "##EXTINF:%time%,%artist% - %title%\n~$HOME/Music/%file%" playlist | perl -F: -p -e 'if (/^#EXTINF/) {$sec=$F[1]*60; $F[2] =~ s/(^.+),/$1/; $sec += $F[2]; s/^.+,(.+)/#EXTINF:$sec,$1/;}' >> $currtime-mpdburn-playlist.m3u;

k3b --audiocd $currtime-mpdburn-playlist.m3u --nosplash

kdialog --yesno "Delete Temporary Extended-M3U playlist?" 

if [ "$?" == 0 ]; then
    echo "Okay, Deleting $currtime-mpdburn-playlist.m3u"
    rm -v $currtime-mpdburn-playlist.m3u;
elif [ "$?" == 1 ]; then
    echo "Okay, Keeping $currtime-mpdburn-playlist.m3u"
else
    kdialog --error "Unexpected Choice."
fi
Categories:  code  software 
Tags:  mpd  bash  k3b  CD  playlist