I am trying to add the numeric values of a tag from the tracks of an album, but I can’t figure out the correct way to do that.
Say an album consists of 4 tracks.
They all have a tag named ‘count’, and the tracks have the respective values of 1, 3, 5 and 7.
I would like to have a tag ‘total’ that has these values added up, which for this example is 16.
The only thing I could come up with is something like this:
First off, welcome to the community forum. One thing though… Rather than hijacking an existing conversation to ask an unrelated question, please open a new topic thread. Thanks.
[Could someone with the required access permissions please split this to a new topic? Thanks.]
Regarding your first question, aggregating track information is one of the primary uses of the persistent variables plugin. The key to making it work is understanding the order in which tagging scripts are processed, and setting up your scripts accordingly. This can be found in the Tagging Scripts section of the documentation.
The issue with your script is that you are assigning the total_count tag before you’ve actually given the script a chance to fully populate the persistent variable. You need to split the script into two, and I also recommend tracking whether a track has been processed so that the persistent variable doesn’t include duplicate information if you reload an album or manually run a script. Something like:
$noop( First Script )
$if($get_a(_processed_track_%tracknumber%),,
$set_a(_processed_track_%tracknumber%,1)
$set_a(total,$add($if2($get_a(total),0),%count%))
)
This first script sets the aggregate value first by processing all tracks on the album. Then you need a second script to assign this aggregate value to a tag on each of the tracks, like:
$noop( Second Script )
$set(total_count,$get_a(total)
I looked for the forum topic of your plugin so I could post my question there, but I couldn’t find it. So this was the closest related topic that I could find.
I tried your two scripts, but no ‘total_count’ tag is getting written?
PS
I don’t see any ‘add’ function in your scripts?
Are you sure it will add the given numbers in the ‘count’ tag of all tracks?
(producing 16 for my example)
(and just to make sure: there are two separate questions in my post)
Please just start a new topic thread, and not hjack something that might be “close”.
Do you have both scripts entered and enabled? You need both for this to work. How are you retrieving the album information from MusicBrainz (in the right hand pane in Picard)? Or are you just loading local files into the clustering pane and not retrieving the album information from MusicBrainz and matching your files? If that’s the case, you may need to cluster your files and run the scripts manually from the context menu.
It’s there. Second last line of the first script.
I saw that, but I was replying on my phone (I’m currently on vacation) and it took the better part of an hour to do the response for your first question.
I noticed a few problems with the script for your second question:
You are setting the multi-var in the same script, so it doesn’t have a chance to process all the tracks first.
You are not checking to see if a track has already been processed, or if a track number exists before processing (adding it to the _tracknumbers persistent variable.
I’m not sure what you’re trying to do in the second line.
If you’re wanting to remove the duplicate items from the multi-var, you can also use the $unique() scripting function, and $cleanmulti() to remove any empty elements.
The release is matched at the right hand side.
I think I have tried everything you suggested, but I can’t get either of the two things that I want to do to work.
($unique is not an option here, since I need possible duplicates remaining)
I get the feeling this is a bad time for asking, so I’ll leave it at this.
Maybe I’ll figure things out after more trials and errors and looking at existing scripts.
Thanks.
First, thanks @outsidecontext for splitting this to a new topic thread. It’s a lot cleaner that way.
Okay, this time I’ll try not to make any assumptions as to the presence or quality of the %count% tag data, other than it will be provided by the metadata in the file because it’s not one of the standard tags provided by Picard from the MusicBrainz data.
The two scripts (for your first question) would be:
$noop( First Script )
$if($and($not($get_a(_processed_track_%tracknumber%)),$add(0,%count%)),
$set_a(_processed_track_%tracknumber%,1)
$set_a(total,$add($if2($get_a(total),0),%count%))
)
and
$noop( Second Script )
$set(total_count,$get_a(total)
Again, both scripts need to be entered as separate scripts and both must be enabled. Since the information is coming from the files and not from MusicBrainz, you may need to run the scripts manually from the context menu after matching the files to the tracks on the release.
Let’s get this one working for you first, and then we can have a look at the second question.
These two scripts are working well.
This solves the original issue that I encountered, and it enables me to circumvent the issue that I encountered as described in question 2.
While I still am curious why the script I was using for that doesn’t simply concatenate the tag values of all album tracks but is adding/repeating values, it’s not something that poses a problem for me anymore.
So as far as I am concerned: thank you and case closed.
Can you post the contents of your two scripts. Perhaps something has changed in the way the tracks are being processed by Picard (although I don’t recall any changes) that might be causing the scripts to fail.
I’m using the exact two scripts that you posted a couple of comments above.
What is even weirder:
I prepended them with the script:
$set(count,1)
To make sure that the 'count tag for all tracks have the value ‘1’.
That results in 4X1=5
When each of the four tracks already have the ‘count’ tag being ‘1’ and I disable this prepending script, your scripts end up creating variying values for each track:
#1 gets 1 #2 gets 3 #3 gets 2 #4 gets 4
Either I am too dumb for this stuff, or there is something wrong with Picard/the plugin/the scripts.
It looks like the plugin is considering ‘album’ not to be the whole release, but any part of a release that has been divvied-up by disc numbers.
Personally I do not care about ‘disc numbers’ at all and consider them something from a bygone era.
(‘set subtitle’ is the 21st century version of the 80’s ‘disc number’ in my opinion)
Is there a way to make the plugin consider a complete release as ‘album’?
Or have it consider ‘set subtitle’ instead of ‘disc number’?