Problems checking the length of a tag

I am developing a script to set the ‘genre’ field based on the values of 4 user-defined tags, called ‘titlegenre’, artistgenre’, ‘albumgenre’ and ‘albumartistgenre’.

The values of the above fields are set via MusicBee, accessing rateyourmusic.com

What I want to do is set the ‘genre’ in the following order

‘albumartistgenre’ - highest
‘artist’
‘album’
‘title’ - lowest

To decide which to use, I planned on checking the length of each field to establish which is set. The code I have as an example is as follows

$if($gt($lenmulti(%artistgenre%),0,auto),$set_a(ARTLEN,1),$set_a(ARTLEN,0))

The above always returns ‘ARTLEN’ = 0

I can see that the ‘artistgenre’ has values by running the View Script Variables, whch shows the following

ARTISTGENRE [‘Baroque Pop’, ‘Beat’, ‘Bubblegum’, ‘Merseybeat’, ‘Pop’, ‘Pop Rock’]

I’m probably doing something really stupid! Any ideas and suggestions gratefully received

Further information…

To test that I have the correct syntax, I also added the following code, noting that the ‘genre’ field already has a value

$if($gt($lenmulti(%genre%),0,auto),$set_a(GENLEN,1),$set_a(GENLEN,0))

For the above, ‘GENLEN’ had a value of 1, i.e. true. So the syntax appears correct

  1. It would probably be easier if there was a Rate-Your-Music plugin for Picard to get the genres directly.

  2. I have no idea what $set_a is. There is nothing in either the Picard documentation nor the Picard source code defining $set_a.

  1. Agreed, but I don’t believe that RYM has an API that can be used

  2. This variable, along with a few others becomes available when the Persistent Variables plugin is installed. It allows for the setting and subsequent retrieving of tags across scripts

RYM does not YET have an API (though apparently one is coming as part of their Sonemic upgrade Project). But you can still screen-scrape the genres if you can find the correct release. That said, there is AFAIK no way to match MBIDs against a specific page - so finding the exact right release may be a bit hit and miss with screen-scraping.

Actually, it allows setting a variable that can be accessed by all tracks in an album. See the Scripting section of the documentation for information about how the tagging scripts are processed.

I assume that you want to set the %genre% tag to the same value for all tracks in the album, based on the values on any/all of the tracks. If this is the case, then you might try the following tagging script to set the working values of each of the four user-defined tags:

$set_a(_albumartistgenre,$if2($get_a(_albumartistgenre),%albumartistgenre%))
$set_a(_artistgenre,$if2($get_a(_artistgenre),%artistgenre%))
$set_a(_albumgenre,$if2($get_a(_albumgenre),%albumgenre%))
$set_a(_titlegenre,$if2($get_a(_titlegenre),%titlegenre%))

Then you would use a second tagging script to set the %genre% tag for each of the tracks, as:

$set(genre,$if2($get_a(_albumartistgenre),$get_a(_artistgenre),$get_a(_albumgenre),$get_a(titlegenre),No Genre Set))

Thanks for the reply and the suggestion. My original explanation of the problem may have caused some confusion, so let me try and clarify.

I have already collected up to four genres from RYM. Now, I want to use the highest priority available as the main genre.

My priority, from highest to lowest, is ‘albumartistgenre’, ‘artistgenre’, ‘albumgenre’ ‘titlegenre’

If an ‘albumartistgenre’ exists, I want to copy that to the ‘genre’ field, if not then see if an ‘artistgenre’ exists, copy that to ‘genre’. If not then ‘albumgenre’, if not copy '‘titlegenre’

The only reason I was using the set_a was to determine if anything was happening. In my case, it appears that nothing is happening because the code is not detecting any value in the user tag fields

Sorry for any confusion

That is what I understood you were trying to do. What you haven’t made clear is whether you want to use the same genre for all tracks on the album, or allow different genres for the different tracks. If each track can have different genres from other tracks on the album, then you don’t need to use persistent variables and can get away with a single script such as:

$set(genre,$if2(%albumartistgenre%,%artistgenre%,%albumgenre%,%titlegenre%,No Genre))

Also, are you matching your tracks to albums retrieved from MusicBrainz or are you processing them in the clustering pane? If processing them in the clustering pane, you may need to run the script(s) manually using the context menu for the files.

Many, many thanks, everything is working fine now!

Using the information that you provided and the suggested code, I went back and retried some tests.

Initially, every time I tested, the ‘genre’ was ending up with the catch-all value of ‘No Genre’! This made me do some checking and I realised that I had NOT set the four genre fields as tags to be kept; something that now seems obvious as these are tags created in MusicBee and not in Musicbrainz

Once again, thanks!

1 Like