Automating / Executing MusicBrainz Picard from Command Line

Tags: #<Tag:0x00007f0eb479d280>

I’m looking for a way to execute MusicBrainz Picard entirely via the command line.

The reason being is that I have about 5K albums (I haven’t counted the individual songs) and in some of them, the cover art that’s embedded in the audio file isn’t compliant with some of the music players (i.e. Sony Walkman NW-A55). Consequently, the album art doesn’t show even though it’s present. For the record, Sony requires album art to be baseline JPGs and not progressive.

I’ve written a simple bash script (this is on macOS, BTW) that will traverse the directory, and query both the cover.jpg file as well as the audio file to validate the cover art (I’m using GraphicsMagick and ffprobe) and fix it if necessary. However, to properly embed the cover art, I need to “run it through” Picard.

I can automate the launching of Picard with the command open -a "MusicBrainz Picard" <name of audiofile> and it will launch Picard with audio file loaded and ready to be saved with the new album art. Unfortunately, that’s as far as it goes because from there, it’s a manual operation. Is there any way to automate saving the file so I can do this process unattended?

It’s currently not possible to automate Picard in such a way. Some ideas:

  • Your script could load all the files, then you could save them all in one go. So it comes down to a single manual operation.
  • Have a look at beets. I don’t know whether it would do exactly what you need, but it often is mentioned when it comes to automating library management
  • If you know some Python you could use mutagen (the library used by Picard to read / write tags) directly. Though cover art handling can be a bit tricky and depends on the file format you are writing.
2 Likes

I would be careful of loading individual files from an album into Picard and then saving them because the various tracks in the album would then likely have non-matching metadata and especially non-matching cover-art.

If you use Python and Mutagen, you could load the file, extract the cover art from the tag, use a python library to make the embedded jpg Baseline rather than Progressive and then save the cover art back to the tag and the file. (Or you could quite quickly code a utility whose sole purpose was to extract or save cover art using mutagen - and then do the rest in bash.)

But given what you have already coded, the obvious thing would be to:

a. Collect the list of album directories that need updating
b. Load Picard once with just those albums
c. Wait for Picard to finish getting metadata
d. Click Save.

1 Like

Good suggestions you’ve raised.

I’m thinking that a simple text file, an array holding the filenames, or even moving the file and folder to a temp location for later processing with Picard might solve this. I’ll spend a little time and bodge together a PoC and see how the workflow develops.

Have a look at beets. I don’t know whether it would do exactly what you need, but it often is mentioned when it comes to automating library management

This looks like some good kit especially since I was (recently) looking for a better library tool than what iTunes provides. Currently, I’m using Strawberry and while it has some excellent strengths, the interface (for me at least) leaves a lot to be desired. One big plus is that it’s cross platform and works on macOS, Windows and FreeBSD. Beets, interestingly enough, it’s available as a port on FreeBSD, but not on macOS or Windows. I’ll take a look at this as well and see how I can install it on my Mac (daily driver).

If you know some Python you could use mutagen

My Python experience is quite limited; when I did actually program code, it was in C/C++ with some Java thrown in for good measure. Right now, the only coding I do on a regular basis is Bash scripting for sys admin tasks.

Again, thanks for response and pointing me to a new utility that I might be able to make good use out of.

1 Like

I hear what you’re saying. The way I’m launching Picard, from same directory where Picard is configured to save files, it works because the new album art and the audio file is already there. Basically, it’s just writing to itself so there’s not much wiggle room (if any) that can cause problems. When Picard launches, all I have to do is click “Save” and the file gets written with the new album art. Thus far, the meta data has stayed the same.

As I replied to outsidecontext, my Python skills are quite weak, but your pointer here has me thinking: maybe I could use ffmpeg instead of Picard to write write the metadata without transcoding the audio. I’ll look into that and see how things evolve.

Thanks for the idea!