Page 1 of 1
Identify files with no subtitles
Posted: 11 Sep 2020, 04:36
by ca81
Hi,
Going through various posts in the forum and some Q&A, I have put together the below code:
Code: Select all
({text.size() >=1 ?
{text.take(2).collect
{ a -> allOf
{ any{a.Language_String3.upper()} {'XSX'} }
{ a.Format.replace('-':'') }
}*.joining('-').join(', ')
}: 'No Subs'})
My intention from this piece of code is for it to display,
- info about only the first two subtitles,
- No subs when there are no subtitles and
- XSX when the language of the subtitle is not defined
the above code works fine as long there are 1 or more subtitles but if the media file does not have subtitles then I don't get
No subs as the output

.
Any help is greatly appreciated...
thanks,
~kg
Re: Identify files with no subtitles
Posted: 11 Sep 2020, 08:01
by rednoah
If you use
text on a file that does not contain any text streams, then the result will not be an empty list, but a binding error that unwinds the expression"
viewtopic.php?t=1895
So we use
any to catch that error and print something else instead:
Code: Select all
{
any{ text.take(2).collect{ a ->
allOf
{ any{ a.LanguageString3 }{ 'XSX' }.upper() }
{ a.Format.removeAll('-') }
.join('-')
}.join(', ')
}{ 'No Subtitles' }
}
Re: Identify files with no subtitles
Posted: 12 Sep 2020, 01:13
by ca81
rednoah wrote: ↑11 Sep 2020, 08:01
So we use
any to catch that error and print something else instead:
Code: Select all
{
any{ text.take(2).collect{ a ->
allOf
{ any{ a.LanguageString3 }{ 'XSX' }.upper() }
{ a.Format.removeAll('-') }
.join('-')
}.join(', ')
}{ 'No Subtitles' }
}
Thanks!!!, this works perfectly
rednoah wrote: ↑11 Sep 2020, 08:01
If you use
text on a file that does not contain any text streams, then the result will not be an empty list, but a binding error that unwinds the expression"
viewtopic.php?t=1895
I kinda realized the above when I was trying to resolve my issue and wrote the below piece of code.
Code: Select all
{{any{text.size} {0}} >=1 ?
{text.take(2).collect
{ a -> allOf
{ any{a.Language_String3.upper()} {'XSX'} }
{ a.Format.replace('-':'') }
}*.joining('-').join(', ')
}: 'No Subs'}
My code snippet above does not work as intended and just for my understanding/learning can someone please advise on what's wrong here?
I am using FileBot GUI and the format editor gives the following error with my code snippet above.
https://imgur.com/8OoUU64
...this again I am unable to understand due to my non-coding background
Please advise.
thanks,
~kg
ps: for some inexplicable reason when I put the error that I was getting in FileBot as a text in this response, I kept on getting an 'Internal Server Error' on the website each time I 'previewed' the response. So finally decided to make an image of the error text and post it's url
Re: Identify files with no subtitles
Posted: 12 Sep 2020, 02:34
by rednoah
The outer-most
{...} delimitate Groovy code. But Groovy itself uses
{...} for code blocks and closures, so inner
{...} have completely different semantics compared to the outer-most
{...}. Notably,
{...} is
not used to reference variables, it's used to delimitate Groovy code sections of arbitrary length. It just so happens that simple code like
vc is valid Groovy code, making
{vc} valid FileBot Format code.
e.g. Groovy code
Code: Select all
// assign "Integer 1" to variable x
def x = 1
// assign "Closure that returns Integer 1 when called" to variable y
def y = { 1 }
https://groovy-lang.org/closures.html