Page 1 of 1
Don't print "[null]" for non-existing metadata
Posted: 25 Oct 2022, 22:33
by cheaters

How can we
not print "null" when metadata doesn't exist? I looked through the forums but could not locate this info - although it's there somewhere from what I remember.
the relevant part of my format:
13 Hours - The Secret Soldiers of Benghazi (2016) {tmdb-300671} [ [null] [2h24m] 2.40∶1 (WS) 1080p BluRay x265 D0C3C9CC ].mp4
I want to use
audo.language because I get all of the languages not just the primary in my format.
"pseudo format"
Code: Select all
{' '+audio.language.empty().replace('[null]','' )}
it seems in the below binding case it's automatic
even the parentheses are not printed if the "ws" metadata item doesn't exist:
my complete format for reference
Code: Select all
{ plex.id.derive { ' {edition-'+tags.toString().replace('[','').replace(']','')+'}' }
{' ['}
{ if ('Documentary' in genres)' [doc]' }
{' '+audio.language}
{' ['}
{ info:video[0].durationString.space(' ').replace(' ','').replace('min','m')+'] ' }
{ info:video[0].displayAspectRatioString.colon(':').replace(':', '"∶"') }
{' ('+ws+')'}
{' '+vf}
{' '+vs}
{' '+vc}
{' '+crc32}
{' ]'}
{ dc > 1 ? '.' + di : null }
}
Re: Don't print "[null]" for non-existing metadata
Posted: 26 Oct 2022, 03:21
by rednoah
The
{audioLanguages} binding will take care of everything, null values, duplicate values, invalid language codes, fail-if-empty behaviour, etc:

If you want to write custom code, then you can remove an element from a list with the
- minus() operator like so:
Code: Select all
{
def x = [1, 2, null, 3]
x - null
}
e.g. remove
null values, thus print
[] empty list String representation:
Re: Don't print "[null]" for non-existing metadata
Posted: 26 Oct 2022, 13:47
by cheaters

To remove the
“[]” as well?
Code: Select all
{ ' ' + (audio.language - null).replace('[','').replace('[','') }
Is there a simpler form of the above?
Re: Don't print "[null]" for non-existing metadata
Posted: 27 Oct 2022, 02:55
by rednoah
Yes, the
{audioLanguages} binding will take care of everything, null values, duplicate values, invalid language codes, fail-if-empty behaviour, etc:

Do you perhaps have a reason for not just using the
{audioLanguages} binding? If so, please explain. If not, just use
{audioLanguages} then.