Page 1 of 1
Problem with non existing Tags
Posted: 29 Jun 2014, 09:47
by ErAzOr
Hi,
I'd like to read out all Audio Informations, which is working great with most of my files.
This is my scheme:
Code: Select all
{'.' + audios.groupBy{ it.Codec + '.' + it.Channels.replaceAll(/[' ']/, "-") + 'ch' }.collect{ c, a -> [c] + a*.Language }.flatten().join('.')}
The problem is, if files doesn't include the tag "Language", I get the error:
"BindingException: Language undefinied".
Is there a way to check, if specified Tag exists, if true, use this scheme, else: ignore?
Re: Problem with non existing Tags
Posted: 29 Jun 2014, 10:55
by rednoah
This is how I'd write that:
Code: Select all
{audios.collect{ a -> allOf{[a.codec, a.channels+'ch']}{a.Language} }.findAll{ it[1] }.groupBy{ it[0] }.collect{ k, v -> k + v*.get(1) }.flatten().join('.') }
If you use a binding that is undefined/null/etc it'll cause an Exception to be thrown. So you can catch that with simple try-catch blocks.
ExpressionFormatFunctions.java defines some simple helpers to keep the format short:
Re: Problem with non existing Tags
Posted: 29 Jun 2014, 11:12
by ErAzOr
Wow thank you very much! Works like charm
Re: Problem with non existing Tags
Posted: 29 Jun 2014, 12:03
by ErAzOr
rednoah wrote:This is how I'd write that:
Code: Select all
{audios.collect{ a -> allOf{[a.codec, a.channels+'ch']}{a.Language} }.findAll{ it[1] }.groupBy{ it[0] }.collect{ k, v -> k + v*.get(1) }.flatten().join('.') }
If you use a binding that is undefined/null/etc it'll cause an Exception to be thrown. So you can catch that with simple try-catch blocks.
ExpressionFormatFunctions.java defines some simple helpers to keep the format short:
one more thing: is it possible to extend this by checking if "CodecIDHint" is available? If true, group by CodecIDHint. Else group by "Codec".
Re: Problem with non existing Tags
Posted: 29 Jun 2014, 14:42
by rednoah
Re: Problem with non existing Tags
Posted: 29 Jun 2014, 15:22
by ErAzOr
I tried this:
Code: Select all
{audios.collect{ a -> allOf{any{a.CodecIDHint}{a.Codec}}{a.Language} }.findAll{ it[1] }.groupBy{ it[0] }.collect{ k, v -> k + v*.get(1) }.flatten().join('.') }
but get no value (just blank).
I also tried:
Code: Select all
{audios.collect{ a -> allOf{[{if (a.CodecIDHint != null) return a.CodecIDHint else return a.Codec}, a.channels+'ch']}{a.Language} }.findAll{ it[1] }.groupBy{ it[0] }.collect{ k, v -> k + v*.get(1) }.flatten().join('.') }
but the result is the same
Re: Problem with non existing Tags
Posted: 29 Jun 2014, 15:37
by rednoah
You broke the expression. Here I fixed it:
Code: Select all
{audios.collect{ a -> allOf{[any{a.CodecIDHint}{a.Codec}, a.Channels+'ch']}{a.Language} }.findAll{ it[1] }.groupBy{ it[0] }.collect{ k, v -> k + v*.get(1) }.flatten().join('.') }
See how the groupBy key is a Array of Codec/Channels.
Re: Problem with non existing Tags
Posted: 29 Jun 2014, 15:58
by ErAzOr
rednoah wrote:You broke the expression. Here I fixed it:
Code: Select all
{audios.collect{ a -> allOf{[any{a.CodecIDHint}{a.Codec}, a.Channels+'ch']}{a.Language} }.findAll{ it[1] }.groupBy{ it[0] }.collect{ k, v -> k + v*.get(1) }.flatten().join('.') }
See how the groupBy key is a Array of Codec/Channels.
That's it. Thank you
Re: Problem with non existing Tags
Posted: 28 Apr 2016, 14:01
by ricobelo
rednoah wrote:This is how I'd write that:
Code: Select all
{audios.collect{ a -> allOf{[a.codec, a.channels+'ch']}{a.Language} }.findAll{ it[1] }.groupBy{ it[0] }.collect{ k, v -> k + v*.get(1) }.flatten().join('.') }
If you use a binding that is undefined/null/etc it'll cause an Exception to be thrown. So you can catch that with simple try-catch blocks.
ExpressionFormatFunctions.java defines some simple helpers to keep the format short:
Note that since version 4.6.2 , c{ c1 } is replaced by call{ c1 }