INTERACT FORUM

Please login or register.

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

Author Topic: Tag manipulation with expression language  (Read 5747 times)

jacobacci

  • Galactic Citizen
  • ****
  • Posts: 256
Tag manipulation with expression language
« on: August 24, 2015, 05:42:44 am »

Hi all,
I am new to using the expression language and I'm looking for some pointers to shorten the learning curve.
I have converted all my SACD ISOs to PCM. MC tags the PCM files with the tags the ISOs have in the library. This means the files show up as duplicates in MC, as artist, album, title etc. are identical.
I would like to add the letters "DS" (as in down sampled) to the album tag of the PCM files. My ISO album tags are "D_xxxxxxx". As I want to be able to run the script also after some of the files already have the DS prefix, I need to make the addition conditional. Functionally the script should do the following

- See if the album Tag of the file starts with D_
- if yes, add DS in front of it
- if not, do nothing
- do this for all files in a particular directory

How do I best go about doing this? I have read that I can add an expression column to the view of the folder where the files reside. Is this the best way to do this?

Thanks a lot
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Tag manipulation with expression language
« Reply #1 on: August 24, 2015, 09:27:32 am »

First you'll want to be able to select the group or groups of files you want to operate on.  Personally, I would use the Audio > Files view for this.  You can choose a directory from the Location pane.  You can even make it a parent directory if you have lots of these to do.  Next, I'd use the File Type pane to remove all SACD files.  Select the file type(s) that you want to rename and of course leave out SACD so it doesn't get selected.

As for actually re-writing the album tag, you can definitely use expressions.  There are probably several ways to do it.  Here's an expression I just tested to do what you're asking for:

