Filter handling null age

Support for Ubuntu and other Desktop Linux distributions
Post Reply
ghostserverd
Posts: 16
Joined: 15 Nov 2019, 06:25

Filter handling null age

Post by ghostserverd »

Hi there. I'm working on improving my filtering for series matches. My ideal filter would be this:

* prefer matches from the past 30 days
* if there is no match from the past 30 days, allow older matches
* if the age is null for some reason, allow it to be the match

This is my current filter:

Code: Select all

'age < 30 || !model.any{ it.age < 30 && it.age != null }'
The reason that I added the check for null is because `null < 30` evaluates to true, and I ran into a query from TheMovieDB with results that have a null age.

It's unfortunate that the data from the API is off, but I'd like to be able to include entries with null ages if we are falling back because the age < 30 check failed.

As far as I can tell, if the age is null, evaluating it causes it to not be included in the possible matches.

For example

Code: Select all

filebot -rename The.Legend.of.Korra.S04E04.The.Calling.1080p.WEB-DL-Obfuscated/ --action TEST --db TheMovieDB::TV -non-strict --filter 'true'
results in

Code: Select all

Rename episodes using [TheMovieDB] with [Airdate Order]
Auto-detected query: [The Legend of Korra]
Fetching episode data for [The Legend of Korra]
Apply filter [true] on [57] options
Include [The Legend of Korra - 1x01 - Welcome to Republic City]
Include [The Legend of Korra - 1x02 - A Leaf in the Wind]
Include [The Legend of Korra - 1x03 - The Revelation]
Include [The Legend of Korra - 1x04 - The Voice in the Night]
Include [The Legend of Korra - 1x05 - The Spirit of Competition]
Include [The Legend of Korra - 1x06 - And the Winner is...]
Include [The Legend of Korra - 1x07 - The Aftermath]
Include [The Legend of Korra - 1x08 - When Extremes Meet]
Include [The Legend of Korra - 1x09 - Out of the Past]
Include [The Legend of Korra - 1x10 - Turning the Tides]
Include [The Legend of Korra - 1x11 - Skeletons in the Closet]
Include [The Legend of Korra - 1x12 - Endgame]
Include [The Legend of Korra - 2x01 - Rebel Spirit]
Include [The Legend of Korra - 2x02 - The Southern Lights]
Include [The Legend of Korra - 2x03 - Civil Wars (1)]
Include [The Legend of Korra - 2x04 - Civil Wars (2)]
Include [The Legend of Korra - 2x05 - Peacekeepers]
Include [The Legend of Korra - 2x06 - The Sting]
Include [The Legend of Korra - 2x07 - Beginnings (1)]
Include [The Legend of Korra - 2x08 - Beginnings (2)]
Include [The Legend of Korra - 2x09 - The Guide]
Include [The Legend of Korra - 2x10 - A New Spiritual Age]
Include [The Legend of Korra - 2x11 - Night of a Thousand Stars]
Include [The Legend of Korra - 2x12 - Harmonic Convergence]
Include [The Legend of Korra - 2x13 - Darkness Falls]
Include [The Legend of Korra - 2x14 - Light in the Dark]
Include [The Legend of Korra - 3x01 - A Breath of Fresh Air]
Include [The Legend of Korra - 3x02 - Rebirth]
Include [The Legend of Korra - 3x03 - The Earth Queen]
Include [The Legend of Korra - 3x04 - In Harm's Way]
Include [The Legend of Korra - 3x05 - The Metal Clan]
Include [The Legend of Korra - 3x06 - Old Wounds]
Include [The Legend of Korra - 3x07 - Original Airbenders]
Include [The Legend of Korra - 3x08 - The Terror Within]
Include [The Legend of Korra - 3x09 - The Stakeout]
Include [The Legend of Korra - 3x10 - Long Live the Queen]
Include [The Legend of Korra - 3x11 - The Ultimatum]
Include [The Legend of Korra - 3x12 - Enter the Void]
Include [The Legend of Korra - 3x13 - Venom of the Red Lotus]
Include [The Legend of Korra - 4x01 - After All These Years]
Include [The Legend of Korra - 4x02 - Korra Alone]
Include [The Legend of Korra - 4x03 - The Coronation]
Include [The Legend of Korra - 4x04 - The Calling]
Include [The Legend of Korra - 4x05 - Enemy at the Gates]
Include [The Legend of Korra - 4x06 - Battle of Zaofu]
Include [The Legend of Korra - 4x07 - Reunion]
Include [The Legend of Korra - 4x08 - Remembrances]
Include [The Legend of Korra - 4x09 - Beyond the Wilds]
Include [The Legend of Korra - 4x10 - Operation: Beifong]
Include [The Legend of Korra - 4x11 - Kuvira's Gambit]
Include [The Legend of Korra - 4x12 - Day of the Colossus]
Include [The Legend of Korra - 4x13 - The Last Stand]
Include [The Legend of Korra - Special 1 - Republic City Hustle: Part 1]
Include [The Legend of Korra - Special 2 - Republic City Hustle: Part 2]
Include [The Legend of Korra - Special 3 - Republic City Hustle: Part 3]
Include [The Legend of Korra - Special 4 - The Re-Telling of Korras Journey]
Include [The Legend of Korra - Special 5 - The Legend of Puppetbender: The Making of a Legend - The Untold Story]
[57 / 57] options passed
[TEST] from [/downloads/nzb/completed/sonarr/The.Legend.of.Korra.S04E04.The.Calling.1080p.WEB-DL-Obfuscated/d714311d27842e9904e18ee8d9c93050ba11a3ac.mkv] to [/downloads/nzb/completed/sonarr/The.Legend.of.Korra.S04E04.The.Calling.1080p.WEB-DL-Obfuscated/The Legend of Korra - 4x04 - The Calling.mkv]
Processed 1 files
note the

Code: Select all

[57 / 57] options passed
but then

Code: Select all

filebot -rename The.Legend.of.Korra.S04E04.The.Calling.1080p.WEB-DL-Obfuscated/ --action TEST --db TheMovieDB::TV -non-strict --filter 'age < 30 || true'
which still always evaluates to true but includes age in the conditional results in

Code: Select all

Rename episodes using [TheMovieDB] with [Airdate Order]
Auto-detected query: [The Legend of Korra]
Fetching episode data for [The Legend of Korra]
Apply filter [age || true] on [57] options
Include [The Legend of Korra - 1x01 - Welcome to Republic City]
Include [The Legend of Korra - 1x02 - A Leaf in the Wind]
Include [The Legend of Korra - 1x03 - The Revelation]
Include [The Legend of Korra - 1x04 - The Voice in the Night]
Include [The Legend of Korra - 1x05 - The Spirit of Competition]
Include [The Legend of Korra - 1x06 - And the Winner is...]
Include [The Legend of Korra - 1x07 - The Aftermath]
Include [The Legend of Korra - 1x08 - When Extremes Meet]
Include [The Legend of Korra - 1x09 - Out of the Past]
Include [The Legend of Korra - 1x10 - Turning the Tides]
Include [The Legend of Korra - 1x11 - Skeletons in the Closet]
Include [The Legend of Korra - 1x12 - Endgame]
Include [The Legend of Korra - 2x01 - Rebel Spirit]
Include [The Legend of Korra - 2x02 - The Southern Lights]
Include [The Legend of Korra - 2x03 - Civil Wars (1)]
Include [The Legend of Korra - 2x04 - Civil Wars (2)]
Include [The Legend of Korra - 2x05 - Peacekeepers]
Include [The Legend of Korra - 2x06 - The Sting]
Include [The Legend of Korra - 2x07 - Beginnings (1)]
Include [The Legend of Korra - 2x08 - Beginnings (2)]
Include [The Legend of Korra - 2x09 - The Guide]
Include [The Legend of Korra - 2x10 - A New Spiritual Age]
Include [The Legend of Korra - 2x11 - Night of a Thousand Stars]
Include [The Legend of Korra - 2x12 - Harmonic Convergence]
Include [The Legend of Korra - 2x13 - Darkness Falls]
Include [The Legend of Korra - 2x14 - Light in the Dark]
Include [The Legend of Korra - 3x01 - A Breath of Fresh Air]
Include [The Legend of Korra - 3x02 - Rebirth]
Include [The Legend of Korra - 3x03 - The Earth Queen]
Include [The Legend of Korra - 3x04 - In Harm's Way]
Include [The Legend of Korra - 3x05 - The Metal Clan]
Include [The Legend of Korra - 3x06 - Old Wounds]
Include [The Legend of Korra - 3x07 - Original Airbenders]
Include [The Legend of Korra - 3x08 - The Terror Within]
Include [The Legend of Korra - 3x09 - The Stakeout]
Include [The Legend of Korra - 3x10 - Long Live the Queen]
Include [The Legend of Korra - 3x11 - The Ultimatum]
Include [The Legend of Korra - 3x12 - Enter the Void]
Include [The Legend of Korra - 3x13 - Venom of the Red Lotus]
Include [The Legend of Korra - 4x01 - After All These Years]
Include [The Legend of Korra - 4x02 - Korra Alone]
Include [The Legend of Korra - 4x03 - The Coronation]
Include [The Legend of Korra - 4x04 - The Calling]
Include [The Legend of Korra - 4x05 - Enemy at the Gates]
Include [The Legend of Korra - 4x06 - Battle of Zaofu]
Include [The Legend of Korra - 4x07 - Reunion]
Include [The Legend of Korra - 4x08 - Remembrances]
Include [The Legend of Korra - 4x09 - Beyond the Wilds]
Include [The Legend of Korra - 4x10 - Operation: Beifong]
Include [The Legend of Korra - 4x11 - Kuvira's Gambit]
Include [The Legend of Korra - 4x12 - Day of the Colossus]
Include [The Legend of Korra - 4x13 - The Last Stand]
Include [The Legend of Korra - Special 1 - Republic City Hustle: Part 1]
Include [The Legend of Korra - Special 2 - Republic City Hustle: Part 2]
Include [The Legend of Korra - Special 3 - Republic City Hustle: Part 3]
[55 / 57] options passed
[TEST] from [/downloads/nzb/completed/sonarr/The.Legend.of.Korra.S04E04.The.Calling.1080p.WEB-DL-Obfuscated/d714311d27842e9904e18ee8d9c93050ba11a3ac.mkv] to [/downloads/nzb/completed/sonarr/The.Legend.of.Korra.S04E04.The.Calling.1080p.WEB-DL-Obfuscated/The Legend of Korra - 4x04 - The Calling.mkv]
Processed 1 files
note the

Code: Select all

[55 / 57] options passed
So my question is:

Is there a way to allow entries with a null age to be included in the possible matches if the first < conditional check returns false?
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Filter handling null age

Post by rednoah »

While null < 1 indeed returns true, top-level bindings such as {age} never return null, instead they will throw:
viewtopic.php?t=1895


e.g. if age is undefined then throw and fail, which --filter will interpret as false:

Code: Select all

age < 30

e.g. catch the error case, and default to true:

Code: Select all

any{ age < 30 }{ true }

:idea: {age} as top-level binding indeed behaves differently from {model.age} where the .age property may be null for individual items.
:idea: Please read the FAQ and How to Request Help.
ghostserverd
Posts: 16
Joined: 15 Nov 2019, 06:25

Re: Filter handling null age

Post by ghostserverd »

Ah interesting. I ended up swapping the condition to short-circuit the top-level age binding

Code: Select all

!model.any{ it.age < 30 && it.age != null } || age < 30
but this is probably more explicit. The fall-through behavior is slick.

Code: Select all

any{ age < 30 }{ true } || !model.any{ it.age < 30 && it.age != null }
Thanks for the tip!
Post Reply