INTERACT FORUM

Please login or register.

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

Author Topic: Expression Help for reordering last name and first name in field  (Read 2836 times)

r_harms

  • Junior Woodchuck
  • **
  • Posts: 67

Hey,

With all the help and good advice I've gotten here my library is getting so clean I'm feeling the urge to try to get it perfect.

It seems like almost every artist has a listing as First Last & another listing as Last, First. I've already cleaned up many manually over the years but now I really want to get it done!

I've been experimenting with expressions but I think I've over complicated it to the point where I'm in over my head (again).

As always, I would appreciate any info that would get me going in the right direction.

Thanks!

Rick
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help for reordering last name and first name in field
« Reply #1 on: January 31, 2012, 10:27:15 pm »

Which way do you want them ultimately?  First Last, or Last, First?
Logged
The opinions I express represent my own folly.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help for reordering last name and first name in field
« Reply #2 on: January 31, 2012, 10:35:32 pm »

...and to get you started.

Create a new Panes view.  In the first column, add an expression column with the expression:

  If(regex([Artist], /#^\w+,\s#/), Yes, No)

In a second column, add the library field Artist.

In a third column, add an expression column with the expression:

  If(Regex([Artist], /#^(\w+),\s(.+)$#/), [R2] [R1], [Artist])

This will give you a way to see which tracks are possibly First Last vs. Last, First.  I say possibly because the expression is simplistic, just testing for a simple word followed by a comma, followed by a space.  We can tune this as needed.

Once you have this going, we can use the third column's expression as the basis for modifying Artist.
Logged
The opinions I express represent my own folly.

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Expression Help for reordering last name and first name in field
« Reply #3 on: January 31, 2012, 10:56:35 pm »

Logged
"Some cultures are defined by their relationship to cheese."

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

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help for reordering last name and first name in field
« Reply #4 on: January 31, 2012, 11:02:33 pm »

Oh, my, I am a Pisces.
Logged
The opinions I express represent my own folly.

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Expression Help for reordering last name and first name in field
« Reply #5 on: January 31, 2012, 11:09:29 pm »

Oh, my, I am a Pisces.

I was thinking you were more Batman in that one, my friend.  I'm the Joker wondering where you get these wonderful toys.  And, I guess, poor r_harms is the shrieking girl.
Logged
"Some cultures are defined by their relationship to cheese."

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

rick.ca

  • Citizen of the Universe
  • *****
  • Posts: 3729
Re: Expression Help for reordering last name and first name in field
« Reply #6 on: February 01, 2012, 12:24:41 am »

Logged

r_harms

  • Junior Woodchuck
  • **
  • Posts: 67
Re: Expression Help for reordering last name and first name in field
« Reply #7 on: February 01, 2012, 10:59:05 am »

Too cool, thanks for the help and the good humor! It looks like I'm the screaming girls in both places, as usual :o

Thanks again MrC. I owe you at least a case of cold ones. I've been a great fan of Media Center since I discovered it and with all your help I'm really in love.

I've been using 'Last, First' as [Artist] and [Album Artist] has been empty. I'm going to change [Artist] to 'First Last' and make [Album Artist] 'Last, First' and get 'Various' tuned up so I can use either style where appropriate. Like I said, just too cool.

I mentioned I was over my head, hell I could barely get the expressions typed in correctly. My Media system doesn't have an internet connection so I used notepad to print out the expressions but I didn't notice it dropped the '/' & "\" characters so I had to write them down for the transfer. Well worth it!

Thanks Again...

Rick
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help for reordering last name and first name in field
« Reply #8 on: February 01, 2012, 12:32:27 pm »

Suggestions...

Set Artist as you want, to First Last.

Leave Album Artist blank, except in cases where you want to assign a single Artist to a multi-artist compilation disc, such as a soundtrack, or a disc that is primarily one artist but contains a couple of exceptions.  There is an automatically calculated field named Album Artist (auto), that uses the values of Artist to determine if an album is a Multiple Artist album, but will use Album Artist when set.  Several areas of MC use Artist as a shorthand for Album Artist (auto), and this drives views, headers, etc.

Create a new use-defined field, called Artist (last, first), and assign your Last, First names there.  This way, you can use Last, First how you want, and use First Last via Artist and Album Artist (auto) normally.

http://wiki.jriver.com/index.php/File_Properties_%28tags%29

To assign the result of column 3 above (the expression that re-orders), just tack on an '=' character in a field's edit area (Tag Action Window, or in-column editing):

  =If(Regex([Artist], /#^(\w+),\s(.+)$#/), [R2] [R1], [Artist])

To assign your Artist (last, first), select any tracks for which Artists is currently formatted as Last, First, edit Artist (last, first), and assign:

  =[Artist]

For those Artist values that are not in Last, First order, create a 4th column in your view, and set the view to the following simplistic expression:

  if(Regex([Artist], /#^(\w+)\s+(.+)$#/), [R2]/, [R1], [Artist])

This is very rudimentary, in that it just moves the first word to the end of the phrase - it does not deal well with such artists as "Mumford and Sons", so you'll want to use it selectively.  The view should help.  We can make the expression much more complex to handle many of the cases, but it may not be worth your while to spend so much time on this.  Let me know what your needs are.

You can use the 4th column expression to assign the values, just like above.
Logged
The opinions I express represent my own folly.

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Expression Help for reordering last name and first name in field
« Reply #9 on: February 01, 2012, 01:06:24 pm »

xkcd is so brilliant.  Thanks, rick.  That's a good one.
Logged
"Some cultures are defined by their relationship to cheese."

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

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help for reordering last name and first name in field
« Reply #10 on: February 01, 2012, 03:41:04 pm »

I'm going downstairs to make homemade vegetable soup.  I think I'll use Regex().
Logged
The opinions I express represent my own folly.

r_harms

  • Junior Woodchuck
  • **
  • Posts: 67
Re: Expression Help for reordering last name and first name in field
« Reply #11 on: February 01, 2012, 07:50:53 pm »

MrC, Wow, the Regex soup sounds great, but for me probably indigestible! I'm still trying to digest everything in your last post. Man, I had made some notes before I started out and you have given me more to think about. Thank you again!

One thing I've noticed in my library is artists with an '&' in them should be excluded from modification. I'm wondering how to modify:

 If(regex([Artist], /#^\w+,\s#/), Yes, No)  to also check for an '&' or better still ' & " in the artist name.

I even dug out my O'Reilly Mastering Regular Expressions from my past and tried my hand. I may have learned a thing or two, but I'm no closer to an answer. I love the power but my brain is now mush...

Ideas or solutions are always most welcome.

Rick

Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help for reordering last name and first name in field
« Reply #12 on: February 01, 2012, 08:43:18 pm »

It is probably faster to wrap the expression inside an If() that excludes what you don't want.  A replacement for the 4th column:

IfElse(Regex([Artist], /# [+&] #/), [Artist],
          Regex([Artist], /#^([A-Z][\w.]+)\s+([A-Za-z]+)$#/,0,1), [R2]/, [R1],
          1, [Artist])

This looks for a " & " or " + " and just outputs Artist, otherwise, it does the reversal if it looks like a possible First Last.  I've modified the RE a little to look for a capital first letter, followed by any letters, digits, or a dot (for an initial-only first name) and a next name that is letter-only.  Feel free to experiment and modify to taste.  I wouldn't try to make it perfect - it never can be given ambiguous input.
Logged
The opinions I express represent my own folly.
Pages: [1]   Go Up