Friday 25 April 2014

Tagging a music library for use with a Sonos system

I migrated my iTunes music library to a NAS built with a Raspberry Pi so it could be shared with my Sonos system. Before this the only thing reading any metadata on the files was iTunes which can sometimes do weird things. Coupled with that, I've previously used TuneUp to fix broken metadata within iTunes. It works very well in that context but it seems that the metadata it writes is non-standard in some way and other programs will not read it. All this manifests in some of my music only appearing in the track listing part of the Sonos interface, being listed by filename rather than track name and not being listed by album or artist at all.

What do I need?

Sonos reads standard id3 tags - apparently v1 or any of the v2 options. The files need to be tagged in one of these formats.

Fixing things up

My files are kept in a consistent directory structure looking like this:

blah/Music/Gun/Swagger/01 Stand in line.mp3

My first plan was to use a Linux command line utility for reading and writing id3 tags and pull the required information from the directory path using some clever scripting. I've been away from work for over a week so my brain isn't really up to the required "clever" scripting at the moment. Fortunately, when building the NAS as per my last post I made all my music available over a samba share so it was easy to mount that on my desktop machine and get access to the files that way.

There are dozens of GUI id3 editors. I chose to use mp3tag (my desktop is a Windows machine) and hoped I could somehow convert the tags produced by TuneUp and used in iTunes to something more standard. Unfortunely mp3tag lists the TuneUp tags as "Bad Tags". Drat. Well, at least that explains the problem.

So, armed with my new clicky it's back to plan 1. Having found the files which needed attention I used the "filename-tag" converter with this pattern:

%artist%\%album%\%track% %title%

Slashes reversed because we're in a Windows environment now.

This solved the vast majority of the problems. There were still a few albums tagged in a bizarre way - with no track numbers and a title of something like "01 Intro". I didn't want to completely nuke the existing tags for these as they included Album Art so it was time to break out the "tag-tag" converter which lets you use existing information in the tag to populate other fields.

We need two different filters here, applied in this order because the second removes information needed for the first.

Field: TRACK
Pattern: $left(%TITLE%,2)

then

Field: TITLE
Pattern: $cutLeft(%TITLE%,3)

These methods came from the scripting section of the mp3tag documentation. It turns out it's quite powerful, even if the methods don't always do exactly what the docs suggest they will do.

Job done.

Next steps

My album art is all extremely patchy. Sonos is now my primary playout system at home and it takes an age to load album art so I'm not too bothered about fixing it, however if I change my mind there are a couple of options. Firstly, mp3tag lets you paste album art into the box rather than having to use a presaved photo. I can look up album art in iTunes and copy from there for the occasional simple fix.

If I want to do a proper, automatic job I'll probably take a look at Album Art Downloader which is apparently very good and can be run as a tool within mp3tag. That's fun for another day though.

No comments: