Can I update the TOTALTRACKS tag to find the max within a set where the album is the same

I have a TON of m4a files where for each track, the TOTALTRACKS tag is equal to the TRACK tag. That is, if an album has 10 songs, the TRACK tags are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 and the corresponding TOTALTRACKS tags are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Is there a way where I could create an action that would update the TOTALTRACKS tags from: (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) to (10, 10, 10, 10, 10, 10, 10, 10, 10, 10)

I can do this manually: select the tracks in an album, (make sure TOTALTRACKS is viewable on the left hand side) and change the value.

But, is there any way I could do this for many albums all at once? If you manually select all of the tracks in an album and then click on the TOTALTRACKS field on the left hand side, the drop down has only the values for that selection (as expected) - could there be a way to find the max TOTALTRACKS value based on an ALBUM name

I think in SQL you could do it like this:

UPDATE Tracks t
SET TOTALTRACKS = (
SELECT MAX(t2.TRACK)
FROM Tracks t2
WHERE t2.ALBUM = t.ALBUM
)

No, I am not claiming that mp3tag can perform SQL operations, I just wanted to flesh this out and see if it would even be possible in SQL.

You might have better success if you use the Auto- Numbering Wizard. It can assign track and disc numbers as well as the totals. If you already have the albums in their own folders this should be pretty straight forward.

Is that the Convert --> Assign Track Numbers... ? I just tried it and it seems promising but for my test I took an album and manually set the TOTALTRACKS to 1 for each song. Then ran the "assign track numbers". It put a leading 0 on the TRACK, that's fine, but it kept the TOTALTRACKS at 1 for every track. Any thing I could add to get around this? Thanks

Okay, so further testing: If they are m4a files AND the TOTALTRACKS is set to some incorrect value, running this fixes everything up nicely. Excellent.

If they are FLAC files AND the TOTALTRACKS is set to some incorrect value then TOTALTRACKS does not get updated but TRACKS goes to the correct format of %track%/%totaltracks% - and then to fix the incorrect TOTALTRACKS follow it with "Import tag fields" that ohrenkino mentioned yesterday.

Taking this one step further...I had an Action (found in forums here) that would take the value after the / (In the TRACKS field) and update the TOTALTRACKS value:

$if2(%totaltracks%,$if($neql(%TRACK%,$regexp(%track%,^\d{1','3}/(\d{1','3})$,$1)),$regexp(%track%,^\d{1','3}/(\d{1','3})$,$1),%totaltracks%))

Doing the above, updates the TOTALTRACKS but keeps the TRACKS in its original format of x/y where as using the "Import tag field" changes both TRACK and TOTALTRACKS. People might want either or. I would like to take the action above and change it so that it ALWAYS updates the TOTALTRACKS regardless if TOTALTRACKS has a value or not. Currently if TOTALTRACKS has a value (even if it's incorrect) it won't update it. I'd like to adjust the action above to ALWAYS update the TOTALTRACKS if anyone could tell me how to edit that.

I took a guess and I think I got it:

$if($neql(%TRACK%,$regexp(%track%,^\d{1','3}/(\d{1','3})$,$1)),$regexp(%track%,^\d{1','3}/(\d{1','3})$,$1),%totaltracks%)

Just remove the opening $if2(%totaltracks%, and also remove the last )

You could use this "Import tag fields" also to update only TOTALTRACKS:
Source: %track%
Target: %dummy%/%totaltracks%

One problem I found using the "Assign Track Numbers..." is that even if the albums are in different directories it increments the disc number as it traverses the directories. So I think the easiest approach is to just uncheck the "Assign disc numbers" as this solves my initial concern. I wonder what this process uses to assign the track numbers? Is it just the leading values of the filename?

AFAIK you can set various criteria to determine the start of the next set.
In many cases this could be the next folder but if an ablum stretches over several folders, it would be the contents of ALBUM.

And no: it is not

If you have problems with the track numbering converter, please show us a screenshot of the current settings you are using for the assistant.

How can I see the "settings" used for this?

⌘ K Assign Track Numbers...
should open a window/dialogue in which you can see the settings.

But that does not indicate how track numbers are determined, only from where the numbering starts and if you want to restart at each directory. I'm asking, if a set of tracks had no "TRACK" value then how does it determine the correct ordering for an album (or a directory) ?

Not at all - you have to put the file into the correct order and then start the numbering assistant.

Right - and the easiest way to to do this is to prefix the "to be track number" at the front of each file so they can easily sort in mp3tag.

Or sort them by the creation date ... assuming that they got created in the correct order by the ripping program.
Or other criteria that ease the sorting.

That was the intended behavior:

It's usually a good idea to link to the source of things that you copy and try to adjust for your use case.