Look who's back, back again... Match array entry based on minimum runtime?

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
User avatar
Wolfie
Posts: 147
Joined: 27 Oct 2015, 02:59

Look who's back, back again... Match array entry based on minimum runtime?

Post by Wolfie »

I'll make this simple, I hope...

Groovy: Select all

array:[
    "188" : "Extended",
    "151" : 'Special",
]
Is there a way to match it so that it "hits" when the runtime matches or exceeds the number of minutes (on the left)?

I have a 188 minute version that is being detected as 189 minutes.

I'm not opposed to reversing the order if there's a way to regex match the value (right) and then use the key (left).
User avatar
rednoah
The Source
Posts: 24532
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Look who's back, back again... Match array entry based on minimum runtime?

Post by rednoah »

Try this:

Format: Select all

{
	def runtimes = [
	    188 : "Extended",
	    151 : "Special",
	    20 : '20min',
	    0 : '0min'
	]
	
	return runtimes.findResult{ k, v -> minutes >= k ? v : null }
}
:idea: Please read the FAQ and How to Request Help.
User avatar
Wolfie
Posts: 147
Joined: 27 Oct 2015, 02:59

Re: Look who's back, back again... Match array entry based on minimum runtime?

Post by Wolfie »

Groovy: Select all

array.findResult{ k, v -> minutes.toString() >= k ? k : null }
This worked. I prefer the key, as the key is... well... the key to what I needed. :D

Having the key (minutes) allows me to use it beyond that one part, and can easily get the value.

The movie is Superman (1978, not the joke that came out in 2025). The theatrical is 143 minutes (2h23m), special is 151 minutes (2h31m), and extended is 188 minutes (3h08m). But I guess it has enough extra padding that it was registering as 189 minutes. I add the time to the folder name to help separate the different versions, and noticed that it was trying to stuff the extended into a new folder when it should have remained in its existing folder. I recently added the `{imdb-}` tag to the movie names, so needed to start parsing my library again. Also wanted to make sure that an edition would be added (if appropriate), since sometimes it's not in the file itself. I'm rather picky about how the Superman movie is treated, because it's a masterpiece and has influenced how hero movies have been getting made. It's even had a big influence on many of the Marvel movies.

👍🏻
User avatar
rednoah
The Source
Posts: 24532
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Look who's back, back again... Match array entry based on minimum runtime?

Post by rednoah »

You'll probably want to compare the numerical values:

Groovy: Select all

minutes >= (k as int)

:idea: If you compare string values, then "9" is greater than "10", which is probably not what we want here.
:idea: Please read the FAQ and How to Request Help.
User avatar
Wolfie
Posts: 147
Joined: 27 Oct 2015, 02:59

Re: Look who's back, back again... Match array entry based on minimum runtime?

Post by Wolfie »

Even better. I didn't know how to do it to integer, and yes, definitely better than comparing strings when dealing with numbers.

Thanks.
Post Reply