INTERACT FORUM

Please login or register.

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

Author Topic: Getting Disc Number off of Album Name (Solved)  (Read 5436 times)

DHF

  • Junior Woodchuck
  • **
  • Posts: 74
Getting Disc Number off of Album Name (Solved)
« on: May 22, 2016, 10:32:22 pm »

All:

I am introducing myself to the expression language with a task - I want to pull the disc number off of the album name.

Say there are 4 albums - Opera Classic Disc 1, Opera Classic Disc 2, etc.   I want to look at the Album name and pull disc number off of it.  If it has Disc or Vol in the name.

So - I found the regex function, and I am making headway.  I ended up defining a library field called Disc Calculator and putting the code in there.  But its a pain to keep going to tools - options - manage library fields.  Is there a better way to test code?

In the wiki - I found that some of the arguments to the regex function in the examples have options or syntax that I cant find in the wiki.  For example (from the wiki):

regex(D03T02 some track.mp3, /#^D(\d+)T(\d+)#/, 1)Disc: [R1], Track: [R2]
The string is matched against the regexp that is looking for a D followed by any number of digits, followed by a T and then more digits. Those digits were captured, and later used to output the value Disc: 03, Track: 02.


I get it that the (\d+) grabs digits, but are there other options - like one digit or two digits?  and where would I find the descriptions of those arguments like \d+?

Thanks in advance.
Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: Expression Language Arguments descriptions?
« Reply #1 on: May 23, 2016, 12:04:53 am »

Not sure I understand the specifics

If(isequal([album],disc,8),....) will find disc in the album name easier than regex, but not necessarily read the disc #.  Proper tagging will have the disc # field populated rather than having it in the album title...just saying

Regex is great but tough.  There are a few good tutorials on the net, they will help a lot if you want to go down that road.  MC expressions without regex can do a lot as well but certainly have a few restrictions.  Blgentry is te resident regex master

As for testing code, the easiest way is to make an expression column in a view, so you get te results instantly.  When you're happy, then make a new field
Logged

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1855
Re: Expression Language Arguments descriptions?
« Reply #2 on: May 23, 2016, 02:59:27 am »

I get it that the (\d+) grabs digits, but are there other options - like one digit or two digits?  and where would I find the descriptions of those arguments like \d+?

Thanks in advance.

Something like:

http://www.rexegg.com/regex-quickstart.html

Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Expression Language Arguments descriptions?
« Reply #3 on: May 23, 2016, 06:52:31 am »

A. Testing expressions is definitely not as easy as it could be.  But expression columns make it easier.   I usually use expression columns for any testing until I get the expression exactly right.  Then I either use it to alter some tags (one time use) or paste it into a custom field.

B.  Regex is sort of a special case, as MC implements regex using a library (I think).  So MC didn't define the regex syntax.  It borrowed the syntax from a generally accepted standard.  In this case, MC uses the Perl regex syntax. I use this reference, but there are others:

http://www.boost.org/doc/libs/1_54_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html

C.  Specific to matching specific numbers of character sets:  You already know about +, which means one or more matches.  * means 0 or more.  If you want to match a specific number it's like this:

\d{1,3}

That matches between 1 and 3 digits.

You might have to use global variables (not regex) to get an accurate disc count.  That's how I did it way back.  Hopefully your way gives you the results you want.

Good luck!

Brian.
Logged

DHF

  • Junior Woodchuck
  • **
  • Posts: 74
Re: Expression Language Arguments descriptions?
« Reply #4 on: May 31, 2016, 08:14:48 pm »

Many thanks for all the help.   The pages on Perl and Regex were exactly what I needed.   Here is what I came up with:

if(Regex([Album], /#(Vol (\d+)|Vol. (\d+)|Disc (\d+))#/, 0),
Right([R1],2),)

So it finds the 3 patterns I see most in multi disc albums - Vol, Vol. and Disc followed by a blank and a one or two digit number. Then strips off all but the last 2 characters, leaving what I want - the disc number.  If the pattern doesnt match - it outputs nothing.

I made this a library field called Disc Calculator.  I then edit [Disc#] to be [Disc Calculator] on those albums.

J River is amazingly flexible - although I will admit that REGEX is not for the masses.  The wiki should have more references in it.
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Expression Language Arguments descriptions?
« Reply #5 on: May 31, 2016, 08:26:27 pm »

Glad you got it working.  :)

Brian.
Logged

DHF

  • Junior Woodchuck
  • **
  • Posts: 74
Re: Expression Language Arguments descriptions?
« Reply #6 on: May 31, 2016, 08:28:07 pm »

Your post was very helpful.  I appreciate it.

I know I could have just asked and somebody would have written it - but I learned so much more by doing it myself.

It was fun.
Logged

AudibleImagery

  • World Citizen
  • ***
  • Posts: 109
Re: Expression Language Arguments descriptions?
« Reply #7 on: February 16, 2023, 08:14:52 pm »

I then edit [Disc#] to be [Disc Calculator] on those albums.

How would I "edit [Disc#] to be [Disc Calculator] for albums"?
Logged
Pages: [1]   Go Up