INTERACT FORUM

Please login or register.

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

Author Topic: Expression Help: IsEqual() on a List Field  (Read 3807 times)

bunglemebaby

  • Galactic Citizen
  • ****
  • Posts: 469
Expression Help: IsEqual() on a List Field
« on: August 17, 2014, 11:14:58 am »

Hi all,
I'm trying to manipulate some filenames based, in part, on the contents of a list type field. The comparison only works if the comparison string is first in the list though. So for example if I do if(isequal([My Media Sub-Types],extra,8),"\extras\") it will only add the text \extras if the list looks like [extras, Movie]. If the list is ordered [Movie, extras] then nothing is output. Am I misunderstanding how IsEqual is supposed to work here?

This is the full expression I am trying to use here:
Code: [Select]
[Media Type]\[Media Sub Type]\if(isempty([series],0),,[series])\if(isempty([album],0),[name],[album]) ([year])IfElse(isequal([My Media Sub-Types], extra, 8), "\extras",isequal([My Media Sub-Types], trailer, 8),"\trailers")
Thanks,
Jon
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Expression Help: IsEqual() on a List Field
« Reply #1 on: August 18, 2014, 11:11:04 am »

This is normal.

You might be able to use ListItem(...) to parse just a certain list item out and compare it.
Logged
Matt Ashland, JRiver Media Center

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Expression Help: IsEqual() on a List Field
« Reply #2 on: August 18, 2014, 12:27:48 pm »

Next build of MC20:
NEW: Added ListEqual(...) expression function to compare two lists (irregardless of ordering).
Logged
Matt Ashland, JRiver Media Center

Arindelle

  • Citizen of the Universe
  • *****
  • Posts: 2772
Re: Expression Help: IsEqual() on a List Field
« Reply #3 on: August 18, 2014, 12:52:43 pm »

Next build of MC20:
NEW: Added ListEqual(...) expression function to compare two lists (irregardless of ordering).

oo I think that is very good, not sure though :) Would that mean if I had multiple genres like Country; Pop Rock in a tag and multiple  linked sub-genres I could parse on the separator to only show Country subgenres and Pop/Rock Sub-genres?

Sort of a true Taxonomy View ?

Mr. C was trying to help me on this but I sort of gave up on the idea. Sort of tired seeing Indie Pop show up under Country as a sub-genre
Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: Expression Help: IsEqual() on a List Field
« Reply #4 on: August 18, 2014, 05:09:56 pm »

oo I think that is very good, not sure though :) Would that mean if I had multiple genres like Country; Pop Rock in a tag and multiple  linked sub-genres I could parse on the separator to only show Country subgenres and Pop/Rock Sub-genres?

Sort of a true Taxonomy View ?

Mr. C was trying to help me on this but I sort of gave up on the idea. Sort of tired seeing Indie Pop show up under Country as a sub-genre

not to hijack the thread, but my workaround for this was to use a small (20 or so) amount of genres, then use keywords to sub-genre. 
for example, i use this for smartlists where it's easy to make a ~mix [genre]=[country] genre=[pop] [keywords]=[outlaw] [keywords]=[folk]

the above will give me (with the proper ~mix % of course) pop and country genres, but only those containing outlaw and folk.  if you want to exclude, you can [keywords]!=[indie] and anything you have as "indie folk" or "indie outlaw" won't appear. 

the added benefit (outside of the major amount of work, which i haven't fully completed yet) is that i'm not "limited" to sub genres that make sense...for example bob dylan may be [genre]=rock, with keywords pop, folk, country, old school, seminal.  this way i can build extremely specific sub categories but easily search or list by as many as i want, so if i search just for keywords folk i'll get pop, metal, rock, country, etc. for genres.
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9139
Re: Expression Help: IsEqual() on a List Field
« Reply #5 on: August 19, 2014, 12:29:41 am »

I couldn't get this to work out for bunglemebaby.

What should work however, is if you tell the expression parser to use the raw data...

Quote
IfElse(isequal([My Media Sub-Types,0], extra, 8), "\extras",isequal([My Media Sub-Types,0], trailer, 8),"\trailers")

Which worked in my tests with list type fields, and if I recall correctly, was why it was added to our arsenal of tools.

-marko

bunglemebaby

  • Galactic Citizen
  • ****
  • Posts: 469
Re: Expression Help: IsEqual() on a List Field
« Reply #6 on: August 22, 2014, 04:26:40 pm »

What should work however, is if you tell the expression parser to use the raw data...

Which worked in my tests with list type fields, and if I recall correctly, was why it was added to our arsenal of tools.

-marko

This did work Marko, thank you! So, am I to assume that adding a ",0" to any list type field will parse it as one long plain text string (possibly including the ";" delimiter)?

I'm having one more strange problem now with this expression.
I've got two empty tests, using isempty() to check on [series] and [album] (which I use sometimes for arbitrary movie groupings). I can get the expression to work in an expression pane, but not in the "Rename..." tool. Does anyone see anything that I'm overlooking here?? My understanding is that the 0-mode for IsEmpty() should be string, but I can only get it to work (on empty fields) if I change the mode to 1 in the "Rename..." tool. Mode 1 does not ever match on non-empty string field though (as expected).

Code: [Select]
[Media Type]\[Media Sub Type]if(isempty([series],0),,[series])\if(isempty([album],0),[name],[album]) ([year])IfElse(isequal([My Media Sub-Types,0], extra, 8), \extras,isequal([My Media Sub-Types,0], trailer, 8),\trailers)
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9139
Re: Expression Help: IsEqual() on a List Field
« Reply #7 on: August 23, 2014, 12:32:35 am »

Good stuff, glad that worked for you.

Re: isempty()...

If you imagine asking MC to create a directory structure using [series] without first testing its 'emptiness', and it was empty, MC would be attempting to create a directory with no name, which is not good. For this reason, if the field is actually empty, the rename tool replaces the emptiness with "Unknown [field]", and it does this before handing things over to the expression evaluator, meaning that as far as its concerned, the field is not empty.

You can use the same method to turn this off, ie...
Quote
[Media Type]\[Media Sub Type]if(isempty([series,0]),,[series])\if(isempty([album,0]),[name],[album])

You just need to be careful you're not asking MC to create illegal file paths or names, although in my testing, MC appears to gracefully and quietly correct any illegal double backslashes that appear in the new path, so you just lose a level in the path, which might not be what you want, but would be easy to correct.

-marko

bunglemebaby

  • Galactic Citizen
  • ****
  • Posts: 469
Re: Expression Help: IsEqual() on a List Field
« Reply #8 on: August 23, 2014, 04:11:41 pm »

Quote
For this reason, if the field is actually empty, the rename tool replaces the emptiness with "Unknown [field]", and it does this before handing things over to the expression evaluator, meaning that as far as its concerned, the field is not empty.
Ah, this makes perfect sense now. I realized it did the substitution, but assumed that it did this substitution at the end of the process, i.e. after evaluating the expression, but before committing the new file path/name. These subtle bits of knowledge you've given me will take me a long way marko, thanks again!!

-Jon
Logged
Pages: [1]   Go Up