Problem with non existing Tags

All about user-defined episode / movie / file name format expressions
Post Reply
ErAzOr
Posts: 6
Joined: 29 Jun 2014, 09:39

Problem with non existing Tags

Post 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?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Problem with non existing Tags

Post 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:

Code: Select all

c{ c1 }

Code: Select all

any{ c1, c2, etc }

Code: Select all

allOf{ c1, c2, etc }
:idea: Please read the FAQ and How to Request Help.
ErAzOr
Posts: 6
Joined: 29 Jun 2014, 09:39

Re: Problem with non existing Tags

Post by ErAzOr »

Wow thank you very much! Works like charm :D
ErAzOr
Posts: 6
Joined: 29 Jun 2014, 09:39

Re: Problem with non existing Tags

Post 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:

Code: Select all

c{ c1 }

Code: Select all

any{ c1, c2, etc }

Code: Select all

allOf{ c1, c2, etc }

one more thing: is it possible to extend this by checking if "CodecIDHint" is available? If true, group by CodecIDHint. Else group by "Codec".
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Problem with non existing Tags

Post by rednoah »

Code: Select all

any{a.CodecIDHint}{a.Codec}
:idea: Please read the FAQ and How to Request Help.
ErAzOr
Posts: 6
Joined: 29 Jun 2014, 09:39

Re: Problem with non existing Tags

Post by ErAzOr »

rednoah wrote:

Code: Select all

any{a.CodecIDHint}{a.Codec}
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 :(
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Problem with non existing Tags

Post 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. :ugeek:
:idea: Please read the FAQ and How to Request Help.
ErAzOr
Posts: 6
Joined: 29 Jun 2014, 09:39

Re: Problem with non existing Tags

Post 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. :ugeek:
That's it. Thank you :D
ricobelo
Posts: 3
Joined: 14 Apr 2016, 16:42

Re: Problem with non existing Tags

Post 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:

Code: Select all

c{ c1 }

Code: Select all

any{ c1, c2, etc }

Code: Select all

allOf{ c1, c2, etc }
Note that since version 4.6.2 , c{ c1 } is replaced by call{ c1 }
Post Reply