Page 1 of 1

trying to use info.certifications

Posted: 11 Feb 2023, 13:47
by mpegman
Hi,

I'm trying to use the info.certifications to determine if a movie is for kids or for adults
for some reason it fails to use the OR statements

Code: Select all

/completed/outputmovies(
{
	if (
	info.certifications.NL.contains('AL') || 
	Double.parseDouble(info.certifications.DE) < 14 || 
	Double.parseDouble(info.certifications.NL) < 14 || 
	Double.parseDouble(info.certifications.FR) < 14 || 
	info.certifications.US.contains('G') || 
	info.certifications.GB.contains('U') || 
	info.certifications.FR.contains('U') 
	) {
	'kids' 
	}
	else {
	'adults' 
	}
})
{info.certifications}
I get quite random results
in some cases the DE value of 6 is not picked up as 'kids' any ideas what I'm doing wrong in my code?

Re: trying to use info.certifications

Posted: 11 Feb 2023, 16:57
by rednoah
If your code errors out, then there will be an error message. However, we cannot set the error message because it depends on the movie you're processing.

:?: Which movie(s) are you testing with? Please post sample filenames or TheMovieDB links.


|| fundamentally works:

Code: Select all

{
	if (true || false) {
		return "TRUE"
	}
}

:!: This code will fail if you are checking a null value:

Code: Select all

info.certifications.NL.contains('AL')
:!: This code will fail if you're checking a null value or a non-number value:

Code: Select all

Double.parseDouble(info.certifications.DE)

:arrow: I'd keep the code simple, and just check all certifications against a list of known certifications that you classify as 'kids' and then grow the pattern with all the PG values you need to make it work for all your files:

Code: Select all

{
	info.certifications =~ /\b(PG-13|12A|TP|12)\b/ ? 'kids' : 'adults'
}

Re: trying to use info.certifications

Posted: 11 Feb 2023, 19:37
by kim
What about this: ?

Code: Select all

{ info.certifications*.value*.findAll(/\d+/).flatten()*.toInteger().average().toInteger() < 14 ? 'kids' : 'adults' }
or

Code: Select all

{ info.certifications*.value*.findAll(/\d+/).flatten()*.toInteger().average().round() < 14 ? 'kids' : 'adults' }

Re: trying to use info.certifications

Posted: 13 Feb 2023, 19:25
by mpegman
Thank you all for your support... I seem to still need to learn some basics about the language
(I used to have some programming experience in the past long time ago)

Code: Select all

{
info.certifications
}
{
info.certifications*.value*.findAll(/\d+/).flatten()*.toInteger().average().toInteger() < 14 ? 'Kids Movies/' : info.certifications =~ /(PG|A|TP|U)/ ? 'Kids Movies' : 'Movies/'
}
{
~ localize.Dutch.plex.id
}
outputs :
{GB=U, US=G}The Movie...
{BR=12, US=PG-}Kids Movies/Other Movie...

Can I not nest these if structures? Is there a null reference or something I'm not understanding, because it does not do either of the statements

Re: trying to use info.certifications

Posted: 14 Feb 2023, 03:34
by rednoah
:?: What does the error message in the Format Editor say when you try a use case that doesn't work as expected?


:?: What is the use case that doesn't work as expected? Please paste movie name and movie ID so we can be on the same page and run tests with the same certification information.


EDIT:

Multiple movie IDs for testing every code path would be good. Then we can help you write code that fits your spec exactly.

Re: trying to use info.certifications

Posted: 14 Feb 2023, 11:24
by mpegman
It does not provide an error. It's more that the programming logic is not correct I think.

I would expect the first output to provide as output 'Kids Movies/The Movie' as it has a GB=U certification

Re: trying to use info.certifications

Posted: 14 Feb 2023, 11:32
by mpegman
Could following notation be more correct to achieve what I want to do?

Code: Select all

{ 
	any{ info.certifications*.value*.findAll(/\d+/).flatten()*.toInteger().average().toInteger() }{ info.certifications =~ /(PG|A|TP|U)/ ? 12 : 99} < 14 ? 'Kids Movies/' : 'Movies/'
	} 
	

Re: trying to use info.certifications

Posted: 15 Feb 2023, 11:42
by rednoah
:?: Which movie(s) are you testing with?

:?: Can you tell us which movie that you are testing with has GB=U certification?





:?: Does this format code achieve what you want to achieve?

Code: Select all

{ any{ info.certifications.toString().matchAll(/\d+/)*.toInteger().average() < 12 ? 'Kids Movies' : 'Movies' }{ 'Uncertified Movies'} }/{~plex.id}
:idea: This format code has been tested with "ice age" and "terminator" movies:

Code: Select all

$ filebot -list --q "ice age" --db TheMovieDB -non-strict --format "{ any{ info.certifications.toString().matchAll(/\d+/)*.toInteger().average() < 12 ? 'Kids Movies' : 'Movies' }{ 'Uncertified Movies'} }/{~plex.id}"
Kids Movies/Ice Age (2002) {tmdb-425}/Ice Age (2002)
Kids Movies/The Ice Age Adventures of Buck Wild (2022) {tmdb-774825}/The Ice Age Adventures of Buck Wild (2022)
Kids Movies/Ice Age - The Meltdown (2006) {tmdb-950}/Ice Age - The Meltdown (2006)
Kids Movies/Ice Age - Continental Drift (2012) {tmdb-57800}/Ice Age - Continental Drift (2012)
Kids Movies/Ice Age - Dawn of the Dinosaurs (2009) {tmdb-8355}/Ice Age - Dawn of the Dinosaurs (2009)

Code: Select all

$ filebot -list --q "terminator" --db TheMovieDB -non-strict --format "{ any{ info.certifications.toString().matchAll(/\d+/)*.toInteger().average() < 12 ? 'Kids Movies' : 'Movies' }{ 'Uncertified Movies'} }/{~plex.id}"
Movies/Terminator Genisys (2015) {tmdb-87101}/Terminator Genisys (2015)
Movies/Terminator 2 - Judgment Day (1991) {tmdb-280}/Terminator 2 - Judgment Day (1991)
Movies/Terminator - Dark Fate (2019) {tmdb-290859}/Terminator - Dark Fate (2019)
Movies/The Terminator (1984) {tmdb-218}/The Terminator (1984)
Movies/Terminator Salvation (2009) {tmdb-534}/Terminator Salvation (2009)
:arrow: If the code above happens to not achieve what you want to achieve for one movie or another, then please do tell us what that movie is, specifically, pretty please, so that we can further refine the code for your specific requirements. ;)

Re: trying to use info.certifications

Posted: 05 Mar 2023, 13:02
by mpegman
many thanks all for your suggestions.
in the end I made a combination of this
maybe not the most beautiful code...

Code: Select all

{ 
	 def folder
	   if ( original =~ /(?i:NLKIDS)/  )  {	folder = " kids" }
	   else if ( info.network =~ /(?i:één|een|vtm|vt4|canvas|streamz|play4|play5|play6|play7|vtm2|vtm3|vtm4|vrt|2be)/ )	{ folder =  ' nl' } 
	   else if ( info.certifications*.value*.findAll(/\d+/).flatten()*.toInteger().average().toInteger() < 8 ) { folder = ' kids'  }
	   else if ( info.certifications =~ /(PG|A|TP|U)/ ) { folder = ' kids' } 
	   folder 
}