Is it possible to read iTunes tags with scripting?

Tags: #<Tag:0x00007f4d4e89fb78> #<Tag:0x00007f4d4e89fab0> #<Tag:0x00007f4d4e89f9e8>

I would like to have a script read the contents of the iTunes “Grouping” tag and append some information from Musicbrainz to it.

I can make it replace the grouping tag completely, but I can’t figure out how to either read the tag so I can re-write it with the additional information, or simply append the information to the end of that tag.

In current Picard 2.0.4 this is not directly possible. You can set the iTunes grouping tag by script with e.g.:

$set(_id3:GRP1,The grouping)

But this will just change it, not reuse existing data. There is kind of a semi-manual workaround. You can create a new script in Options > Scripting (name it something like “Extend iTunes Grouping” with the following content (adapt to your needs by replacing “something to append” with what you actually want there):

$set(_id3:GRP1,%_id3:GRP1% something to append)

Now make sure to have this script disabled (no checkbox before the name) so it won’t run by default, because if it does it will just overwrite the iTunes grouping with only " something to append". Then when you have matched files to a release in the right pane select the files or the album, right click and use “Scripts…” > “Extend iTunes Grouping”.

The good news: With Picard 2.1 this story will be much improved. In Picard 2.1 there will be an option “Save iTunes compatible grouping and work”, which will allow you to use Picard’s builtin grouping tag for this instead of the _id3:GRP1 hack.

1 Like

Thanks. I couldn’t get the script to work, unfortunately. At first I thought it was the ID3 part, so I looked at this page:

And it seemed to say it should be this ID3 tag instead:

$set(_id3:TIT1,%_id3:TIT1% something to append)

Or maybe this iTunes specific tag:

$set(_id3:©grp,%_id3:©grp% something to append)

However all three scripts failed. I even tried turning off all plugins and other scripts.

Sounds like I just need to wait for Picard 2.1. (Or iTunes Music Nerd Edition. If iTunes had tags for country, label and catalog number I wouldn’t need this workaround at all.)

If you use the Classical Extras plugin (v2.0) then I think you can achieve this on the tag mapping page by adding grouping to the “list of existing file tags which will be appended to” and then adding a tag mapping line (not conditional) which maps the required additional information into grouping.
If you are not wanting the full functionality for classical music, then uncheck the top left box on the “works and parts” tab, otherwise the plugin will also append anything specified on that tab. In any case, make sure that the default options specified on the Artists and Tag Mapping tabs meet your needs.
Also make sure that grouping is not specified in the main Picard “Preserve tags” options (Options->Tags) otherwise Picard will not amend it.

1 Like