How to use conditional statements alongside variables?

Hi all,

(Edit at 2026-04-03 22:00 CST - Whole post was reworded because, as pointed out, it didn’t much sense what I was trying to ask. Being sleep deprived and taking flu meds didn’t helped at all - lesson learned)

Well, as title says, is it possible to validate the current value of a variable to determine what the script will do next?

Long story short: Using HTML scrapping (as no API, nor JSON are available) current version of script can get Artist name, and Release Type (e.g., Split, Full-Length, Single, etc).

However, due to how albums with multiple artist are displayed, to get the proper artist for each track Artist’s value needs to be changed depending if current album has an specific Release Type (Split) and leave it alone if it is not. Basically something like this:

IF RELEASE_TYPE is “Split” THEN
ARTIST = “New Value”
END IF

As per current HTML design, Artist value will always be found before the Release Type.

So, part of my initial idea was to validate RELEASE_TYPE’s value to determine if Artist’s value needs to be updated or not - but it so far it hasn’t been possible for me to achieve that.

Worth to mention that most of my attempts have gravitated around this potential solution but either there’s something that I am missing/doing wrong, or something else is going on, because I am not able to make it work as expected.

Any ideas how to validate a variable’s value? Or is something that is not possible?

Nonetheless, thanks in advance.

Regards.

It is not clear what you are attempting to do. There should not be percents in the release_type. It is better to use conditional when the value is occurring in the html, then store something temporary depending on the condition if you need to use it later. I would recommend using the debug output to see how MP3tag is building the buffers.

You might need to re-word or point out the exact problem you’re having, sorry. :worried: What site are you trying to scrape from and are there any test albums/artist we can use to replicate what you’re doing?

SayOutput "%RELEASE_TYPE%"

That should be okay as using a %placeholder% in this example means you can swap around the name of the output buffer to look for, which could be “Split” or “Not-split” etc.

This, even better show us what part of the debug process where you’re not getting something processed right and what result you’re expecting instead.


If I'm reading this right though, maybe your code's looking for a value in the wrong place? The way If conditional commands work is by comparing what’s currently in the current selection/pointer/whatever you want to call it; in a debug file, it's whatever value is in Line and Position, where other commands like FindLine and MoveLine will temporarily store their data. Commands like SayRest then move that data into an Output buffer. For example, here's a bit from a debug file from a source looking for an output buffer called "TV":

Script-Line    : 38
Command        : if
Parameter 1    : >TV<

JSON objects   : ><
JSON loops     : ><

Output         : >Movie<

Line and position:
TV

This would match, as it finds TV where it wants it, not Movie which is the actual contents of the currently loaded output buffer as shown in Output. So to get that splitConstant value read by an If, you can use the Use command to load whatever data you want into that section:

Edit: Don't use this, this is stupid. My fault. Read further down.
Use "splitConstant"
IfOutput "splitConstant"
set "Artist" ""
endif

Hi @AreDigg and @arb, thanks for the reply - and thank you for pointing out that my initial post was a mess… I think that I’ve fixed it, or at least is now a little bit more simpler.

As for your questions:

I’m trying to do this for Metal Archives and these are the examples for a "Full-Length Album” and a “Split Album“. In both cases the Release Type field can be found with the proper value.

Sure thing.

Although I’ll attach the script on this reply (just with the current conflicting logic), this is how currently script attempts to validate the value

set "splitConstant" "Split"
set "temp_Type" ""
outputto "temp_Type"
SayOutput "RELEASE_TYPE"

IfOutput "splitConstant"
    set "Artist" "Output was Split"
else
    set "Artist" "Output wasn't Split"
endif

Using either link that I provided above, result is the same: Output was Split

Debug for Full-Length is:

------------------------------------------------------------

Script-Line    : 43
Command        : ifoutput
Parameter 1    : >splitConstant<

Output         : >Full-length<

Line and position:
              Full-length
                      ^

------------------------------------------------------------

Script-Line    : 44
Command        : set
Parameter 1    : >Artist<
Parameter 2    : >Output was Split<

Output         : >Full-length<

Line and position:
              Full-length
                      ^

------------------------------------------------------------

And for Split is:

------------------------------------------------------------

Script-Line    : 43
Command        : ifoutput
Parameter 1    : >splitConstant<

Output         : >Split<

Line and position:
            Split
                ^

