Match function not (quite) working?

Support for Windows users
Post Reply
DavidRTurner
Power User
Posts: 85
Joined: 01 Feb 2014, 16:59

Match function not (quite) working?

Post by DavidRTurner »

Sorry to bug you, red, but this one's got me stumped.
I'm trying to combine several code snippets into one, but what I want to do, is not passing a boolean check.

Basically:
IF the source filename contains a S00E00(letter), then skip the formatting process altogether (i.e. keep the S00E00(letter) as it is - I've added a letter for my own reasons & want to skip this file).
ELSE
do the formatting for S00E00 and TITLE* - (the 'xxxx' is simply there to show if the boolean check works or not... and so far, I've not been able to display it).

This is what I THINK it should be, but it's not passing the first Elvis operator:

Code: Select all

{(fn.match(/(?i)(\bS\d{2}E\d{2}[a-zA-Z])\b/)) ? (fn.match(/(?i)(\bS\d{2}E\d{2}[a-zA-Z])\b/)) : 'xxxx'+
	{(allOf{s00e00}{'S'+season.pad(2)+'E'+special.pad(3)}.join(' - '))}
	{if(s00e00.contains('-'))  {(FORMAT(t)).replaceAll(/[(]([0-9]+)[)]/, {group, match -> ' (Part'+match.pad(1)+')' }).take(80)} else 
		{(FORMAT(localize.english.title)).replaceAll(/[(]([0-9]+)[)]/, {group, match -> ' (Part'+match.pad(1)+')' }).take(80)}
	}
}
If a sample file has a S00E00(letter) in it, the code works fine, it retains that match, then skips the rest - and continues with the remaining code in my full format.
But if it's a regular episode, it does not do the 2nd part of the Elvis check; it just exits the function.

*since 4.7, I've had to separate (t) from (localize.english.title), but up to now, that's worked fine - no issue with using both.
The FORMAT code (elsewhere in my format) works fine, and each line snippet here works on its own.
It's just when combining them into one IF/THEN section that it fails.

I figure I'm not using the match function correctly, but I can't find anything online to help me with it - I've tried various alternatives (contains, find...) but can't find anything that seems to work.

Thanks for any direction on this one...


**P.S. I've somehow managed to kill what code I had to pad the Specials episodes to 3 digits - not sure if I've missed something here from previous code. Any thoughts?
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Match function not (quite) working?

Post by rednoah »

1.
I'd try something like this:

Code: Select all

{any{fn.match(/S\d{2}E\d{2}\p{L}/)}{s00e00 + ' - ' + t}}
Test Data:

Code: Select all

Alias S01E01a.mp4
Alias S01E02.mp4
String.match(regex) throws an Exception when it can't find a match:
viewtopic.php?f=5&t=1895

e.g.

Code: Select all

{'X'.match('Y'); return 'This code is never reached.'}

2.
There's a built-in helper for dealing with trailing parentheses:

Code: Select all

{'Hello (1)'.replaceTrailingBrackets()}

3.
If you make a Preset with a predefined Input Folder, then you can also specify an Includes filter that prevents certain files from being loaded into FileBot altogether:

Code: Select all

!(fn =~ /S\d{2}E\d{2}\p{L}/)
:idea: Please read the FAQ and How to Request Help.
DavidRTurner
Power User
Posts: 85
Joined: 01 Feb 2014, 16:59

Re: Match function not (quite) working?

Post by DavidRTurner »

rednoah wrote:1.
I'd try something like this:

Code: Select all

{any{fn.match(/S\d{2}E\d{2}\p{L}/)}{s00e00 + ' - ' + t}}
I knew I was missing something... the 'any' part has done the trick!
3.
If you make a Preset with a predefined Input Folder, then you can also specify an Includes filter that prevents certain files from being loaded into FileBot altogether:

Code: Select all

!(fn =~ /S\d{2}E\d{2}\p{L}/)
Hmmm... I'll try that.

Thanks again!
Post Reply