More > JRiver Media Center 21 for Windows
Getting Disc Number off of Album Name (Solved)
DHF:
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.
ferday:
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
mark_h:
--- Quote from: DHF on May 22, 2016, 10:32:22 pm ---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.
--- End quote ---
Something like:
http://www.rexegg.com/regex-quickstart.html
blgentry:
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.
DHF:
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.
Navigation
[0] Message Index
[#] Next page
Go to full version