Expression Help - I can't seem to test for null or not exist.

All about user-defined episode / movie format expressions
Post Reply
HellPhantom
Posts: 35
Joined: 15 Apr 2020, 10:45

Expression Help - I can't seem to test for null or not exist.

Post by HellPhantom »

I have been stuck on this issue now for 2 days now.

Does not matter what I try I just can't figure this one out, please have pity on me.
I want to test when there is a subtitle or audio language and just get simple True or False.

When no subtitles or language exist my code just fails and does not execute my failed block, i want to do something when there is none.
I can't seem to successfully test for this. it does not seem to be null the var just seems to not exist or what ever @#$%#.
I have tried so many things and variables that I would be happy with something as simple as the below to just understand what to do.

Code: Select all

{answer = (audio.languages!=null && audio.languages.size() >0 ) ? 'Found' : 'Not found'}

Code: Select all

{answer = (text.languages!=null && text.languages.size() >0 ) ? 'Found' : 'Not found'}
Please save me from this syntax Hell.
User avatar
rednoah
The Source
Posts: 20461
Joined: 16 Nov 2011, 08:59

Re: Expression Help - I can't seem to test for null or not exist.

Post by rednoah »

e.g.

Code: Select all

{ 
	def x = any{ audio.language.size() > 0 }{ false }
}
:idea: Please read Learn how {expressions} work and useful Helper Functions for details.
:idea: Please read the FAQ and How to Request Help.
HellPhantom
Posts: 35
Joined: 15 Apr 2020, 10:45

Re: Expression Help - I can't seem to test for null or not exist.

Post by HellPhantom »

Ok, so I managed to convert your answer into the following.
I have removed a lot of unnecessary code to try and only solve the bit that I cannot fix.
Because of those xattr I am struggling to add this bit where I have to determine all the variable lengths items in my filename.
I have read and tried so much code but I can't bring this together.

This works just fine.

Code: Select all

{t.colon(' - ')
	.take(259-160-(primaryTitle.length()*2)
	)
}
when I un-comment any of the 2 following variants it does not work, it appears the result from the if is a string and not a number.

Code: Select all

{t.colon(' - ')
	.take(259-160-(primaryTitle.length()*2)

	//1.  Determine Audio languages indicator length
//		-({if (any{audio.language.size() > 0} {false})
//			{(audio.language.size() == 1 ? 6 : 
//			{(audio.language.size() == 2 ? 18 : 
//			{(audio.language.size() >10 ? 24 : 25)})})}
//			else {0}})

	//2. Determine Audio languages indicator length
//		- ({def x= {if (any{audio.language.size() > 0} {false})
//			{(audio.language.size() == 1 ? 6 : 
//			{(audio.language.size() == 2 ? 18 : 
//			{(audio.language.size() >10 ? 24 : 25)})})}
//			else {0}}})
	)
}
Individually this gives me the correct answer although it appears to be a string

Code: Select all

		//Determine Audio languages indicator length
		-({if (any{audio.language.size() > 0} {false})
			{(audio.language.size() == 1 ? 6 : 
			{(audio.language.size() == 2 ? 18 : 
			{(audio.language.size() >10 ? 24 : 25)})})}
			else {0}})
User avatar
rednoah
The Source
Posts: 20461
Joined: 16 Nov 2011, 08:59

Re: Expression Help - I can't seem to test for null or not exist.

Post by rednoah »

I guess you mean to write some sort of nested set of conditions like this:

Code: Select all

{
	def x = any{ audio.language.size() }{ 0 }
	def m = x >= 10 ? 24 :
	        x ==  2 ? 18 :
	        x ==  1 ?  6 : 0

}
:!: This is notably not the way to find out the length of a String value.


Checking the length of a String value, and then doing different things depending on the situation, would look like this:

Code: Select all

{
	def x = any{ audioLanguages as String }{ '' }
	// e.g. "[eng, jpn]" => 10
	x.length() < 25 ? x : '[many languages]'
}
:idea: Please read the FAQ and How to Request Help.
HellPhantom
Posts: 35
Joined: 15 Apr 2020, 10:45

