Page 1 of 1

Not to put [720p, ]

Posted: 06 Dec 2013, 22:32
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)

Re: Not to put [720p, ]

Posted: 07 Dec 2013, 06:52
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(', ')}

Re: Not to put [720p, ]

Posted: 07 Dec 2013, 11:20
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

Re: Not to put [720p, ]

Posted: 07 Dec 2013, 11:31
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.

Re: Not to put [720p, ]

Posted: 07 Dec 2013, 11:38
by Ambroisie
Ok thanks, you can answer really quickly.

Re: Not to put [720p, ]

Posted: 08 Dec 2013, 04:47
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(', ')+']'}

Re: Not to put [720p, ]

Posted: 08 Dec 2013, 10:08
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.