Using {"$genres"} returns empty brackets if null

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

Using {"$genres"} returns empty brackets if null

Post by cheaters »

I am positive someone has the solution for this. I couldn't come up with it after doing a few hour of playing around with it.

My movie format looks like this:

Code: Select all

{"$ny"} {"[$certification]"} {"[$runtime min]"} {"$genres"} {"[$imdbid, $rating]"}
Problem is that when using genres instead of genre, brackets are included. However, If genres returns a null value I get nothing but a pair of [] in my title. I tried using:

Code: Select all

{"$ny"} {"[$certification]"} {"[$runtime min]"} {replaceAll([], replacement = "")"$genres"} {"[$imdbid, $rating]"}
That failed because it removed the brackets and genres.

I tried to change the sample movie from Avatar to a movie that would return empty brackets to test formulas, couldn't figure that out, too convoluted.

Any help?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Using {"$genres"} returns empty brackets if null

Post by rednoah »

genres is never null. If it's empty then you'll get an empty List.

e.g. check if genres is non-empty:

Code: Select all

{genres ?: null}

I'd just use genre though, which will fail, and thus give you the behaviour you want:

Code: Select all

{ny} {[certification]} {[runtime + ' min']} {[genre]} {[imdbid, rating]}
:idea: Please read the FAQ and How to Request Help.
cheaters
Posts: 214
Joined: 09 Oct 2016, 02:01

Re: Using {"$genres"} returns empty brackets if null

Post by cheaters »

I am trying to get the entire list and if it's empty (no genres) then no empty brackets.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Using {"$genres"} returns empty brackets if null

Post by rednoah »

Here's the solution:

Code: Select all

{ny} {[certification]} {[runtime + ' min']} {genres.take(3) ?: null} {[imdbid, rating]}
It'll limit the number of genres to 3 because there are some movies that supposedly belong to an insane number of genres.


EDIT:

The unwind-on-undefined behaviour has been extended to include null / Empty String and (new) Empty List with r4960.
:idea: Please read the FAQ and How to Request Help.
cheaters
Posts: 214
Joined: 09 Oct 2016, 02:01

Re: Using {"$genres"} returns empty brackets if null

Post by cheaters »

Thanks a lot, this works fine.
Post Reply