Need help for a small Script

Hi,
I‘m new to Picard and need help by a (hopfully) smal Script.
I want to name the ARTISTS tag (and some other Multi-valued tags) as a String and not proper multi-valued tags, e.g.
Nicki Minaj; Drake; R.E.M

and not
Nicki Minaj
Drake
R. E. M.

Is there a Solution?

I think this could be as simple as doing:

$set(artists,%artists%)

This should flatten the multi-value tag into a string, separated by semicolon as you wish. The reason is that internally all scripting functions on Picard operate on string values, so using %artists% just converts this to a string.

If you actually wanted to preserve the tag being a multi-value tag you would use $setmulti as in this example from the scripting documentation:

$setmulti(genre,$lower(%genre%))
2 Likes

I don’t think this is what you want, but I had an issue with certain multi-valued fields being not technically compliant with the MP3 standard, and a particular implementation being a stick in the mud about it. If that’s your situation, you can check out the plugin I wrote to deal with it: https://github.com/metabrainz/picard-plugins/pull/83

But that won’t touch the tags for anything that doesn’t use ID3 tags.

Let me thank you for this as a bystander.

I have been quite confused myself about ‘$setmulti’.

This is the explanation about it in the documentation:

$setmulti(name, value, separator="; ")

Sets the variable name to value, using the separator (or "; " if not passed) to coerce the value back into a proper multi-valued tag. This can be used to operate on multi-valued tags as a string, and then set them back as proper multi-valued tags, e.g. …

Reading that, I assumed that it would create a multivalue tag, with ‘;’ as a seperator.

But reading your answer (and checking it with Picard), ‘$set’ will create an actual multivalued tag with ‘;’ as seperator.
And '$setmulti" does not create ‘a proper multi-valued tag’ (as it says in the documentation), but it creates separate (multiple) tags?
And the seperator that you can choose to use for $setmulti is not the seperator that gets written, but it’s the seperator that $setmulti will look for to decide where to split and so create the multiple tags?

Is this indeed how it works?

2 Likes

@hiccup: Yes, that’s correct :slight_smile:

1 Like

Great. I hope somebody is able to correct the error in the explanation. (multivalue instead of multiple)
Or even better, clarify the explanations to the variables a bit better, with perhaps some actual examples added to them.
That would be a great first step in making scripting easier to understand to a larger amount of users.

Yeah I’m having a hard time understanding this $setmulti as well :thinking:
The problem I have is that my genre tags are flattened into a string, with "; " separator.

Current situation = comment[32]: GENRE=Soul; Vocal; Blues
Which should be: multiple comment tags (flac files):
COMMENT[32]: GENRE=Soul
COMMENT[33]: GENRE=Vocal
etc…

If I set genre as ‘unpreserved’, the existing value just gets deleted.
If I set it ‘preserved’, nothing changes…

How do I fix this ?

Thank you all for your help and explanation. It works. Now I can tag my musicvideos with MusicBrainz Picard and write the tags in a .nfo file to scrape this with Kodi.

I am guessing you will need to use the $copymerge function for that, but I am not able to present you a tailor-made script for that.

There is probably still some misunderstanding. A “multivalue” tag for Picard is a certain tag (e.g. artists) that has multiple distinct values (like a list). So instead of storing just a string with some separator like “Artist 1; Artist 2” there will actually be a list of artists (“Artist 1” and “Artist 2”).

So if you do $set(artists,Artist 1; Artist 2) the tag will have just a single value with an arbitrarily chosen separator (“;”). But if you do $setmulti(artists,Artist 1; Artist 2) you will actually get a tag with multiple distinct values.

You need $setmulti every time you manipulate a tag with tagger script and want to write it back as a proper multi-value tag. The reason is that all tagging functions will work on strings, and as such get passed “Artist 1; Artist 2” instead of actual multiple values.

How this is actually saved to the files is independent of this concept and depends on the tagging format. E.g. ID3 v2.4 supports having multiple values inside frames, whereas in Vorbis tags you will just get multiple entries in the form “ARTISTS=Artist 1”, “ARTISTS=Artist 2”. But this is just an implementation detail, the result is the same. And if multiple values are not supported for a tag it will be flattened.

3 Likes

You need to use $setmulti. You didn’t tell us the script you are using, but you probably have something like $set(comment:genre,%genre%) there. Use $setmulti instead of $set.

1 Like

Thanks for the replies :slight_smile:
I am actually using $setmulti, like this: $setmulti(genre,%genre%,separator="; ")
I’m gonna try it with “comment:genre” now…

Here is the issue, you have to use $setmulti(genre,%genre%,; ), or even better just $setmulti(genre,%genre%,) because a separator of ; is the default.

Your original code would assume you have genres set as Soulseparator="; "Vocalseparator="; "Blues instead of Soul; Vocal; Blues :smiley:

3 Likes