EDIT - I seem to have resolved this (a few hours later) by using a tilde instead of a curly bracket for each side of the string; and using indexOf and lastIndexOf to distinguish them.
This is a workaround, not a solution, though.
My need here, was to use a character (or sequence of characters, which could be even more confusing) that's not likely to be part of a legitimate show/episode name.
But while the curly brackets would WORK in the GET of the subtring, I was unable to find any way to check if they exist first - i.e. "if special string with curlies, then return what's between them, else do other things".
As a special character, it had to be escaped first, but everything I tried (& found online) failed to work in Groovy.
So - all is good now with the format, even though I'd still like to find out why I couldn't escape the curlies...
ORIGINAL POST -
OK, I thought I had everything working correctly, but I've found a glitch & could use some help, as my research comes up empty.
I use a (personal choice) convention to manually add notes to some filenames, to indicate that they are related to an episode in the season, but are not database-relevant.
That is; when some shows do crossover episodes, they relate to each other, but are not (all) listed in each show's database.
For example, Chicago PD S02E07 was part 3 of a 3-show crossover among the 3 related Chicago shows - Chicago Fire was part 1, Law & Order: SVU was part 2, and Chicago PD was part 3.
I will get the 'other' episodes, so I can watch the whole storyline, and keep them in the same folder as the Chicago PD episode.
I will get the properly-formatted name for all 3, then (MANUALLY) insert the Chicago PD episode SxxExx reference to the other 2, so that they all sort alphabetically.
To show that there's something odd here, I add an a/b/c... to the SxxExx number.
I also add a '{' and '}' to the 'other' show's info, and keep a regex in the format to 'keep' that substring intact if the collection is later renamed.
i.e.
Chicago P.D. S02E07a - S02E07 (2014, US, NBC, TheTVDB, #269641) -- They'll Have to Go Through Me (Part 3) {Chicago Fire S03E07 - Nobody Touches Anything [2014-11-11]} [2014-11-12] [Crime, Drama]
What I use is this snippet:
Code: Select all
{fn.getAt((fn.indexOf('{'))..(fn.indexOf('}')))}
It finds the index of each of the curly brackets, and 'gets' the substring between them to carry to the new filename.
Problem1 is: using
GetAt(, I find I get a trailing character (often a ']', but sometimes a letter (I do not know where it comes from!) at the end of the results line of episodes that do NOT have this curly-bracket string in the filename.
Problem2 is: using
Get( eliminates the trailing character, but fails to keep the substring, so I have to switch to
GetAt whenever I cross these special episodes.
This
Getxx( is the only function I've found that can do this, but there must be another way that covers both scenarios.