Re: Expression Help - I can't seem to test for null or not exist.

Post by HellPhantom »

For the audio and subtitles I have a specific output and decided to not try to count the actual output but rather define certain lengths.
I would not even know how to count the length of the result of that expression and would probably have to duplicate that code to just count it.

My Possible outcomes and their lengths. I restrict them to only display 3 and cater for only 99 in my count + a similar set for subtitles
None or null = 0
.[eng] = 6
.[eng,afr].[Aud-2] = 18
.[eng, jpn, afr].[Aud-9] = 24
.[eng, jpn, afr].[Aud-10] = 25
HellPhantom
Posts: 35
Joined: 15 Apr 2020, 10:45

Re: Expression Help - I can't seem to test for null or not exist.

Post by HellPhantom »

The code for the language bit is long, and I am not covering everything in the length count.
I won't be able to count the length for this.
This xattr is making my life very difficult to get it to consistently work.
I don't know if there is maybe some 32bit dll or api on my windows 10 system interfering.
I am still trying to figure it out. when the path goes over 238+ the 21 chars for xattr it cannot write it period. not the system or folder method.

Code: Select all

{f.name.upper() =~/RIFFTRAX/?
	'.'+{def languages = [];
	any{audio.collect{ au -> languages << any{ au.'LanguageString3' }{'Unknown'}};
	'['+languages.unique().take(3).join(",")+',Rifftrax]'}	{'[None, Rifftrax]'}}:'.'+

	{def languages = [];
	any{audio.collect{ au -> languages << any{ au.'LanguageString3' }{'Unknown'}};
	'['+languages.unique().take(3).join(",")+']' }
	{'[None]'}}
	{'[None]'}}
	

	{text.language.size() > 0 ?
	'.'+{def subtitles = []; any{text.collect{ sub -> subtitles << any{ sub.'LanguageString3' }{'Unknown'} };
	'['+subtitles.unique().take(3).join(",")+']'}
	{'[None]'}}:{null}}

	{audio.language.size() > 1 || text.language.size() > 1 ?
	'.['+
	{audio.language.size() > 1 ? 'Aud-'+audio.language.size()+
	{text.language.size() > 1 ? ',Sub-'+text.language.size() : null}: 'Sub-'+text.language.size()}+
	']': null}
kim
Power User
Posts: 1217
Joined: 15 May 2014, 16:17

Re: Expression Help - I can't seem to test for null or not exist.

Post by kim »

Code: Select all

{
	def languages = any{ audio.'LanguageString3' }{'Unknown'}
	'bla.bla.RIFFTRAX.bla.bla' =~/RIFFTRAX/
		? languages.unique().take(3) + 'Rifftrax'
		: '[None, Rifftrax]'
}
kim
Power User
Posts: 1217
Joined: 15 May 2014, 16:17

Re: Expression Help - I can't seem to test for null or not exist.

Post by kim »

Code: Select all

{ 	def languages = any{ audio['LanguageString3'].findAll().unique().take(3)*.upper() }{['Unknown']}
	def langSize = any{audio.language.findAll().unique().size()}{}
	def aud = '.[Aud-'+langSize+']'

	'.'+ ( 'bla.bla.RIFFTRAX.bla.bla' =~/RIFFTRAX/
	? any{langSize > 1 ? (languages + 'YES Rifftrax').toString() + aud : ''}{languages}
	: any{langSize > 1 ? (languages + 'NO Rifftrax').toString() + aud : ''}{languages})
}
{	def subtitles = any{ text.language.findAll().unique().take(3)*.upper() }{['Unknown']}
	def subSize = any{text.language.findAll().size()}{}
	'.'+ any{subSize > 1 ? subtitles.toString() + '.[Sub-'+subSize+']' : ''}{'[None]'}
}
sample:

Code: Select all

.[ENG, FRA, ITA, YES Rifftrax].[Aud-13].[EN, FR, IT].[Sub-9]
Post Reply