INTERACT FORUM

Please login or register.

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

Author Topic: Expression help  (Read 4395 times)

daveg

  • World Citizen
  • ***
  • Posts: 158
Expression help
« on: June 03, 2015, 09:50:00 am »

have been trying to figure out an expression for a few days now, but cannot seem to get it to work.

My issue is.....I have many files with a dash and space "- " in front of the filenames. When auto importing, I would like to have JR remove those 2 characters.

I have tried the removecharacters([Filename(name)], - ). Also the removeleft function, but that will remove the first 2 characters even if I don't want it to.

Have looked at the regex function....but that just gave me a headache...any help would be appreciated.

Thanks
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42373
  • Shoes gone again!
Re: Expression help
« Reply #1 on: June 03, 2015, 09:52:38 am »

The function RemoveCharacters(...) should do the trick.

An example:
RemoveCharacters([Artist], - [], 0)
Logged
Matt Ashland, JRiver Media Center

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Expression help
« Reply #2 on: June 03, 2015, 10:51:59 am »

Here is a regex I just tested that works:

Code: [Select]
=regex([Name],/#(- )*(.+)#/,2,0)
Replace [Name] with whatever field you are working on as input.  I think you knew that; just being sure.

Regex is one of the most powerful text manipulation tools around.  I'm very glad it's included in JRiver.  Makes a lot of things easy.  :)  If you'd like me to I can break this one down for you as a short lesson on how regex works.

Brian.
Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: Expression help
« Reply #3 on: June 03, 2015, 11:59:49 am »

Brian

I for one would appreciate that immensely!
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Expression help
« Reply #4 on: June 03, 2015, 04:06:33 pm »

I've posted a new topic, breaking down and explaining this Regular Expression (with a slight modification).  You can read it here:

http://yabb.jriver.com/interact/index.php?topic=97996.0

Brian.
Logged

daveg

  • World Citizen
  • ***
  • Posts: 158
Re: Expression help
« Reply #5 on: June 04, 2015, 09:14:47 pm »

Thanks for the help....but I have still been struggling with this. The removecharacter function does not work, it just removes all instances.

The regex does not work either. Have tried many different variations, but can't get any to work.

An example of a file is c:\music\- Skid Row - Psycho Love.mp3 or c:\music\- green day - ashley - demo.mp3

or could be c:\music\abba-waterloo.mp3

The regex expression =regex([FileName(Name)],/#(- )*(.+)#/,2,0) seems to remove the .mp3 at the end of the filename.

Have tried =regex([Filename(Name)],/#(- )*(.+)#/,2,0) among others. Any other suggestions
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Expression help
« Reply #6 on: June 04, 2015, 09:47:38 pm »

^ Ok, hold on.  I think I ignored earlier that you are talking about *file* names and not track titles.  Are you trying to rename files?  Or change the track names inside of JRiver?

If you want to change track titles, then what I showed should work fine.  If you want to RENAME the actual files on disk, you should probably use the Rename, Move, and Copy tool.  It doesn't seem to understand Regex, but it really doesn't need to either.  You can tell it to make the filename something like:

[Artist] - [Album] - [Name]

Or something more simple like my favorite:

[Track #]_[Name]

Or whatever you want really.  As long as your metadata tags are right, Rename, Move and Copy can use them to rename your files into any format you want.

Brian.
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: Expression help
« Reply #7 on: June 04, 2015, 10:16:14 pm »

For future reference and use during import, the original question.

=regex([Filename (name)],/#(- )*(.+)#/,2,0)
http://wiki.jriver.com/index.php/Expression_Language#Regex.28.E2.80.A6.29:_Regular_expression_pattern_matching_and_capture
The fourth example uses this exact form of "[filename (name)]". Note the extra space.

This also works.
=regex(Filename(),/#(- )*(.+)#/,2,0)
http://wiki.jriver.com/index.php/Expression_Language#FileName.28.E2.80.A6.29:_Returns_a_file.27s_name_component
Note the last example.

But as Brian suggests, you can just run the Rename, Move, and Copy tool. Although if you update filename tag in the library using Regex, MC does seem to update the filename on disk immediately as well.
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

daveg

  • World Citizen
  • ***
  • Posts: 158
Re: Expression help
« Reply #8 on: June 05, 2015, 04:58:58 am »

I can't thank you both enough for your help. I am going to read that regex document to get a better understanding. Great info. I did some Perl programming about 15 years ago, but life and kids etc seem to have pushed that all that stuff out of my brain :P

blgentry. The metadata is usually not correct. I need the file name to be correct first, then use the "rename files from filenames" function to correctly populate the artist, album etc info.

Got it working with the =regex(Filename(),/#(- )*(.+)#/,2,0) line in auto import.

As for the rename,move and copy tool. This is something I wanted to have automated... But on that note, that function did not work for what I was trying to do. I had  

Replace what: \ -
Replace with:  \

For some reason, this does not work. or could I have used a regex expression there?

And just in case anyone was wondering why filenames are all over the place...I had about 7,000 old cd's that I finally wanted to rip. I hired a bunch of kids to do it for me, and they all ripped with different naming conventions.

Thanks again
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Expression help
« Reply #9 on: June 05, 2015, 08:26:53 am »

A couple of thoughts:

1.  Yay!  Glad you got it working.
2.  I didn't know you could rename files on import.  Are you doing some sort of Apply Tag functionality, like to the filename or something?  I'm always learning new stuff with JRiver and this one is definitely something I'm not familiar with.
3.  If your file names and tags are very, very wrong and not standardized, you might be in for a long organization process.  Do you already have a plan for figuring out which sets of files have which naming conventions so you can use the Fill Tags From Filename function?  If you have a plan and it won't require tons of effort, maybe you're all set.

If you don't already have a good plan, you should consider using another tool to clean up your metadata first.  Something like Music Brainz Picard can do pretty deep analysis on your files to find the correct metadata and apply it.  It even has a feature to listen to the files to figure out what songs they are.  I mean the computer listens, with no human intervention required.  Music Brainz is free so it might be worth trying.  Maybe on 5 or 10 albums first to see how it does.

Anyway, I wish you good luck on this quest.  If you lived anywhere close I'd offer to help in person.

Brian.
Logged

daveg

  • World Citizen
  • ***
  • Posts: 158
Re: Expression help
« Reply #10 on: June 05, 2015, 09:11:52 am »

Thanks. But this expression has solved all my problems...all I needed was the dash/space to be removed from some filenames. That was really my only issues.

I didn't know you could rename files on import either, but with JRiver, almost anything is possible. Just have to look hard enough.

Here are the steps I used to accomplish that.

1. Go to auto-import settings and select the folder you want to modify
2. On bottom, under "apply these tags" chose "add"
3. For field I added Filename(name)
4. Function =regex(Filename(),/#(- )*(.+)#/,2,0)

That's it. Now it will remove the first 2 characters if they match the pattern on auto import. Now I just have to highlight them and fill the properties from the filename. I'm sure there is a way to automate this(and will look into that later), but only takes me a few seconds to accomplish that now

 

Great info on the other tools, but as you can see, my problems have been solved.

Thanks again.
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Expression help
« Reply #11 on: June 05, 2015, 10:06:36 am »

Thanks for the additional information Dave.  JRiver does SO MUCH; I'm always interested to know more.

More importantly I'm happy your problem is solved. :)

Brian.
Logged
Pages: [1]   Go Up