Code: [Select]
if(compare(regex([Album], /#^D_(.+)$#/,0,0), =,1), DS_[R1], [Album])
This works on the [Album] tag.  If you want to apply this to a different tag, you'll need to change the expression appropriately.

To test this out, make a new expression column and paste this expression into it.  Then review it's values for the albums you are talking about.  Make sure it looks correct.  To apply this to the [Album] tag here's the procedure:

1.  Select some files you want to change.  Start with a small test group.  If it doesn't work, use undo to reverse the changes right away.
2.  Press Alt-enter, or right click to select "Tag".  The tagging pane will appear on the left.
3.  Find the Album tag and click in it to highlight it.  You are now editing that tag for all selected files.
4.  Paste in the expression with an = sign in front of it.  Like this: 
Code: [Select]
=if(compare(regex([Album], /#^D_(.+)$#/,0,0), =,1), DS_[R1], [Album])5.  Press enter to make the changes.
6.  Review to make sure the changes worked.  If not press control-Z to undo.  Or Edit > Undo

You can work on a larger group, or the whole thing after you've done a test or two.

NOTE:  This changes the [Album] tag in all of the files you are working on.  It does NOT change the filename.  To change the file name, you would need to use the Rename, Move, and Copy tool *after* you make these changes to the Album tag.  We can help you with that also if necessary.

Good luck.  Let us know how you do and/or if you need any help tweaking this to work for you.

Brian.
Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: Tag manipulation with expression language
« Reply #2 on: August 24, 2015, 09:49:44 am »

i would do it blgentry's way because i like regex.

but to offer an alternative, you can do this in the JRiver built in expression language as well, which may help you learn the 'basics' a little better (regex is not basic LOL)

instead of blgentry's code, you can paste in this code (in the album field or a new expression column):

Code: [Select]
if(isequal(left([Album],2),d_,1),DS-[Album],[Album])
if you want to do another field than album, change as needed.  the rest of blgentry's excellent comments apply, it does NOT change anything on disk.  you can either paste it in to an expression column (right click, add expression column) or paste in to the tag field you want to change.

personally, i'd paste it in to an expression column (let's call it DS), then i could see the changes.  then i'd go in to the tag window if i was happy and type into the [album] field

Code: [Select]
=[DS]
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Tag manipulation with expression language
« Reply #3 on: August 24, 2015, 10:02:27 am »

Reading Ferday's post, I realized that the requirement isn't exactly clear.  Ferday and I have read it two different ways.

I read it to mean that he wants to transform this way:

D_The_Great Album ---->  DS_The_Great_Album

I think Ferday read it as:

D_The_Great_Album ----> DS-D_The_Great_Album

Can you give an example of what you are trying to do so we can be sure?

Ferday:  Not trying to pick on you at all buddy.  I was reading your code because I wanted to understand more about the other functions in the Expression Language and saw the differences.  I'm not 100% sure what the original poster really wants, so I'm asking him to clarify.

Thanks,

Brian.
Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: Tag manipulation with expression language
« Reply #4 on: August 24, 2015, 10:15:43 am »

ha ha ha no worries at all, if i didn't have my code picked apart i wouldn't get better at it.  i never though about wanting to remove the current d_ which of course i would've then been irritated at having, so thanks for pointing it out!

if he wanted your scenario then this should work

Code: [Select]
if(isequal(left([Album],2),d_,1),replace([album],D_,DS-),[Album])
which would output D_name.iso to DS-name.iso.  of course replace the dash with _ or whatever...i hate underscores so i use dashes more often ;)
i've only tested this with one album (renaming it to D_album) FYI

if the album name gets much more complex than just D_name.iso, the built in language will start to fail a bit.  as i said i like the regex solution but it's good to show a few ways of doing it IMO

Logged

jacobacci

  • Galactic Citizen
  • ****
  • Posts: 256
Re: Tag manipulation with expression language
« Reply #5 on: August 26, 2015, 05:27:57 am »

Hi guys,
I'm very sorry I didn't answer before, but somehow my new post notification seems to have been turned off.
Thanks a lot for your answers. It is much clearer to me no how JRiver expressions can be used. I am used to work with selecting a group of files from a smarlist or other selection method. Realizing that I can enter the expressions into the "alt-enter" tag fields is the key insight from your hints - that's where I was stuck.
I will try the JRiver expression method and let you know how it went.
BTW what I want to achieve is the following for all the album tags in the given selection of files:
D_The_Great_File_1 should be changed to DSD_The_Great_File_1
DSD_The_Great_File_2 should not be modified.
Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: Tag manipulation with expression language
« Reply #6 on: August 26, 2015, 09:54:25 am »

are the files named consistently?

so, are they ALL D_album1_1, D_album1_2, D_album2_1, D_album2_2.........

is there ever more than 2 (D_album1_3)?  is the last character in the album name ALWAYS a number?

the expression engine (regex or MC) will need a pattern to match!  so we need to know where the pattern stops to be able to change one but leave another...

Code: [Select]
ifelse(isequal(right([Album],1),1,5),[Album],isequal(left([Album],2),d_,1),replace([album],D_,DSD_))),[Album]
i haven't test the above, but in theory it should start by testing for a number great than 1 as the LAST character in the album name, and if so it ignores it.  if it is 1, it should then move on to replace the D_ with DSD_
i'll try to test it when i have time but in the meantime, you need to let us know how the albums are actually named.

edit:  thanks blgentry, figured you'd have it quick
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Tag manipulation with expression language
« Reply #7 on: August 26, 2015, 10:02:56 am »

BTW what I want to achieve is the following for all the album tags in the given selection of files:
D_The_Great_File_1 should be changed to DSD_The_Great_File_1
DSD_The_Great_File_2 should not be modified.

If you just want to change the album tags like that, you can use my expression with a tiny modification:

Code: [Select]
=if(compare(regex([Album], /#^D_(.+)$#/,0,0), =,1), DSD_[R1], [Album])
You keep mentioning file names, and they are sometimes important.  Do you want to change the [Album] tag, the actual filename on disk or both?

Brian.
Logged

dtc

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3125
Re: Tag manipulation with expression language
« Reply #8 on: August 26, 2015, 10:14:33 am »

You can just start with a compare of the first 2 characters of the album name to D_, as ferday did in his expression. That would eliminate any problems with D_ occurring later in the album name. If you are looking at the filename, you can look for \D_.

Regex is a powerful tool, but as the old expression goes it is "indistinguishable from line noise".
Logged

jacobacci

  • Galactic Citizen
  • ****
  • Posts: 256
Re: Tag manipulation with expression language
« Reply #9 on: August 26, 2015, 12:23:29 pm »

Sorry if I was not clear. Let me try again.

I have converted all my SACD ISOs to FLAC files. All the original SACD ISOs have an album tag of D_this_is_a_great_album (Abbey Road or whatever)
After the conversion all the resulting FLAC files have the same album tag as the original SACD ISO, namely D_this_is_a_great_album.
I then want to change the album tags of the FLAC files to DSD_this_is_a_great_album. Filenames etc. should not be changed.
When I convert more SACD ISOs in the future they will have album tags of D_this_is_a_great_album. Now I want to run the album name change expression on the directory with all the converted FLAC files.
All files that have an album tag of DSD_this_is_a_great_album should not be changed (they have had their DS added in front of the album name before). All files that have an album tag of D_this_is_a_great_album should have a DS added in front of the album name.

I think I see how ferday's expression works. It checks the first two characters of the album name. If they are D_ it adds DS in front. If they are not D_ it does nothing.

However when I selected a few files and pasted ferday's expression into the "alt enter" album field, the album tag seems to have been populated with the expression. It does not look like the expression did its work on the files.

Sorry if I am being difficult.


Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: Tag manipulation with expression language
« Reply #10 on: August 26, 2015, 12:25:53 pm »

Where did you paste it?  Into a field or a column?

I still haven't tested my second one but my first one tested fine...its probably the = try

Code: [Select]
=if(isequal(left([Album],2),d_,1),replace([album],D_,DS-),[Album])
Logged

jacobacci

  • Galactic Citizen
  • ****
  • Posts: 256
Re: Tag manipulation with expression language
« Reply #11 on: August 26, 2015, 04:01:02 pm »

@ferday,
pasting the expression with the = into the "alt enter" album field did the trick.
The expression I ended up using was
=if(isequal(left([Album],2),D_,1),replace([album],D_,DSD_),[Album])
This did exactly what I had intended.
Thanks a lot to everyone for their help. You guys shortened my learning curve by days.
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Tag manipulation with expression language
« Reply #12 on: August 26, 2015, 09:21:14 pm »

Happy to hear it worked out for you.  ...and +1 to our man Ferday for the expression that both worked AND was easy enough to understand for a new user!

I've heard Perl described as line noise before but not regex.  Not that I *deny* it.  :)  I just like it because once you know it, it works for so many different things.  Regex literally does the job of something like 4 or 5 different functions in the Expression Language.  Perhaps more...

Brian.
Logged

dtc

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3125
Re: Tag manipulation with expression language
« Reply #13 on: August 27, 2015, 06:37:53 am »

I believe the replace function replaces all instances of D_ with DSD_. Since there is an off chance that D_ may occur in the rest of the string, another option is to add DS to the beginning of the string, by adding DS to [Album]. In MC there is no concatenate function, so you just add the letters.

=if(isequal(left([Album],2),D_,1),DS[Album],[Album])

In this case, replace would probably work fine. I just wanted to add another option.
Logged

jacobacci

  • Galactic Citizen
  • ****
  • Posts: 256
Re: Tag manipulation with expression language
« Reply #14 on: September 01, 2015, 02:51:39 pm »

Thanks a lot. I'll be an expert before long
 :)
Logged
Pages: [1]   Go Up