INTERACT FORUM

Please login or register.

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

Author Topic: Search Fields and Update Other Fields Based on Results ?  (Read 1421 times)

kstuart

  • Citizen of the Universe
  • *****
  • Posts: 1955
  • Upgraded to MC22 Master using preorder discount
Search Fields and Update Other Fields Based on Results ?
« on: January 22, 2013, 08:24:10 pm »

I'm looking to get started in the expression language, so I thought this would be good for someone to explain as a good example.   Please include where in the Menus to do this, and if possible, how to limit it to certain files:

Search through all fields and the filename and if the string "Mozart" is found then update the Composer field to "Mozart" (if possible, do it only if the field is blank).

Thanks !

(Hopefully other people in the future can find this thread helpful too.)

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Search Fields and Update Other Fields Based on Results ?
« Reply #1 on: January 22, 2013, 08:34:48 pm »

The only place to quickly search through (almost) all fields is via the Search box.  It automatically examines all stock fields, and any you define as searchable.

But you can construct expressions to search a list of fields that you define in the expression.

If you are learning the expression language, the easiest way to play is to create a panes view, and add either expression columns to the panes, or in the file list.  This allows quick edit and preview of your results.

You're wanting to look for "Mozart" in one or more fields.  The easiest way it to start with one field:

   if(isequal([Artist], Mozart, 8), Amadeus has been Found, No Amadeus).

Add the above to a new pane column of type expression, and you'll be able to click to see the results.

To add more fields, just tack them together to form a larger string for comparison:

   if(isequal([Artist][Composer][Album Artist][Name], Mozart, 8), Amadeus has been Found, No Amadeus).

Here's the expression language reference:

   http://wiki.jriver.com/index.php/Media_Center_expression_language
Logged
The opinions I express represent my own folly.

kstuart

  • Citizen of the Universe
  • *****
  • Posts: 1955
  • Upgraded to MC22 Master using preorder discount
Re: Search Fields and Update Other Fields Based on Results ?
« Reply #2 on: January 23, 2013, 04:16:01 pm »

So the only place I can find to apply this sort of thing (to the "Composer" field) is:

Fill Properties from Filename

( I don't see anything which could be "Fill Properties from Other Properties" - the closest thing is the Tag On Import facility, and I don't see a way to do "If the string Mozart is anywhere in the Properties, then fill the Composer with Mozart".  Update - there was a thread a couple of years ago requesting "Fill Properties from Properties". :) )

Actually, I would expect that the same proportion of files that have "Mozart" in tags, have "Mozart" in the full filename.

Currently I have a Smartlist running which uses the rule "Filename - contains - Mozart" and then does Shuffle.

Too bad instead of Shuffle, it can't "Write - Composer field - "Mozart". ;)

So, I guess I am wondering if the "Fill Properties from Filename" template can use an expression, and can that expression say:

If "Mozart" ( is found in filename )
Then [Composer] = "Mozart"
Else do nothing

kstuart

  • Citizen of the Universe
  • *****
  • Posts: 1955
  • Upgraded to MC22 Master using preorder discount
Re: Search Fields and Update Other Fields Based on Results ?
« Reply #3 on: January 23, 2013, 04:24:41 pm »

Okay, I did find this in the Wiki:

Quote
if(isequal([filename (path)],Classical,8),Classical,Not Classical)
Here, compare mode number eight has been specified, so, if the letters classical appear anywhere in the file path for a given file, the expression will return "Classical" and if not, it will return "Not Classical". Note that when using compare modes seven and eight, the subject must be given first, and the term to compare for given second

and obviously, just change Classical to Mozart (so others have had similar thoughts).

Can that be used in Fill Properties from Filename ?

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Search Fields and Update Other Fields Based on Results ?
« Reply #4 on: January 23, 2013, 04:27:41 pm »

You can apply them directly in-line in any tag editing field by prefixing the edit with an equals sign.  So, edit [Composer] and type =<expression>

So, to give you a (very) simple example, if you select a bunch of files, edit the [Episode] tag, and type:

=Counter()

It will re-tag the [Episode] tag for each file as: 1, 2, 3, 4, 5 (etc).

That's a stupid-silly expression, but you can use complex ones.  I find if I build one that is complex enough that it is tough to type over and over, I just make it into its own calculated field, which "acts like" a variable or method call.

So, you define your RegEx search to give you the results you want, make it a field called [MyHandyRenamer] (or whatever) and then do this on the [Composer] field:

=[MyHandyRenamer]
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Search Fields and Update Other Fields Based on Results ?
« Reply #5 on: January 23, 2013, 04:29:39 pm »

By the way, you can combine this with static text too.

So, using my Counter example, if you wanted the pattern to be e## for the episode number (for some reason), you'd use:

=ePadNumber(Counter(), 2)
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

kstuart

  • Citizen of the Universe
  • *****
  • Posts: 1955
  • Upgraded to MC22 Master using preorder discount
Re: Search Fields and Update Other Fields Based on Results ?
« Reply #6 on: January 23, 2013, 04:33:16 pm »

Okay, looking at the expression I found, will this work:

if(isequal([filename],Mozart,8),Mozart,[Composer])

and will it output the previous value of the Composer field if I use [Composer] ?

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Search Fields and Update Other Fields Based on Results ?
« Reply #7 on: January 23, 2013, 05:40:06 pm »

Right.  That expression will examine filename, and if it contains the string "Mozart" anywhere, it will output Mozart.  Otherwise, it will output the value contained in the Composer field.

Above I gave instructions on how to *see* the results in action, live.  Do this first, so you can learn how expressions work in MC, and test them quickly.

Once you're confident in the output, use glynor's instructions for taking your expression and assigning the output to some field.
Logged
The opinions I express represent my own folly.
Pages: [1]   Go Up