Not to put [720p, ]

All about user-defined episode / movie format expressions
Post Reply
Ambroisie
Supporter
Posts: 19
Joined: 06 Dec 2013, 22:08

Not to put [720p, ]

Post by Ambroisie »

Hi, when I use this naming scheme,
E:/Video/Films/{"$collection/"}{n} ({y}){ [{"${fn.match(/3D/)}, "}{"${cf}, "}{"${hpi}, "}{"${vc}, "}{"${ac}"}]}
Which outputs :
E:\Video\Films\Avatar Collection\Avatar (2009) [3D, mkv, 720p, x264, ac3].mkv
Imagine I could only have the hpi variable, it would write [720p, ] at the end, and I would like it to write only [720p] (of course it would not hapened, but if I wanted to change my scheme, I wanted to know how-to do it)
User avatar
rednoah
The Source
Posts: 19133
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Not to put [720p, ]

Post by rednoah »

It's sort of tricky... it's easy if you put hpi/vc/ac into the same {...} block and then either you get all values or none.


But here's a solution to what you want, it's a bit complicated but you can do it like this:

Code: Select all

{def m = []; c{m+=hpi}; c{m+=vc}; c{m+=ac}; m.join(', ')}
:idea: Please read the FAQ and How to Request Help.
Ambroisie
Supporter
Posts: 19
Joined: 06 Dec 2013, 22:08

Re: Not to put [720p, ]

Post by Ambroisie »

Ok thanks. Could you explain it (if it's not too difficult), I learn more easily if I understand what I write.

Edit: Filebot says "Syntax error: Unexpected node type: Closure_List found when expecting type: ELIST at line: 1 column 2 File: Script38.groovy
Last edited by Ambroisie on 07 Dec 2013, 11:35, edited 1 time in total.
User avatar
rednoah
The Source
Posts: 19133
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Not to put [720p, ]

Post by rednoah »

The main issue you have all these variables, when used, cause an exception to be thrown if they're undefined (which makes the whole {...} block break). That's intentional for make expressions short and handle undefined issues automatically.

We just make a list of the values, and we wrap each binding with an try/catch so it can't throw exceptions to break the block.

The c{...} is really just an empty try/catch block:

Code: Select all

/**
 * General helpers and utilities
 */
def c(c) {
	try {
		return c.call()
	} catch (Throwable e) {
		return null
	}
}
Other than that it's just adding items to a collection.
:idea: Please read the FAQ and How to Request Help.
Ambroisie
Supporter
Posts: 19
Joined: 06 Dec 2013, 22:08

Re: Not to put [720p, ]

Post by Ambroisie »

Ok thanks, you can answer really quickly.
User avatar
rednoah
The Source
Posts: 19133
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Not to put [720p, ]

Post by rednoah »

Ambroisie wrote:I looked at the format expression you gave me, and I modified it like this

Code: Select all

E:/Video/Films/{"$collection/"}{n} ({y}) { [{"${fn.match(/3D/)}, "}{"${cf}, "}{"${hpi}, "}{"${vc}, "}{"${ac}"}]}
And the original version

Code: Select all

E:/Video/Films/{"$collection/"}{n} ({y}) {[def m = []; c{m+=fn.match(/3D/)}; c{m+=hpi}; c{m+=vc}; c{m+=ac}; m.join(', ')]}
And if I type them on filebot it writes
Filebot wrote:Syntax error: Unexpected node type: Closure_List found when expecting type: ELIST at line: 1 column 2 File: Script38.groovy
Why does it write this ? Thanks for your support.

This is not what I wrote. You can't just add [...] randomly in the code. Learn Groovy and you'll know why.

This works:

Code: Select all

{def m = []; c{m+=fn.match(/3D/)}; c{m+=hpi}; c{m+=vc}; c{m+=ac}; m.join(', ')}
This also works:

Code: Select all

[{def m = []; c{m+=fn.match(/3D/)}; c{m+=hpi}; c{m+=vc}; c{m+=ac}; m.join(', ')}]
And if you're worry about empty [] you can do:

Code: Select all

{def m = []; c{m+=fn.match(/3D/)}; c{m+=hpi}; c{m+=vc}; c{m+=ac}; if (m) '['+m.join(', ')+']'}
:idea: Please read the FAQ and How to Request Help.
Ambroisie
Supporter
Posts: 19
Joined: 06 Dec 2013, 22:08

Re: Not to put [720p, ]

Post by Ambroisie »

Ok thanks for your support. I don't think I will learn groovy, but now I have something which suits me and won't change until a good time.
Post Reply