How to setup mpd on debian

/media/images/cat-with-headphones.jpg

mpd, the music player daemon, runs as a background process and plays or streams your music under command from a mpd client communicating via a tcp socket. Once you've got it working it's great, your music is always available, it can play every possible weird format in any configuration, and it's tolerant of missing files but setting it up is painful because the debian packages are old and broken.

The main issue is the binary package sets mpd to run at the system level but pulseaudio expects apps with user privileges. A system level audio stream will block sounds generated in userspace. This causes firefox to hang where it should mix with your other audio and if you have a notification that plays a sound it will block all of these until you run out of memory from thousands of pending streams. In the mpd config file you can tell it to drop privileges but this doesn't work. Also frustrating is the binary runs as a daemon by default so it's easy to get into situations where there are multiple instances all wrestling for the audio stream.

The solution is to setup mpd as a user process. Systemd can do this but it's not well known and the recommended hack for fixing audio privilege issues was a hack where you setup a tcp socket stream from your system level mpd and connect to this using another pulseaudio hack. I used this for several years until I finally learned the right way of doing things.

Installing mpd

First uninstall the mpd package and install dependencies. mpd has a massive list of dependencies.

sudo apt remove mpd
sudo apt build-dep mpd

Download the latest release from their webpage

They suggest running:

sudo apt install meson g++ \
libpcre3-dev \
libmad0-dev libmpg123-dev libid3tag0-dev \
libflac-dev libvorbis-dev libopus-dev libogg-dev \
libadplug-dev libaudiofile-dev libsndfile1-dev libfaad-dev \
libfluidsynth-dev libgme-dev libmikmod-dev libmodplug-dev \
libmpcdec-dev libwavpack-dev libwildmidi-dev \
libsidplay2-dev libsidutils-dev libresid-builder-dev \
libavcodec-dev libavformat-dev \
libmp3lame-dev libtwolame-dev libshine-dev \
libsamplerate0-dev libsoxr-dev \
libbz2-dev libcdio-paranoia-dev libiso9660-dev libmms-dev \
libzzip-dev \
libcurl4-gnutls-dev libyajl-dev libexpat-dev \
libasound2-dev libao-dev libjack-jackd2-dev libopenal-dev \
libpulse-dev libshout3-dev \
libsndio-dev \
libmpdclient-dev \
libnfs-dev \
libupnp-dev \
libavahi-client-dev \
libsqlite3-dev \
libsystemd-dev \
libgtest-dev \
libboost-dev \
libicu-dev \
libchromaprint-dev \
libgcrypt20-dev

But I remove gnutls from this list because I'm not sure about installing a package that wants to replace one I already have.

Configure, compile, and install the source with meson and ninja:

meson . output/release --buildtype=debugoptimized -Db_ndebug=true
ninja -C output/release
ninja -C output/release install

During the configuration step you may see missing features because of missing dependencies, this is ok. I've never succeeded in fulfilling the entire list of dependencies. Next go into /etc and remove any service files the binary package may have installed:

cd /etc/
rm systemd/system/multi-user.target.wants/mpd.service
rm systemd/system/multi-user.target.wants/mpd.socket
rm systemd/user/mpd.service
rm systemd/user/mpd.socket
rm systemd/user/default.target.wants/mpd.service

Copy the service file and symlink it to the user level systemd directory. I haven't had to setup a socket file. Note that in the source they include the service files as intermediate files so you have to pull them from your output (build) directory:

cd <source directory>/output/release/systemd/user/
sudo cp mpd.service /usr/local/lib/systemd/user/
cd systemd/user/default.target.wants/
sudo ln -s /usr/local/lib/systemd/user/mpd.service .

Copy the mpd.conf file to your home directory. Apparently they don't ship a template of this file with the source code, generate it in the compiled output, or install it to /usr/local/share/.

cd ~/
mkdir .mpd
sudo mv /etc/mpd.conf ~/.mpd/

The man.conf(5) page says mpd looks for it's configuration in these four places and in this order:

$XDG_CONFIG_HOME/mpd/mpd.conf
~/.mpdconf
~/.mpd/mpd.conf
/etc/mpd.conf

Make sure you only have one file. I prefer ~/.mpd/mpd.conf.

Modify this file with your settings. Here's mine:

music_directory         "/home/na/mp3"
playlist_directory      "/home/na/.mpd/playlists"
db_file                 "/home/na/.mpd/mpd.db"
log_file                "/home/na/.mpd/mpd.log"
pid_file                "/home/na/.mpd/pid"
state_file              "/home/na/.mpd/state"
sticker_file            "/home/na/.mpd/sticker.sql"
user                    "na"
bind_to_address         "localhost"
port                    "6600"
log_level               "default"
auto_update             "yes"
audio_output {
        type            "pulse"
        name            "My Pulse Output"
}
connection_timeout      "60"
max_connections         "50"
max_playlist_length     "16384"
max_command_list_size   "2048"
max_output_buffer_size  "8192"

Before you start the service run it by hand to see if everything works.

ps ax | grep mpd   # make sure there isn't some service already running!
mpd --no-daemon /etc/mpd.conf