------------------------------------------------------------

Script-Line    : 44
Command        : set
Parameter 1    : >Artist<
Parameter 2    : >Output was Split<

Output         : >Split<

Line and position:
            Split
                ^

------------------------------------------------------------

And basically this is why I think that I am missing something important/critical here - asides how “regular” If works (based on current line/position on HTML - that part I kinda get it right).

Unfortunately, in this case the order of the values are set in a way that I can’t see a feasible way to do it, as Artist is acquired first, then the Release Type, and if needed, Artist replacement is way down the HTML document.

Of course, I’ll be more than happy if I am proved wrong, because at this point I have zero ideas left :sweat_smile:.

In any case, I really appreciate the comments and suggestions.

Thanks in advance.

RELEASE_TYPE_WITH_IF_TEST.src (1.3 KB)

Cool, try this:

RELEASE_TYPE_WITH_IF_TEST_BACK_AT_YOU.src (1.5 KB)

I disregarded splitConstant and aimed for the value of RELEASE_TYPE which is what you’d ideally want to use. I’m also ultimately amending my previous suggestion. :sweat_smile:

Your biggest problem was using IfOutput, which only checks if there’s actually an output buffer called what you want, not the actual value of that buffer (I can’t recall if it actually requires content in the buffer to be recognised or just goes by its existence). If will check whatever’s in Line and Position, which is what you want.

Next, your code actually keeps the previous value from your # Type section loaded in Line and Position up to the IfOutput command so it’s still usable... almost.

Script-Line    : 44
Command        : if
Parameter 1    : >Split<

Output         : >Split<

Line and position:
	          Split
                ^

The pointer in Line and Position, i.e. the ^, isn’t at the start of “ Split” string so the match will fail.

I replaced your RegexpReplace with the regex <[^>]+> with (\s+)?<[^>]+> to remove the leading spaces from your values below band_name and Type: so it then becomes:

Script-Line    : 44
Command        : if
Parameter 1    : >Split<

Output         : >Split<

Line and position:
Split
     ^

:face_with_bags_under_eyes:

The ^ still isn’t where we want it because the previous SayRest moves the pointer along the line. If we use MoveChar to set it back, it’ll throw an error if it’s too far along and “Full-length” and “Split” are different lengths so that’s a hassle.

So the solution is Use “%RELEASE_TYPE%”: the percents turn the RELEASE_TYPE output into its actual value, the Use command loads it into Line and Position. This actually also removes the leading spaces so that updated regex becomes … more of a cosmetic nicety but it does guarantee your values won’t have that spacing. :nerd_face:

So by ultimately using:


Use "%RELEASE_TYPE%"
If "Split"

you get:

Script-Line    : 43
Command        : use
Parameter 1    : >Full-length<

Output         : >Full-length<

Line and position:
Full-length
^

------------------------------------------------------------

Script-Line    : 44
Command        : if
Parameter 1    : >Split<

Output         : >Full-length<

Line and position:
Full-length
^

------------------------------------------------------------

Script-Line    : 47
Command        : set
Parameter 1    : >Artist<
Parameter 2    : >Output wasn't Split<

Output         : >Full-length<

Line and position:
Full-length
^

and:

Script-Line    : 43
Command        : use
Parameter 1    : >Split<

Output         : >Split<

Line and position:
Split
^

------------------------------------------------------------

Script-Line    : 44
Command        : if
Parameter 1    : >Split<

Output         : >Split<

Line and position:
Split
^

------------------------------------------------------------

Script-Line    : 45
Command        : set
Parameter 1    : >Artist<
Parameter 2    : >Output was Split<

Output         : >Split<

Line and position:
Split
^

:grimacing:

(oh, I also changed the debug files to save in the sources folder. Might be more convenient debugging and editing from where your source works from but save it where you want :wink: )

Hi!

First and foremost: Whoa, that was amazing! It worked like a charm.

I am very thankful for your help, as well for the patience. I learned quite a few new things, as well to better understand how the Web Scripts Framework works in these cases.

Also, due to have a kinda outdated version of the application, and I wasn’t aware of Use command (the version of MP3Tag that I had simply threw an error when attempting to use it).

In any case your solution, as well explanations, have helped me not only with my original issue, but also to do some additional things that were giving me some issues.

Once again, thank you so much!

Hope you’re having a great day.

Regards.