Pad episode number to 3 digits when at or over 100 episodes in a season

All about user-defined episode / movie / file name format expressions
Post Reply
bassmadrigal
Posts: 10
Joined: 04 Jun 2015, 13:13

Pad episode number to 3 digits when at or over 100 episodes in a season

Post by bassmadrigal »

I am looking to make it that when I have a show that has over 100 episodes in a season that the entire season has 3 digits for the episode number. This ensures that no matter the sort method of filesystems or applications, the episodes will show up in order.

I know I can manually do this replacing

Groovy: Select all

{S00E00}
with something like

Groovy: Select all

S{s.pad(2)}E{e.pad(3)}
However, I was hoping to do a "set it and forget it" type of thing, so I tried researching and came up with

Groovy: Select all

{{episodelist.count{ it.episode && it.season == s }} >= 100 ? S{s.pad(2)}E{e.pad(3)} : {S00E00}}
But I get an "Unexpected input" error with the letter "E" for the pad (no clue why since it works without the if/then/else portion when I simply replace the {S00E00} portion -- I tried it with and without quotes) and if I remove the letters (for testing), I get the following error:

Console Output: Select all

Expression yields empty value: No signature of method: net.filebot.GroovyEngine.S() is applicable for argument types: (__script_819cc574498608c7564eef8ee3b38da7_2a$_run_closure1, __script_819cc574498608c7564eef8ee3b38da7_2a$_run_closure2) values: [__script_819cc574498608c7564eef8ee3b38da7_2a$_run_closure1@571c6ed3, ...]
Possible solutions: any(), is(java.lang.Object), wait(), dump(), find(), grep()
I'm not very knowledgeable with groovy scripting, but have learned enough to believe this is possible... I'm just not seeing it. Any suggestions?
User avatar
rednoah
The Source
Posts: 22999
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Pad episode number to 3 digits when at or over 100 episodes in a season

Post by rednoah »

:!: Note that {episodelist} was changed with FileBot 5.1.0 (currently in beta) and may break-backwards compatibility:
viewtopic.php?t=1609


:arrow: If you're using FileBot 5.1.0 or higher, then this should work:

Format: Select all

{ episodelist.findAll{ s == it.s }.e.max() < 100 ? s00e00 : "S${s.pad(2)}E${e.pad(3)}" }
:arrow: If you're using FileBot 5.0.3 or lower, then this should work:

Format: Select all

{ episodelist.findAll{ s == it.season }.episode.max() < 100 ? s00e00 : "S${s.pad(2)}E${e.pad(3)}" }
** NOTE: this format does not support multi-episodes, special episodes, etc
:idea: Please read the FAQ and How to Request Help.
bassmadrigal
Posts: 10
Joined: 04 Jun 2015, 13:13

Re: Pad episode number to 3 digits when at or over 100 episodes in a season

Post by bassmadrigal »

Sweet! Thank you!

Turns out I was running a 5.1.0 beta from before the change, so I was confused at first until I tried the older one. That worked. Then I updated to the latest beta and the newer one worked.

I'm guessing my issue with the error about the "E" was due to not having the padding have the dollar sign before it?

Thanks again!
User avatar
rednoah
The Source
Posts: 22999
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Pad episode number to 3 digits when at or over 100 episodes in a season

Post by rednoah »

Your Groovy code was just syntactically incorrect. Your code suggests that you assume all {...} have the same meaning. That is a misconception. The outermost {...} delimit Groovy code, and anything inside is just Groovy code, which happens to also use {...} for code blocks and closures, so outermost {...} (Format code) and inner {...} (Groovy code) are completely different in meaning:
viewtopic.php?t=10824




e.g. this format code with 2 static text sections and 2 dynamic Groovy code sections:

Format: Select all

S{ s.pad(2) }E{ e.pad(3) }
:idea: s.pad(2) is a Groovy script. e.pad(3) is another Groovy script.




e.g. this is format code with 1 dynamic Groovy code section:

Format: Select all

{ 'S' + s.pad(2) + 'E' + e.pad(3) }

Format: Select all

{ "S${s.pad(2)}E${e.pad(3)}" }
:idea: "${variable}" is just Groovy code: String interpolation

Format: Select all

{
	def hello() {
		return "Hello"
	}
	hello()
}
:idea: def hello() { ... } is just Groovy code: Methods
:idea: Please read the FAQ and How to Request Help.
Post Reply