Don't print "[null]" for non-existing metadata

Support for macOS users
Post Reply
cheaters
Posts: 214
Joined: 09 Oct 2016, 02:01

Don't print "[null]" for non-existing metadata

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

Code: Select all

{' '+audio.language} 
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:

Code: Select all

{' ('+ws+')'} 
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 }
}
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Don't print "[null]" for non-existing metadata

Post by rednoah »

The {audioLanguages} binding will take care of everything, null values, duplicate values, invalid language codes, fail-if-empty behaviour, etc:

Code: Select all

{ audioLanguages }


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

Code: Select all

{ ' ' + (audio.language - null) }
:idea: Please read the FAQ and How to Request Help.
cheaters
Posts: 214
Joined: 09 Oct 2016, 02:01

Re: Don't print "[null]" for non-existing metadata

Post by cheaters »

:?: To remove the “[]” as well?

Code: Select all

{ ' ' + (audio.language - null).replace('[','').replace('[','') }
Is there a simpler form of the above?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Don't print "[null]" for non-existing metadata

Post by rednoah »

Yes, the {audioLanguages} binding will take care of everything, null values, duplicate values, invalid language codes, fail-if-empty behaviour, etc:

Code: Select all

{ audioLanguages }

:?: Do you perhaps have a reason for not just using the {audioLanguages} binding? If so, please explain. If not, just use {audioLanguages} then.
:idea: Please read the FAQ and How to Request Help.
Post Reply