INTERACT FORUM

Please login or register.

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

Author Topic: Help with regex  (Read 3502 times)

jherbert

  • World Citizen
  • ***
  • Posts: 120
Help with regex
« on: April 28, 2015, 03:08:34 am »

I am trying to build a regular expression that will automate renaming and moving files in a way that was used in older versions of MC.

If there is an album artist for an album, this should be used as the name of the artist subdirectory, if there is no album artist the artist subdirectory shall use the name of the first artist listed in the artists field.

- ListItem([Artist],0)\[Album])
- [Album Artist]\[Album]

both do work, but

If(IsEmpty([AlbumArtist]),ListItem([Artist],0)\[Album],[Album Artist]\[Album]

does not.What am I doing wrong?
Logged

Arindelle

  • Citizen of the Universe
  • *****
  • Posts: 2772
Re: Help with regex
« Reply #1 on: April 28, 2015, 08:54:00 am »

I'm a real noob in Regex, but looks like you are missing a parenthesis somewhere ....  for the If(IsEmpty ?
Logged

BryanC

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2556
Re: Help with regex
« Reply #2 on: April 28, 2015, 09:47:50 am »

If(IsEmpty([Album Artist]),ListItem([Artist],0)\[Album],[Album Artist]\[Album])

I think you might want to try [Album Artist (auto)] as this function is already baked into MC. Otherwise, see the change above.
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8955
Re: Help with regex
« Reply #3 on: April 28, 2015, 11:24:38 am »

For clarity, regex is all that gobbledy stuff that MrC could speak fluently, something to do with perl, google it to see what I mean. It's very powerful, but also quite hard to get to grips with for most of us (me included).
What we're discussing here are simply called 'expressions' within MC. A small distinction, but important when you're looking for help.

Here's a quote from August last year...
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

So, in your case, you should be using:

If(IsEmpty([AlbumArtist, 0]),ListItem([Artist],0)\[Album],[Album Artist]\[Album])

And now some thoughts on this string above:
By default, if you use multiple, semi colon seperated artists in the artist field, when using the rename tool, [artist] will default to the first item in the list without any trickery from the user, MC should just pick the first one and move along.

Also, as BryanC has stated, I'm sure that if you use [album artist (auto)] it does exactly what you appear to be after all on it's own. i.e.: If Album Artist is populated, it will use that value, if not, it will use the first item in the artist field, and if the album has multiple artists, it can be set to use Various by way of the check box you see in the tool itself.

If you have any other questions, please ask, or if the above described behaviour is not what you're seeing, please provide as much detail as possible and we'll try and see if we can see anything else wrong.

EDIT:
Just spotted this too: If(IsEmpty([AlbumArtist]....
Is that a typo? or perhaps a custom library field of yours? otherwise, it will fail as the default MC field is [Album Artist]

Regards,
-marko

jherbert

  • World Citizen
  • ***
  • Posts: 120
Re: Help with regex
« Reply #4 on: April 28, 2015, 12:05:27 pm »

Thank you all for your help. I do not use [Album Artist (auto)] because it returns "Multiple Artists" whenever there are fifferent co-artists in one album.

Jack Bruce; Eric Clapton
Jack Bruce; Eric Clapton
Jack Bruce; Eric Clapton

returns "Jack Bruce"

but

Jack Bruce; Eric Clapton
Jack Bruce; Carla Bley
Jack Bruce

returns "Multiple Artists" while I want it to return "Jack Bruce". This is the way [Album Artist (auto)] used to work, but this was changed in MC19 orMC20.

On

Eric Clapton
Carla Bley
Jack Bruce

as artists I use "Various Artists" in the Album Artist field.

Marko spotted my error: I misstyped Album Artist, so this could not work.

If(IsEmpty([Album Artist, 0]),ListItem([Artist],0)\[Album],[Album Artist]\[Album])

works like a charm. Just in Case somebody else wants to use this.  :)

Thank you all once again!
Logged

~OHM~

  • Citizen of the Universe
  • *****
  • Posts: 1825
  • "I Don't Play The Music The Music Plays Me"
Re: Help with regex
« Reply #5 on: April 28, 2015, 12:58:46 pm »

MrC could speak fluently,

Off topic but....where oh where has MrC gone?
Logged
“I've Reached A Turning Point In My Life. I Now Realize I Have More Yesterdays Then Tomorrows”

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 41968
  • Shoes gone again!
Re: Help with regex
« Reply #6 on: April 28, 2015, 01:13:29 pm »

Off topic but....where oh where has MrC gone?

He's AWOL.

I've reached out to him a few times by email, but only crickets.
Logged
Matt Ashland, JRiver Media Center

jherbert

  • World Citizen
  • ***
  • Posts: 120
Re: Help with regex
« Reply #7 on: May 06, 2016, 10:16:06 am »

Another probably dumb question:

I want to rename/move files from a working directory to a target directory depending on file type, i.e. *.flac is supposed to be moved to \lossless and all others shall be moved to \compressed.

I tried IfElse([File Type]=flac", l:\music, m:\music)

Which does not work. What's wrong?
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8955
Re: Help with regex
« Reply #8 on: May 06, 2016, 10:48:47 am »

Using ifelse()
ifelse(isequal([file type],flac), l:\music, 1, m:\music)

You give it multiple tests, and it only takes the positive result and moves on to the next. So, here, we only have two, test for flac, then everything else. This allows you to add more file types easily by inserting the test for them before the last test, a bit like so...
ifelse(isequal([file type],flac), l:\music, isequal([file type],ape), n:\music, 1, m:\music)

If you were only ever going to deal with two scenarios, the following is closer to what you were originally driving at, works the same, but is not so easily expaneded upon...
if(isequal([file type],flac), l:\music, m\music)

marko

jherbert

  • World Citizen
  • ***
  • Posts: 120
Re: Help with regex
« Reply #9 on: May 06, 2016, 11:52:13 am »

marko, thank you so much!
Logged
Pages: [1]   Go Up