IfLess and IfGreater not parsing the whole output

Consider this:

outputto "_Test"
SayOutput "10"
IfGreater 5
Say "Greater than 5"
Else
Say "Less than 5"
Endif

This returns:

Less than 5

Whereas it should be greater @Florian ? Or does this function only check the first digit?

I've done a workaround by doing:

json_select "track_count"
RegexpReplace "^\s*1\s*$" "True"
If "True"
Say "XXX"
Endif

According to the documentation:


the command IfGreater check for a NUMBER not a string like "10".
What to you get if you SayOutput 10 (without the quotes)?

Would it work then as expected?

SayOutput needs to be a string.

The function will probably parse that as an int and do this check I would say but it doesn't seem to get the whole output or in my particular case the json_select function which is like so:

{"track_count": 15}

If I check for IfGreater than 1 here it returns False.

It seems that there is a slight misunderstanding on how this command is supposed to be working. IfGreater and IfLess interpret the input string at the current position as a numeric value and compare it with the given parameter.

It's not related to what you write to the current output.

Thanks for the explanation.

How would I go about checking the track_count value in the JSON structure?

I was trying:

OutputTo "_GREATER_THAN_CHECK" 
json_select "track_count"
IfGreater 1
Say "True"
Else
Say "False"
Endif


OutputTo "_LESS_THAN_CHECK" 
json_select "track_count"
IfLess 2
Say "True"
Else
Say "False"
Endif

But in a case where the track_count value is let's say 16. It returns true for both.

See here.

Yes, this is to be expected from the code you've posted. Can you explain the intention behind those checks, i.e., what you're trying to achieve? It might help me to better understand the issue and propose an alternative approach.

I basically want to check the value when using the json_select to check this value and then do an IfLess or IfGreater fn on that.

Here's the workaround that I'm using currently to only output to the _TIME_CHEK tag if the track_count is 1.

OutputTo "_TIME_CHECK"  # Shows track length when only single track available, convenient to check time comparison
json_select "track_count"
RegexpReplace "^\s*1\s*$" "True"
If "True"
json_unselect_object # Unselect data object
json_unselect_object # Unselect state object
json_unselect_object # Unselect "queries" 1 array (Album info)
json_select_array "queries" 2 # Select "queries" 2 array (The Tracks)
json_select_object "state"
json_select_object "data"
json_select_array "results" 1
json_select "length" # All that to get this little blighter
SayRest
json_unselect_object # Unselect results array
json_unselect_object # Unselect data object
json_unselect_object # Unselect state object
json_unselect_object # Unselect "queries" 2 array (The Tracks)
json_select_array "queries" 1 # Select "queries" 1 array (Album info)
json_select_object "state"
json_select_object "data"
Endif

Could you just do:

json_select "track_count"
If "1"
  json_unselect_object # Unselect data object
  ...
  SayRest
  ...
  json_select_object "data"
Endif

?

I did try that also Florian.

If json_select "track_count" returns 11,12,13,14,15,16,17,18 or 19

Then:

If "1"

will equal true.

Yes, true :man_facepalming:

So IfLess 2 would detect the track count = 1. Can you explain the purpose of IfGreater 1 in your example? Still trying to find out what you're trying to achieve.

IfLess 2 doesn't work either. Not for 21-29.

IfLess or IfGreater doesn't seem to get the whole parsed number which isn't ideal when your wanting to know if the track_count value is greater than 1 when it returns true for the cases I've mentioned.

Basically, I was wanting to write to a tag if and only if the track_count value is 1.

I have worked around this by doing:

OutputTo "_TIME_CHECK"  # Shows track length when only single track available, convenient to check time comparison
json_select "track_count"
RegexpReplace "^\s*1\s*$" "True"
If "True"
json_select "length"
SayRest
Endif

But I was trying to get my head around the IfLess and IfGreater fns'.

This is now fixed with Mp3tag v3.21b.

2 Likes