Managing My Music Library with beets

The documentation of the Tangara reminded me to check out a tool that has been collecting dust in my bookmarks for months: the powerful beets!

What a mighty tool! You can have a look at my configuration that takes care of all my music library management needs:

And that does not even cover the superb command line interface, beets’ query language, and the vast plugin ecosystem.

The query language allows me to do some neat data analysis on my music collection on the command line. For example, a little bar chart of the number of albums per year (with the help of Zach Holman’s spark):

beet ls -af '$year' | sort | uniq -c | cut -c -7 | xargs | spark
▁▁▁▁▁▁▁▁▁▃▃▃▂▃▄▃▅▆▆▇█▇▅▅▅▂▃▃▃▃▃▆▆▂

I will do mor extensive analysis once my whole collection is managed by beets.

Sync Library With Rsync

I have been thinking about a way to automatically sync my music library whenever I put my Tangara’s SD card into my machine. First I thought that beets’ own move command with the export option -e would be the answer, but unfortunately beets does not ignore already present files but repeatedly copies them with an incremental suffix leading to loads of duplicates. So I turned to rsync which is actually built for tasks like this. Let’s have a look at the command that I put together and dissect it:

rsync -vahm --size-only --include='*.mp3' --include='*/' --exclude='*' --delete --delete-excluded <path_to_music_library> <path_to_external_storage>

By using rsync I learned that the Linux FAT driver (and Windows) have issues with files and directories that end with a dot. Directories with a dot at the end—like Papa Roach’s F.E.A.R. album—get copied by rsync over and over again irrespective of its existence at the destination folder. This StackExchange answer explains what is going on.

I changed my beets replace rules to trim trailing dots and now everything works smoothly. I love small, sharp command-line tools!