INTERACT FORUM

Please login or register.

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

Author Topic: Expression help? Padding and limiting  (Read 1934 times)

darichman

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1363
Expression help? Padding and limiting
« on: January 27, 2012, 08:47:37 am »

I think I might need to bite the bullet and learn RegEx :o

I'm working on a rename expression for TV series, and I'm stuck trying to work out a way to handle video files with multiple episodes.

[Series]=Lost
[Season]=6
[Episode]=1-2   (ie double episode)
[Name]=Episode Name  (can't remember)

I'd like an output of Lost - s06e01-e02 - Episode Name.mkv
  (ie individual episodes padded out to 2 digits each and separated by a hyphen and an e-)

MC pads out Season and normal Episode numbers to 2 digits, which is nice.

In this case, I'm having trouble:
  - splitting the '1' and the '2' to put a '-e' between them
  - turning the '1' into '01' and the '2' into '02'

I did some pottering with the Pad and Mid(...) functions but got lost because I was trying to refer to an element within the expression and not a field itself...

If any kind souls have a solution I'd be very happy :)
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression help? Padding and limiting
« Reply #1 on: January 27, 2012, 11:09:24 am »

You can use ListItem(), but it is more cumbersome since ListItem() doesn't manage degenerate list cases well (eg. single item lists).

RegEx([Episode], /#^(\d+)(?:-(\d+))?$#/, -1)[Series] - sPadNumber([Season],2) ePadNumber([R1],2)IfElse(!isempty([R2]),-ePadNumber([R2],2)) - [Name]

The above runs the RegEx() to capture the 1 or 2 episode numbers, and outputs the string as you want.  It has to test for a possible empty second series value to skip outputting a useless dash after the first episode.

Edit: added missing optional quantifier ?
Logged
The opinions I express represent my own folly.

darichman

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1363
Re: Expression help? Padding and limiting
« Reply #2 on: January 27, 2012, 05:39:42 pm »

Thanks MrC!

The above runs the RegEx() to capture the 1 or 2 episode numbers, and outputs the string as you want.  It has to test for a possible empty second series value to skip outputting a useless dash after the first episode.

It is working perfectly on files with multiple episodes separated by a hyphen.
When I run the expression above, however, if [Episode] only contains 1 digit (ie [Episode]=3) I get an output like
   Stargate Atlantis - s01 e00 - Hide and Seek

I know how to use MCs expression language to say 'if episode contains a hyphen do this, else do this' so I can do it that way, but is there a way with RegEx or have I fudged it up?


Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression help? Padding and limiting
« Reply #3 on: January 27, 2012, 06:14:30 pm »

Silly Me.  I forgot a ? in the pasted RE:

RegEx([Episode], /#^(\d+)(?:-(\d+))?$#/, -1)[Series] - sPadNumber([Season],2) ePadNumber([R1],2)IfElse(!isempty([R2]),-ePadNumber([R2],2)) - [Name]
Logged
The opinions I express represent my own folly.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression help? Padding and limiting
« Reply #4 on: January 27, 2012, 06:21:47 pm »

And here's the explanation of the RE portion:

  ^(\d+)(?:-(\d+))?$

^Match from beginning of string (your [Episode])
(\d+)match 1 or more digits, and remember them - capture 1
(?:start of a cloister group
(\d+)match 1 or more digits, and remember them - capture 2
)end of the cloister group
?The previous atom (here, the cloister group) is optional
$Match must now be at end of string
Logged
The opinions I express represent my own folly.

darichman

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1363
Re: Expression help? Padding and limiting
« Reply #5 on: January 27, 2012, 09:42:30 pm »

[Woops I'm sorry I directed my thanks to EpF and not MrC in my last post as I was reading a post on another thread. I'm a bit scatterbrained this morning! - post amended]

Thanks so much for that MrC. This works flawlessly.

I think I'm starting to wrap my head around the language a bit better. There's a lot of flexibility here with a bit of time investment!
MC has made some great steps with automating import, processing metadata and renaming and moving the files.

*Now moves on to music*

Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression help? Padding and limiting
« Reply #6 on: January 27, 2012, 10:08:14 pm »

[Woops I'm sorry I directed my thanks to EpF and not MrC in my last post as I was reading a post on another thread. I'm a bit scatterbrained this morning! - post amended]

Thanks so much for that MrC. This works flawlessly.

I think I'm starting to wrap my head around the language a bit better. There's a lot of flexibility here with a bit of time investment!
MC has made some great steps with automating import, processing metadata and renaming and moving the files.

*Now moves on to music*

No problem, heck I posted a response into the wrong thread today.

Glad to hear its working for you. Cheers.
Logged
The opinions I express represent my own folly.
Pages: [1]   Go Up