INTERACT FORUM

Please login or register.

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

Author Topic: Expression Language - Returng the position of an Ascii character in a string  (Read 963 times)

woollies66

  • Recent member
  • *
  • Posts: 35

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
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186

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.
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

woollies66

  • Recent member
  • *
  • Posts: 35

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.

Logged

Moe

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 695
  • Hi

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
Logged

dtc

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3015

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.
Logged

Moe

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 695
  • Hi

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, / -/ )

Logged

woollies66

  • Recent member
  • *
  • Posts: 35

Thanks Moe


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

Thanks for your help

BR woollies66
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186

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.
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

Moe

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 695
  • Hi

Thanks, I learned something new too.
Logged

woollies66

  • Recent member
  • *
  • Posts: 35

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
Logged

Moe

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 695
  • Hi

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.
Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732

good one Moe!
Logged
Pages: [1]   Go Up