Use mpc as a simple client to setup the playlist

mpc update      # update the database of files
mpc add /       # add everything to the current playlist
mpc toggle      # play/pause

Running it by hand should make the problem immediately obvious but you can also look at ~/.mpd/log. Finally setup the systemd user service:

systemctl enable mpd --user
systemctl start mpd --user

I use vimpc as a console client - it's great.

Out of eggs?

/media/images/blood_sausage.jpg

Blood has a similar coagulation temperature and almost the same amount of protein per gram. Just use this substitution:

1 egg (approx. 58 g/unit) = 65 g of blood
1 egg white (approx. 33 g/unit) = 43 g of blood

Is it a game?

/media/images/darkhold_015-002.jpg

Wait, what?

/media/images/darkhold_015-007.jpg

OMG! What is it?!

/media/images/darkhold_015-008-009.jpg /media/images/darkhold_015-010-011.jpg

Hmm.

/media/images/darkhold_015-012.jpg /media/images/darkhold_015-034.jpg

Rare picture of na in the 80's (wearing white pants).

hair rental

/media/images/hair_rental.jpg

I just want a media player that ignores id3 tags

/media/images/id3-tags.png

As part of the TMBG fanclub I got an album of a live show in Ashbury park. The songs weren't new but it was fun to hear the guys chat between sets and I wanted to load it to my phone so the next time we were stuck on a long car ride I could listen to it with Amanda. I copied the files to my phone, putting them into a new folder under the system-designated 'Music' directory.

Last weekend I found myself in a position to listen to those songs during the drive to elkhorn slough. Unfortunately I forgot this is the wrong way to listen to music.

I have an android phone running lineageos (a version of android without tracking or advertisements) and I don't have any google apps including the google app store which is a cesspool of malware and marketing. I rarely listen to music on my phone and I've used the built-in media player to my collection on shuffle. It doesn't matter what the files are called when you listen to everything on shuffle and it was only when I wanted to listen to my tmbg songs in order that I remembered there are no android media players that will ignore id3 tags.

About 60% of the 7000 files in my mp3 collection have missing or misleading tags. Also, the entire collection consists of individual songs - not albums. I had albums once decades ago (before id3 tags even) but I aggressively delete songs and my collection now looks like a cabinet of curiosities; a vast assortment of unique gems. There might be 3500 different artists in my collection.

I've tried some of the automatic mp3 tagging tools that using naming heuristics and online fingerprinting but they don't work. They assume you have a collection of albums (I don't) and they otherwise require manually typing in artists and albums - an exercise I have no interest in that would take weeks of work.

I use filenames to tell mp3s apart. It works well and I hate that the rest of the world has decided we should use invisible metadata to identify media files. You might ask why I don't use playlists. A playlist is just a text file with a list of songs in order - simple right? m3u's have a specific format. You can't just make a text file with a list of songs.

It's insane that I can have a list of files:

tmbg_song_1.mp3
tmbg_song_2.mp3
tmbg_song_3.mp3
tmbg_song_4.mp3

But the media player will only display this as:

(1)_unknown
bad tag
bobby_\;droptables
(99)_''

Because the id3 tags are messed up and the recommended solution is to use a separate playlist file, with it's own unique format, to refer back to the sensible file names.

I spent 20 minutes of our car ride to the slough messing with my media player. It refused to show me the files (because they were in a subdirectory? ) - but I could see them if I looked at the 'recent files' tab. All of the files had tags but the tags don't indicate the order in which they should play (like the filenames do) so there was no way for me to know if I was playing things in order. Eventually I gave up in frustration and deleted the whole album (using the file manager) because I was so irritated I never wanted to feel this way again and there was a chance, some time in the distant future, when I might forget and go looking again for the setting to just show me the damn file names.

Moving away from github

/media/images/github_youtubdl.png

Everyone was outraged by the take down of youtube-dl from github including, supposedly, the current owner of github, microsoft. It's funny because microsoft is also a member of the RIAA, the same organization that shut down the project.

My response, like many others was to scramble to find the latest repo and start keeping track where the developers move next because youtube-dl is useful both for it's utility and also as a model for learning how to structure projects of that type.

A few days ago I saw a post indicating a new release of mitmproxy (also hosted on github) and realized every project hosted on that site was threatened.

That got me thinking about other projects hosted on github of critical utility but whose existence frustrates assholes in power.

  • libtorrent
  • bitcoin
  • sabnzb
  • openssh
  • openvpn
  • gnuradio
  • wireshark
  • wine
  • dolphin and every other game emulator ever

Open source and git makes censorship difficult but without a vibrant and secure darkweb, it's easy to make things disappear. Just ask all the nintendo fans who had their projects shut down after years of development.

Update 20201116

As of today youtube-dl has moved back to github.. They changed their tests to avoid explicitly mentioning RIAA owned music but the tests still remain in the git history.

This is just depressing. My first though was this suggests youtube-dl guys feel they have no other option for hosting - because why else would you return to a hosting service after they had shown you who they are? But after some consideration I realize they're probably more protected from the shitty laws than if they hosted it themselves.