How to remove leading characters from user defined multi tag

I have two scripts that between them collect the track genres and combine them into an album genre, which is ultimately written to each track of the release.

The first script accumulates each of the track genres into an album genre field :

‘’‘‘taggerscript
$set_a(_albumgenre,$get_a(_albumgenre); %titlegenre%)
‘’’’
The second script takes the value accumulated and writes it to an album genre tag:

‘’‘‘taggerscript
$set(albumgenre,$get_a(_albumgenre))
$set(albumgenre,$unique($sortmulti(%albumgenre%)))
‘’’’
The scripts are run manually because they reference user-defined tags rather than using MusicBrainz available tags.

Everything works fine, apart from one small problem, i.e. the resulting value in the ‘albumgenre’ tag ends up looking as follows:

; Doo-Wop; Glam Rock; Pop Rock; Progressive Pop

Note the leading '; ’ in the above

I’m pretty sure that removing the leading characters could be done via $replace or $rreplace but my regex is non-existent, so not sure how I would code it.

If anybody has any ideas or can offer an alternative approach, I’d be grateful for the advice

I’m guessing that this is happening because you are appending to an empty list in the first pass through the line $set_a(_albumgenre,$get_a(_albumgenre); %titlegenre%). There are a couple of ways you can handle this, but perhaps the easiest is to remove the empty elements in your final multi-value by using the $cleanmulti() function. This way the second script would be something like:

$setmulti(albumgenre,$get_a(_albumgenre))
$set(albumgenre,$unique($sortmulti($cleanmulti(albumgenre))))

Note that this is just off the top of my head and I haven’t tested it.

2 Likes

Many thanks for taking a look at this.

The idea seemed good; unfortunately, the results weren’t what we had hoped for. Rather than removing the leading characters, the ‘artistgenre’ tag values were flagged for deletion.

I even tried running the $cleanmulti on a separate line, but the results were as per my initial report, i.e. leading characters remain

Huh? That completely baffles me.

Have you changed both lines in your second script to match what I had posted? In your original script, your first line assigned the string to an ordinary variable rather than a multi-value variable. That’s also why the $unique() and $sortmulti() functions won’t work as expected.

Again, that’s because you only have a single value variable and not a multi-value. If you want to keep the single value (without sorting or removing duplicates) and just remove the leading semicolon and space then change your second script to:

$set(albumgenre,$deleteprefix($get_a(_albumgenre),; ))

Note that I haven’t tested this.

Thanks for your continued help on this. Following your last update, I went back and rechecked my scripts, especially the second one. You were right that I had NOT used a $setmulti, but after doing so and retesting, I am still not getting the desired results.

Regarding the deletion of the artistgenre tag that I previously mentioned, when I rechecked, I found that I already had a variable of the same name! To eliminate that as a possible cause of any problem, I updated the 2nd script as follows

$setmulti(testgenre,$get_a(_albumgenre))
$set(testgenre,$unique($sortmulti($cleanmulti(testgenre))))

As I was running the scripts, I checked on the Persistent Variables and noted the following values recorded against _albumgenre after the first script:

; ; ; Doo-Wop; ; Glam Rock; ; Doo-Wop; ; Pop Rock; ; Pop Rock; ; Glam Rock; ; Glam Rock; ; Pop Rock; ; Glam Rock; ; Progressive Pop

It appears that the ‘titlegenre’ values have been accumulated, though the number of semi-colon/space combinations looks odd!

After running the 2nd script the ‘testgenre’ tag was not written to the individual tracks!

Regards,
Terry