INTERACT FORUM

Please login or register.

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

Author Topic: [How To?] Use Expression Language with Rename [F6]  (Read 3411 times)

astromo

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2251
[How To?] Use Expression Language with Rename [F6]
« on: November 07, 2015, 06:10:22 pm »

I'm struggling with getting a handle on how to employ expression language to assist with some renaming jobs. I'd like to set up a renaming rule to help streamline the process and help save me some time.

I've done some forum searches and have looked here:
http://wiki.jriver.com/index.php/Expression_Language
and I can work out that I need to put ifelse, isequal, Left & RemoveLeft to work but I'm just getting a little lost along the way.

Here's some pseudo-code to explain the intent:
Code: [Select]
ifelse
1st 7 characters of [Name]="Movie: "  (quotes are used here to highlight that there's a space after the colon)
then
make [Media Sub Type]=Movie
elseif
1st 7 characters of [Name]="Movie: "  (quotes are used here to highlight that there's a space after the colon)
then
Remove 1st 7 characters of [Name] and make [Name] = remaining text
elseif
[Media Sub Type]=Movie
then
make [Filename (name)]=[Name] ([Year])
elseif
[Media Sub Type]=TV Show
then
make [Filename (name)]=[Series] S[Season]E[Episode] [Name]

I'm assuming that I can apply the rule to the Filename rule box within Rename, Move & Copy Files [F6] and that it's permissible to manipulate non-filename attributes at the same time. I'm not manipulating file paths to keep things simple, although that may come later.

Thanks in advance to whoever can help me go from this  ?  to this   :)
Logged
MC33, Win10 x64, HD-Plex H5 Gen2 Case, HD-Plex 400W Hi-Fi DC-ATX / AC-DC PSU, Gigabyte Z370 ULTRA Gaming 2.0 MoBo, Intel Core i7 8700 CPU, 4x8GB GSkill DDR4 RAM, Schiit Modi Multibit DAC, Freya Pre, Nelson Pass Aleph J DIY Clone, Ascension Timberwolf 8893BSRTL Speakers, BJC 5T00UP cables, DVB-T Tuner HDHR5-4DT

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: [How To?] Use Expression Language with Rename [F6]
« Reply #1 on: November 07, 2015, 06:33:29 pm »

This seems pretty straight forward to me.  I would do it in several passes.  The first two, I would just a search to find the files that match.  Then use an expression to change what you want.  Specifically:

1.  Type into the search box:
Code: [Select]
[Name]=[Movie: "That should find everything that matches your criteria.
2.  In the results, highlight everything.  Then open the tagging pane and change the [Media SubType] field to Movie.
3.  Now, with the same stuff still highlighted, change the [Name] field to make it the way you want.  If you want to remove the first 7 characters, you can use this expression:
Code: [Select]
=removeleft([Name],7)Just type (or cut and paste) that expression into the [Name] field in the tagging pane and it will change them all.  Here's the reference for the removeleft() function:

http://wiki.jriver.com/index.php/Expression_Language#RemoveLeft.28.E2.80.A6.29:_Trims_characters_from_the_beginning_of_a_string

Now you can do your renames using the rename, move, and copy tool.  Just do a search for [Media Subtype]=Movie, then select all and do your rename.  Use the "Filename" section of the RM&C tool, and just type in the expression you want to use.  The one you showed in your psuedo code seems very straightforward.

Do a similar process for your TV Shows.  Search for the media subtype.  Then highlight all, and use the Rename, Move, and Copy tool with your expression for the filename of those files.

Some basic cautions and disclaimers:

1.  I have not tested any of the above expressions.  You should test them and be cautious.
2.  Please make a database backup before you start!  File > Library > Back up library
3.  These types of things should be tested on one or a few files to start, and then on larger batches.  UNDO is your friend.  Try to undo as soon as possible if you make a mistake or have unexpected results.
4.  Read the docs on the RM&C tool:

http://wiki.jriver.com/index.php/Rename,_Move,_and_Copy_Files

It's one of the most useful and powerful tools in MC and you'll do well to understand how it works, so you can use it wisely.

5.  ALWAYS, always, use the preview pane in the RM&C tool!  This lets you validate what the tool is going to do BEFORE you press OK to do it.  This will save you tons of grief and will probably save you a lot of work.  It has saved me from many, many, many mistakes, by showing me that I was not going to get what I was expecting.  This allowed me to modify my rules and get what I wanted instead.

6.  Take things one step at a time.  You'll get there.

Ask here if you need more help.  Good luck!

Brian.
Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: [How To?] Use Expression Language with Rename [F6]
« Reply #2 on: November 07, 2015, 10:28:19 pm »


In the filename box try

Ifelse(isequal([media sub type],TV Show,1),[series] S[season] E[episode] [name],isequal([media sub type],Movie,1),replace([name],Movie: )[year])

No testing but that should be close ish.  You can't really change the media type and search for the media type in the same expression so you'll need to do all that before hand...or make another RMC rule based on that
Logged

astromo

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2251
Re: [How To?] Use Expression Language with Rename [F6]
« Reply #3 on: November 07, 2015, 11:46:43 pm »

Thanks to both.

I'll give this a go.

I was hoping to ultimately hoping to kill a number of birds with the one stone but I was mindful that I might be asking too much.

Regardless this will help with the learning process.

Cheers.
Logged
MC33, Win10 x64, HD-Plex H5 Gen2 Case, HD-Plex 400W Hi-Fi DC-ATX / AC-DC PSU, Gigabyte Z370 ULTRA Gaming 2.0 MoBo, Intel Core i7 8700 CPU, 4x8GB GSkill DDR4 RAM, Schiit Modi Multibit DAC, Freya Pre, Nelson Pass Aleph J DIY Clone, Ascension Timberwolf 8893BSRTL Speakers, BJC 5T00UP cables, DVB-T Tuner HDHR5-4DT

astromo

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2251
Re: [How To?] Use Expression Language with Rename [F6]
« Reply #4 on: December 13, 2015, 01:29:33 am »

Just so I don't struggle trying to work this out next time, I thought I'd throw this one up here for safe keeping.

I was looking to organise files using [F6] Rename, Move & Copy Files with the following folder structure for photos:
Code: [Select]
F:\Camera\
F:\Camera\2012\
F:\Camera\2012\11 November\
F:\Camera\2012\12 December\
F:\Camera\2013\
F:\Camera\2013\01 January\
F:\Camera\2013\02 February\
F:\Camera\2013\03 March\
F:\Camera\2013\04 April\
F:\Camera\2013\05 May\

I couldn't find easily from searching where extracting the month as a number and using it in a rule is detailed. I did find this old post:
http://yabb.jriver.com/interact/index.php?topic=57562.0
but it looks to hack what should be readily available from the product as delivered.

I ran the following rule using [F6] with the Directories sectioned checked and the following rule detail:
Code: [Select]
Base Path:  F:\Camera\
Rule:       [Year]\FormatDate(MM) FormatDate(MMMM)\
I forget where I found the guidance for this or how I worked it out. If the above is repitition then that's not the end of the world.

The above lets me move or copy files dumped into a single directory with complete date meta-data into folders organised by year and month so that they sort sensibly using file explorer (be it MC or other).
Logged
MC33, Win10 x64, HD-Plex H5 Gen2 Case, HD-Plex 400W Hi-Fi DC-ATX / AC-DC PSU, Gigabyte Z370 ULTRA Gaming 2.0 MoBo, Intel Core i7 8700 CPU, 4x8GB GSkill DDR4 RAM, Schiit Modi Multibit DAC, Freya Pre, Nelson Pass Aleph J DIY Clone, Ascension Timberwolf 8893BSRTL Speakers, BJC 5T00UP cables, DVB-T Tuner HDHR5-4DT
Pages: [1]   Go Up