Eliminate discnumber and totaldiscs if 0 or 1

taggerscript
picard
discnumber
totaldiscs
Tags: #<Tag:0x00007f23c6b19bf8> #<Tag:0x00007f23c6b19860> #<Tag:0x00007f23c6b195b8> #<Tag:0x00007f23c6b19360>

#1

I try to remove the content of %discnumber% and %totaldiscs% if the value is smaller or equal to 1 (to only write them into my tags if they are 2 or greater) with the following lines:

$if($lte(%totaldiscs%,1),$set(%totaldiscs%,),))
$if($lte(%totaldiscs%,1),$set(%discnumber%,),))

Unfortunately, this doesnt work. I get the undesired value 1/1 in my id3 tag DISCNUMBER

What would be the correct syntax?


#2

There’s probably two bugs there. First, $set(...) needs to have the raw name of the variable rather than the value ($set(%discnumber%,0) would try to set a variable named 1 to 0, when $set(discnumber,0) without the % is actually what does what you’re expecting). Second, I think that’s just going to leave the fields empty, but still in the file; $unset(discnumber) will actually remove the fields entirely. The rest of that looks good, though.


#3

Try $if($eq(%totaldiscs%,1),$unset(discnumber))

From this topic: Remove disc number tag


#4

Thank you @mfmeulenbelt
With the command $eq the discnumber will only be unset if totaldiscs has exactly the content 1, correct? Not if totaldiscs is empty or 0 or bigger as 1?

I think I have found a working solution:

$if($lte(%totaldiscs%,1),$unset(discnumber))
$if($lte(%totaldiscs%,1),$unset(totaldiscs))

The order of this two lines is important.
In the first step the discnumber will be unset if totaldiscs is smaller or equal to 1.
In the second step the totaldiscs itself will be unset for the same condition.


#5

You can get away with only using the $if once. Just put both $unset statements together within it, side by side.


#6

I tried exactly this, but it does not work for me. Can you explain what you did to make it work?


#7

Just go to Picard options, scripting, add a script and paste $if($eq(%totaldiscs%,1),$unset(discnumber)) $if($eq(%totaldiscs%,1),$unset(totaldiscs))
in the box to the right. Apply the settings and reload the release. That should be all.


#8

Yes, I did it, but does not work. Maybe some bug. Thanks for the reply.


#9

I haven’t tested this, but you should even be able to simplify it further by using the single line:

$if($eq(%totaldiscs%,1),$unset(discnumber)$unset(totaldiscs))

As for it not working, the best guesses I have are that you put spaces or line breaks between an $if( and the following comma (extra characters make it think that the test succeeded every time) or you put the lines in a script with some error that passes the parser but fails when run (rare, but that’s why @mfmeulenbelt recommended making a new script). And, just to be sure, you aren’t putting it in the box on the file renaming page, are you? That will still run as long as you have renaming enabled, but only once you save the file, so you may not see any change.

If none of that’s what’s wrong, I’m not entirely sure what’s going on. I know I’ve had issues with $unset in the past myself, but I forget how I fixed them then. Sorry!