Use Lucene-based tagging in MusicBrainz to automagically scan and tag all your MP3s from the command line.
Most people never understand the importance of clean metadata (e.g., ID3 tags) in their music until they shove their haphazard music collection into an iPod. If you have no tags or inconsistent tags in your music collection, it’s nearly impossible to really enjoy your shiny new iPod. To help out with this dilemma, MusicBrainz has been working on creating intelligent tagging applications that take the pain out of fixing your music metadata (for an introduction to MusicBrainz, see [Hack #30] ).
MusicBrainz offers a full-blown GUI application code-named Picard [Hack #32] that provides a visual approach to tagging your music. Musicbrainz also provides pimpmytunes for people who prefer to work on the command line. MusicBrainz tagging applications use the Lucene engine (http://lucene.apache.org) behind the scenes to identify tracks. This general-purpose text indexing engine, when applied to music metadata, allows tagging applications to perform metadata matching based solely on the incomplete metadata found in the source music track and a separate index file. MusicBrainz used to match a song to its online metadata by using acoustic fingerprints that attempt to identify music on the actual audio characteristics, but this was slow and inaccurate. These new tools are much better but do have one downside: they require very large index files to run, which delays the instant gratification of tagging your music collection right now, because you first have to download the index files.
Go to the pimpmytunes site at http://musicbrainz.org/wd/PimpMyTunes)to get started. Download the program and the index files pimpmytunes references. Follow the provided instructions for installing the program and its prerequisite software and for where to place the index files.
Once you install the application and index files, run
pimpmytunes (command line pmt
)
without command-line arguments to print out the usage for the
program and write the default settings file to
~/.pimpmytunes.conf. Using your favorite text
editor, edit this file and tweak the default settings to your taste.
Pay close attention to the settings listed in Table 2-8.
Table 2-8. Important settings in pimpmytunes.conf
Setting | Purpose |
---|---|
| The location of the MusicBrainz Lucene index. |
| The file naming mask that specifies how to rename tracks (explained later). |
| The file mask that specifies how to rename various artist (compilation) tracks. |
| The directory where to save cleanly tagged tracks. |
| Move files to the destination directory when saving. |
| Rename files when saving. |
pimpmytunes works best when you move cleaned tracks from your
music directory to the destination directory. To organize files in
place, either turn off the MoveFiles
option or set the destination
directory to be the same dir
as
your existing music directory. In the latter case, pimpmytunes will
create subdirectories according to your selected FileMask
.
Since no two people name their music tracks the same way, pimpmytunes supports file masks, which let you tell the program how to save your files (see Table 2-9). For example, the following file mask:
%abc/%sortname/%album/%0num - %track
will instruct pimpmytunes to save the track “Taxman from The Beatles” to the following file:
/mnt/mp3/clean/B/Beatles, The/Revolver/01 - Taxman.mp3
Table 2-9. pimpmytunes file masks
File mask | Description |
---|---|
| The first letter of the artist name |
| The name used to sort the artist |
| Album name |
| Track number padded with zeroes |
| Track name |
Well, I’m assuming you have set DestDir
to
/mnt/mp3/clean—which you don’t have to do. Having
a / in the file mask causes pimpmytunes to create a subdirectory, so
that all your music gets cleanly organized on your hard drive. Please
refer to the pimpmytunes documentation for a full
listing of the supported substitution variables.
Now that you’ve configured pimpmytunes, you
can invoke it with the command pmt
, a mode (I’ll explain modes shortly),
and music files and/or directories containing music files on the
command line. pimpmytunes will start up and examine the passed files
and recursively search for MP3, FLAC, Ogg Vorbis, and WAV files in the
directories.
pimpmytunes operates in two modes: automatic and manual. In the
automatic mode (command line option –a
), the program will check each file and
directory passed on the command line to see if it can match the file
against the index. If the application finds a match and its confidence
rating exceeds the AutomaticThreshold
setting, it automatically
accepts the match, saves the new metadata to the file, and moves on to the next file. If
pimpmytunes can’t find a suitable match, it ignores the file and moves
on to the next.
Matching files with the automatic mode allows the user to get the mostly clean files out of the way quickly and focus on the troublesome files that pimpmytunes can’t readily identify. pimpmytunes in automatic mode can also act in the background to automatically tag files, without user interaction. Setting up a cron job to invoke pimpmytunes periodically allows you to automatically tag files in a download directory. If you download files with mostly clean metadata, pimpmytunes will identify, save, and rename your newly downloaded files automatically—all according to your preferences.
Operating pimpmytunes in manual mode (-m
) presents the top matches found in the
Lucene index for each of the files. You need to inspect the matches
and enter the number of the match that fits best. Once the match is
selected, pimpmytunes saves the file and moves on to the next file. If
pimpmytunes didn’t find a close enough match, enter e
at the command prompt to edit the
metadata for this track. pimpmytunes will show the metadata that this
track has so far and allow you to edit the information so it can
attempt another lookup.
In most cases where pimpmytunes cannot find a match, the
metadata tags contained incomplete or incorrect information. For these
cases, fixing the data in the tracks with the e
command lets pimpmytunes find the right
track.
Sometimes MusicBrainz does not have the album that matches your
track— in that case enter l
to
open a web browser and look up the artist/track at MusicBrainz. Use
the MusicBrainz web site to locate the right album or add a new album
if the correct one isn’t found. Once you locate the album, copy the
album page URL that contains the album UUID (e.g., 8f468f36-8c7e-4fc1-9166-50664d267127
), and
then switch back to pimpmytunes. In pimpmytunes type a
(for a
lbum id) and then paste the UUID and hit
Enter. This causes pimpmytunes to retrieve the album from MusicBrainz
and match the current track to that album.
If pimpmytunes can’t find the right match for a track, you can try one of the options from Table 2-10.
Table 2-10. pimpmytunes options
Key | Function |
---|---|
| Look up this track at MusicBrainz. |
| Enter a specific album ID for this track. |
| Skip this track and try again after processing other tracks. |
| Delete this track from disk permanently. |
| Remove this track from pimpmytunes. |
If you have trouble with pimpmytunes, go to the MusicBrainz Contact Us page at http://musicbrainz.org/wd/ContactUs and choose your favorite method of getting help.
—Robert Kaye