INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Expression language - show not empty fields  (Read 856 times)

chris13

  • Junior Woodchuck
  • **
  • Posts: 64
Expression language - show not empty fields
« on: November 03, 2018, 05:56:39 am »

Hello Forum,

i have a question about expression language. Maybe someone could help me with this.

For tagging my audio collection i use additional fiels, like:

[Release Type 2]
Here i type in some information like
Remastered
Reissued


[Release Type 3]
Here i type in some information like
Collectors Edition
Deluxe Edition
Enhanced
Box Set


I have another Field called [Album Enhanced]
In this field all information regarding [Release Type 2] and [Release Type 3] shall be displayed if available.

like this: [Album] ([Release Type 2] [Release Type 3])

I know the function !isempty but i am struggling to implement this to get the correct result for all combiantions.

Examples:
Remastered Deluxe Edition --> all fields with values
...And Justice for All (Remastered Deluxe Edition)

Remastered Edition --> only [Release Type 2] with value
...And Justice for All (Remastered)

Original Editiion --> no values in Release Type 1 and 2
...And Justice for All


Thanks for your support!
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: Expression language - show not empty fields
« Reply #1 on: November 03, 2018, 07:05:37 pm »

You can test the field for being not empty, or being empty, and just change around where the field is set.

if(!isempty([Release Type 2], 0), [Release Type 2],,)

OR

if(isempty([Release Type 2], 0),, [Release Type 2])

https://wiki.jriver.com/index.php/Conditional_Functions#If.28.E2.80.A6.29
https://wiki.jriver.com/index.php/Test_and_Comparison_Functions#IsEmpty.28.E2.80.A6.29


You can also use the ifelse function to simplify a bit.

ifelse(!isempty([Release Type 2], 0), [Release Type 2])
and
ifelse(!isempty([Release Type 3], 0), [Release Type 3])

https://wiki.jriver.com/index.php/Conditional_Functions#IfElse.28.E2.80.A6.29


As you want to include brackets in the output, you also need to "escape" each bracket around the Release Types you are adding, using the escape character "/" so that MC doesn't treat them as part of the expression;

/(  and /)

But then you don't want the brackets showing if neither Release Type 2 or 3 have content.
ifelse(!isempty([Release Type 2][Release Type 3], 0), /()

Will yield an opening bracket "(" if either [Release Type 2] or [Release Type 3] contain any value.

Similar expression section for the closing bracket.
ifelse(!isempty([Release Type 2][Release Type 3], 0), /))


So the full expression using the ifelse command would be;


[Album] ifelse(!isempty([Release Type 2][Release Type 3], 0), /()ifelse(!isempty([Release Type 2], 0), [Release Type 2]) ifelse(!isempty([Release Type 3], 0), [Release Type 3])ifelse(!isempty([Release Type 2][Release Type 3], 0), /))


Or in indented form;

[Album]
ifelse(
   !isempty(
      [Release Type 2][Release Type 3], 0
   ), /(
)
ifelse(
   !isempty(
      [Release Type 2], 0
   ), [Release Type 2]
)
ifelse(
   !isempty(
      [Release Type 3], 0
   ), [Release Type 3]
)
ifelse(
   !isempty(
      [Release Type 2][Release Type 3], 0
   ), /)
)
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

chris13

  • Junior Woodchuck
  • **
  • Posts: 64
Re: Expression language - show not empty fields
« Reply #2 on: November 04, 2018, 01:59:00 am »

Thank you for the solution and also for taking the time to give a great explanation!
The expression works great. Only one minor problem is left.

If only one field is populated with a value a blank inside the bracket is left.

For example:
...And Justice for All (Remastered )

If you have any further idea, your support is much appreciated.

Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Expression language - show not empty fields
« Reply #3 on: November 04, 2018, 10:09:30 am »

If you have a single space in some of your fields, you might be able to automatically remove them using the function:  Library Tools > Clean File Properties .

You might try it on one song or album and see how it works.  Then use it on everything if it works as you expect it to.

Make sure to select the function(s) that you want applied as "clean file properties" has several modes and features.

Brian.
Logged

chris13

  • Junior Woodchuck
  • **
  • Posts: 64
Re: Expression language - show not empty fields
« Reply #4 on: November 04, 2018, 03:19:52 pm »

As far as i can tell there is no space in the fields. The space is inserted by the expression, if one of the two fields is empty. Don't know why  ?

For simplicity i just use one field for now "Release Type 2" which contains all information, e.g. Remastered Deluxe Edition.
I just used the expression you have posted and modified a little bit.

[Album] ifelse(!isempty([Release Type 2]), /([Release Type 2]/))

This works without insertion of a space.

Thanks again for support
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: Expression language - show not empty fields
« Reply #5 on: November 04, 2018, 08:11:33 pm »

Oops. I thought I had tested for correct spaces, but I must not have. I wasn't testing using your fields of course, so I may have mucked something up in testing and converting the expression to your field.

You can still use the two fields as you have previoously. Not a big deal to fix the expression. In fact, there are lots of ways to do it, but I decided to use the "Clean" function. Look that up in the Wiki about the Expression Language.

So here it is. Spaces work correctly with the data I was looking at. I was using [Artist] and [Genre] fields to test against, and my Genre sometimes had addition characters in it, such as "Pop/Rock", but I made those work as well.

Clean([Album]ifelse(!isempty([Release Type 2][Release Type 3],0),/ /()Clean(ifelse(!isempty([Release Type 2],0),[Release Type 2])ifelse(!isempty([Release Type 3],0),/ [Release Type 3]))ifelse(!isempty([Release Type 2][Release Type 3],0),/)))


Note that I removed all spaces from the expression itself unless they were actually required, which makes reading it a little harder, but making sense of it a little easier.


Mind you, Brian could probably write a Regex expression that did it in a much shorter form. But the above works, whether there are values in [Release Type 2] or [Release Type 3] or both.

Try it.
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

chris13

  • Junior Woodchuck
  • **
  • Posts: 64
Re: Expression language - show not empty fields
« Reply #6 on: November 05, 2018, 01:41:55 pm »

Great, it works!  :)

Thanks alot!

Logged
Pages: [1]   Go Up