Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Removing leading zeros from %tracknumber% (Read 6795 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Removing leading zeros from %tracknumber%

Hi,

Can foobar2000 display the %tracknumber% variable in the playlist truthfully, i.e. without adding a zero for all numbers below 10? I would like to be able to sort it so I can determine which albums have not been formatted using 'Auto track number'.

Alternatively, is there a way to have Masstagger set up to truncate the leading zeros from %tracknumber%?

Since I keep multiple discs per folder, just doing an 'Auto track number' on the entire library will unfortunately screw it up.

Removing leading zeros from %tracknumber%

Reply #1
$num(%tracknumber%,1) will do that for you.

No idea about MassTagger, as I've never used it.


Removing leading zeros from %tracknumber%

Reply #3
Edit: What I previously said here was really wrong, so ignore me. Dario was right! Unless I’m mistaken, CoRoNe’s suggestion of subsong isn’t relevant.

Removing leading zeros from %tracknumber%

Reply #4
$meta(tracknumber) should also work.

Removing leading zeros from %tracknumber%

Reply #5
For MassTagger ("Manage Scripts"), you can use "Format values from other fields" and set "Destination Field Name" to TRACKNUMBER and the pattern to "$num(%tracknumber%,1)" as previously suggested. I tested this on one particular album and it seems to work.

EDIT: You could select everything in your playlist but I'd perform some backup and/or tests to be sure the results are what you want.

EDIT: It seems to set songs without track number to track number zero. Be aware!

Removing leading zeros from %tracknumber%

Reply #6
EDIT: It seems to set songs without track number to track number zero. Be aware!
So use this:
Code: [Select]
[$num(%tracknumber%,1)]
The square brackets will have the expression return absolutely nothing (not a zero) if the field does not exist.

I just noticed: Technically, for fields whose literal value doesn’t have a leading zero, here you’d be adding one via %tracknumber% and then immediately removing using $num … but although this is redundant, the syntax is simple, and an expression that doesn’t do this is about five times longer—so never mind.

Removing leading zeros from %tracknumber%

Reply #7
I'm curious about the expression that doesn't do this, is it just an $if() expression or something fancier?

 

Removing leading zeros from %tracknumber%

Reply #8
Actually, this entire thread somewhat requires clarification over whether the OP’s fields literally contain leading zeroes, or whether the problem is simply due to the (documented) behaviour of %tracknumber% padding to two digits when necessary.

In the latter case, this can be averted just by using $meta(tracknumber) to show the literal value, without any processing.

In the former case, we have the suggestions above, or the purist’s way:
Code: [Select]
[$num($meta(tracknumber),1)]

This is what you asked about, nevets1219; the reason I previously thought it might’ve been complicated was because I was uncertain whether square brackets supported $meta fields—which would have necessitated an $if, a $meta_test, and such—but then I verified via Wine that they do. As I said, it hardly matters, but this should provide the pleasant placebo of knowing that no zeroes will be added only to be taken away.  (And now, before I ramble any more, I’m taking myself away…)

Removing leading zeros from %tracknumber%

Reply #9
Is there some standard or at least encouraged standard for tracknumbers (e.g. leading zero or not)? I took a look here but couldn't find anything. I recently went through a semi-manual process of removing leading zeros but I stopped midway because it was very tedious (select an entire album, "Run Last Script") - but with the method discussed here, I could do everything in one sweep. Just not sure if it is worth the effort.

Removing leading zeros from %tracknumber%

Reply #10
Sorry to resurrect this thead. I am looking into doing the opposite: insert the leading zero on metadata. EAC creates it with leading zeros, so I want to keep them.
How to achieve this?

Removing leading zeros from %tracknumber%

Reply #11
Code: [Select]
[$num($meta(tracknumber),2)]
Who are you and how did you get in here ?
I'm a locksmith, I'm a locksmith.

Removing leading zeros from %tracknumber%

Reply #12
Does anybody know what is the difference between %track number% (*not* %tracknumber%; see the link) and $meta(tracknumber)?

Removing leading zeros from %tracknumber%

Reply #13
Does anybody know what is the difference between %track number% (*not* %tracknumber%; see the link) and $meta(tracknumber)?

There shouldn't be any. They do the same thing, which is returning the value of the TRACKNUMBER field without further modifications.

Removing leading zeros from %tracknumber%

Reply #14
Wouldn't $meta(tracknumber) bypass the foobar database and return the value as it is stored in the file whereas %tracknumber% and %track number% both access the value stored in the foobar database?

I don't know if the database stores single-digit values with or without leading zeroes, adding or removing them or what.

Removing leading zeros from %tracknumber%

Reply #15
The short test I did was:

Track number in properties: 1
%track number%: 1
$meta(tracknumber): 1
%tracknumber%: 01

Track number in properties: 01
%track number%: 01
$meta(tracknumber): 01
%tracknumber%: 01

Track number in properties: 1/5
%track number%: 1/5
$meta(tracknumber): 1/5
%tracknumber%: 1/5

By nature $meta(tag) should make a difference in most cases, as it ignores remappings but TRACKNUMBER has none. Perhaps if you installed one of the custom database components which would take over the field.

Removing leading zeros from %tracknumber%

Reply #16
Wouldn't $meta(tracknumber) bypass the foobar database and return the value as it is stored in the file whereas %tracknumber% and %track number% both access the value stored in the foobar database?
The built-in functions and fields never access audio files directly. They only access the information which foobar2000 has already retrieved and cached.

I don't know if the database stores single-digit values with or without leading zeroes, adding or removing them or what.
foobar2000 stores all fields as they are decoded by the associated input plugin. For most formats the value is returned as it is stored in the file.

By nature $meta(tag) should make a difference in most cases, as it ignores remappings but TRACKNUMBER has none.
%tracknumber% only checks the TRACKNUMBER tag but it does format the value. This is what is written in the title formatting help which you can access in foobar2000 from the Help menu:
Quote
Two-digit index of specified track within the album. Available only when “tracknumber” field is present in track’s metadata.

Removing leading zeros from %tracknumber%

Reply #17
By nature $meta(tag) should make a difference in most cases, as it ignores remappings but TRACKNUMBER has none.
%tracknumber% only checks the TRACKNUMBER tag but it does format the value. This is what is written in the title formatting help which you can access in foobar2000 from the Help menu.

I was referring to %track number%, not %tracknumber%, as per d125q's post. So no formatting applied.

Removing leading zeros from %tracknumber%

Reply #18
The built-in functions and fields never access audio files directly. They only access the information which foobar2000 has already retrieved and cached.

Oh... so in a case where foo_playcount is installed, $meta(rating) returns the value stored by the foobar database and %rating% returns the value stored by the foo_playcount database?

Apparently, I got the impression that $meta(rating) retrieved the value from the file and assumed $meta() bypassed both databases. I don't remember why or how I got that impression.

foobar2000 stores all fields as they are decoded by the associated input plugin. For most formats the value is returned as it is stored in the file.

I tested after posting and found this to be the case. %tracknumber% simply adds leading zeroes when none are present.

Thanks for your help.

p.s. - sorry for wasting your time, Daeron.

Removing leading zeros from %tracknumber%

Reply #19
Man Eating Duck, thanks. That worked!