INTERACT FORUM

More => Old Versions => JRiver Media Center 25 for Windows => Topic started by: woollies66 on May 12, 2019, 02:25:26 am

Title: Expression Language - Returng the position of an Ascii character in a string
Post by: woollies66 on May 12, 2019, 02:25:26 am
Apologies in advance if I've posted this in the wrong section.

MC Version - 25.0.33 (64 bit)
OS             - Windows 10 (all service packs applied)


Background:
Re-ripping cd collection after an epic NAS failure in 2018 :-[

Problem:
When the CD track info is retrieved from the on line databases the "artist" is being included in the track name e.g.
"Visage - Fade to Grey"

Request:
Can anyone point me to the function(s) within the expression language which will return the "found at" position within a string of a specified ascii character

I would like to populate the [artist] field with "Visage" after parsing the [name] field , searching for "-"
I have identified the Mid() as potentially being the "Parsing" function to use

=Mid([name],1,"Found at position" - 1)

in other languages i.e. Vb I would use the "instr" function (after doing a logic test to confirm that the "-" char exists with the string being searched)

e.g. =mid([name],1,instr([name],"-")-1)

Any help would be very much appreciated

Best regards

woollies66
Title: Re: Expression Language - Returng the position of an Ascii character in a string
Post by: RoderickGI on May 12, 2019, 03:14:13 am
Problem:
When the CD track info is retrieved from the on line databases the "artist" is being included in the track name e.g.
"Visage - Fade to Grey"

That shouldn't be happening. At least, not if you are ripping with MC. Are you ripping with some other tool?
The easiest way to fix the problem would be to eliminate it at the source. Are there settings in the tool you are using to change its behaviour with respect to the Name tag?
I would expect any ripping tool to put the Artist in the Artist tag, and the Track name in the Name (or Title, depending on the tool, but it is the same tag) tag. Unless the source database is set up in a strange way.

Alas, I am not the person to help with this level of expression. You need someone with Regex experience, which could fix that is a jiffy.
Title: Re: Expression Language - Returng the position of an Ascii character in a string
Post by: woollies66 on May 12, 2019, 03:48:27 am
Hi
 Thanks for the speedy response

 Yes all of my ripping is done within MC25

99.99% of the time the lookup returns the correct album information, in the 0.01% where it hasn't, it is always on compilation cd's . In the example I've used - the "visage" track is from CD 1 of 3 for the album "The New Romantics" by "Various Artists"

If I've understood some of the other threads on the "album lookup" functionality in the YABDB (I think) database , then it will return what has been loaded in to. If I can work out how to fix it without having to manually edit it, I will then upload it back to the online database.

Title: Re: Expression Language - Returng the position of an Ascii character in a string
Post by: Moe on May 12, 2019, 10:22:44 am
I am a bit of a regex neophyte but this should work.  This will only work if there is one - in the song title, if there are more you will get strange results.

You'll create two expression columns for the first one use

regex([Name], /#(.+)\s-\s(.+)#/, -1) [R1]

and the second use

regex([Name], /#(.+)\s-\s(.+)#/, -1) [R2]

Using your example of Visage - Fade to Grey the first one will return Visage and the second will return Fade to Grey.  You can then use MCs built in move/copy field tool to put them in their proper place.

If you want to get some idea of how this works, see this https://regex101.com/r/M0j84q/1
Title: Re: Expression Language - Returng the position of an Ascii character in a string
Post by: dtc on May 12, 2019, 10:29:44 am
The Expression Language is extremely powerful, but I do think a Find, Instr type function would be useful. Having to use Regex to find a hypen is a bit of overkill. Many users are just not that familiar with Regex.
Title: Re: Expression Language - Returng the position of an Ascii character in a string
Post by: Moe on May 12, 2019, 02:08:44 pm
There is a non-regex solution

Setup two expression column like I suggested before but use these values instead

   listitem([name], 0, / -/ )
   listitem([name], 1, / -/ )

Title: Re: Expression Language - Returng the position of an Ascii character in a string
Post by: woollies66 on May 12, 2019, 02:18:55 pm
Thanks Moe


I like the 2nd  potential solution better, simpler to understand. ;)
I'll give it a try

Thanks for your help

BR woollies66
Title: Re: Expression Language - Returng the position of an Ascii character in a string
Post by: RoderickGI on May 12, 2019, 05:56:50 pm
There is a non-regex solution

Setup two expression column like I suggested before but use these values instead

   listitem([name], 0, / -/ )
   listitem([name], 1, / -/ )

Nice simple solution Moe. Well done.
Title: Re: Expression Language - Returng the position of an Ascii character in a string
Post by: Moe on May 12, 2019, 06:12:34 pm
Thanks, I learned something new too.
Title: Re: Expression Language - Returng the position of an Ascii character in a string
Post by: woollies66 on May 13, 2019, 03:29:10 pm
Hi Moe

This worked perfectly, I did not bother creating 2 custom DB fields - I just entered the 2 commands respectively in the [Artist] and [name] fields in the "tag" action window (prefixed with "=") prior to ripping the CD. Once I initiated the rip - MC took over, ensuring all tracks named correctly therefore no need to use "rename, move & copy files..."

Thanks once again

woollies66
Title: Re: Expression Language - Returng the position of an Ascii character in a string
Post by: Moe on May 13, 2019, 03:46:51 pm
Happy to help, glad it worked for you.

To be clear though, I wasn't referring to "rename, move & copy files..." there is another command in MC called "Move / Copy Fields..." (Right click a track\Library Tools\Move / Copy Fields...) that allows you to copy, move or flip flop the value of two columns.
Title: Re: Expression Language - Returng the position of an Ascii character in a string
Post by: ferday on May 13, 2019, 11:40:09 pm
good one Moe!