How to Tidy Up Your Music Collection with BASH and metaflac

I recently ripped my 450 or so CDs to FLAC using Audio CD Extractor (Sound Juicer) for my SqueezeCenter. This does a really good job since it will automatically retrieve track information from MusicBrainz. The final step is to add album art to the files (there’s already a cover.jpg file in each album folder.)

After trying just about every tagger suitable for Ubuntu (and compiling Pinky-Tagger.) I quickly realised that this would be a long and tedious task… unless I could do something using the BASH command line. This is what I did.

First, remove all existing artwork:

$ find . -name "*.flac" -type f -execdir metaflac --remove --block-type=PICTURE {} \;

Unfortunately, it’s not possible to mix major operations so you’ll only see errors output from this instruction. If you want to test first replace –remove –block-type=PICTURE with –show-tag=TITLE. For example:

./Giacomo Puccini/La Bohème (Berliner Philharmoniker feat. conductor: Herbert von Karajan, soprano: Mirella Freni, tenor: Luciano Pavarotti)/Giacomo Puccini-La Bohème (Berliner Philharmoniker feat. conductor: Herbert von Karajan, soprano: Mirella Freni, tenor: Luciano Pavarotti)-04-La Bohème: Act I. "Si può_" (Benoit).flac: ERROR: reading metadata, status = "FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE"
The FLAC file could not be opened.  Most likely the file does not exist
or is not readable.

I had three such errors in over 6,000 tracks.

Finally, add the cover art:

find . -name "*.flac" -type f -execdir metaflac --import-picture-from="cover.jpg" --show-tag="Title" {} \;

If you try this, test on one or two folders first (it’s recursive) and back up your important files!

Stay up to date…

Sign up for email updates and never miss another post.

  • Rob Collins

    Hey thanks man for this extremely helpful tip which worked very well. Gosh I love the power of linux command line. It is just a shame that my favourite player amarok STILL does not read embedded cover art while just about every other app you can think of does.

You may also like…

Sansa e260 on Ubuntu 9.04My Sansa e260 , which is running Rockbox wasn't recognised when connected to Ubuntu. ...