INTERACT FORUM

More => Old Versions => JRiver Media Center 26 for Windows => Topic started by: Matt on September 24, 2019, 03:02:22 pm

Title: NEW: ItemCount(...) expression
Post by: Matt on September 24, 2019, 03:02:22 pm
Coming soon to MC25 is a new expression function ItemCount(...).

It provides the count of whatever expression you put in as a parameter in the library.

So let's say you specify:
ItemCount(/[Album/])

You'll get the count of files in the album.

You can also use expressions like:
ItemCount(AlbumKey/(/))

That expression gets the count of files in the album (smart handling of duplicate album names, etc.)

This came from the requests in this thread:
https://yabb.jriver.com/interact/index.php/topic,122303.0.html

Originally we thought it might be too slow, but now we cache the results and rebuild the cache each minute (so a fresh import might not show for a minute).

Enjoy :)
Title: Re: NEW: ItemCount(...) expression
Post by: RoderickGI on September 24, 2019, 11:54:29 pm
Hmmm, these seem to require a different syntax to what I am used to, since you are including escape characters inside the function.

Okay, I read the thread discussing this. I havent' been drinking whiskey, but I still don't understand the nuance of why escape characters are required. After all, we use functions inside functions all the time in Expressions, such as the simple;

if(isequal([artist], bob dylan, 1), Genius, Mediocre)

The () for isequal don't need escaping. So why does Albumkey()?

I get what the escaping does, passing the literal "Albumkey()" to the ItemCount() function, but how is that different to the isequal()?

I assume that what you want to do is pass the literal, and not evaluate the function, or in the case of /[Album/] field first. But I'm not sure why.  ?

Sorry. I'm not really a programmer.  :o
Title: Re: NEW: ItemCount(...) expression
Post by: RoderickGI on September 25, 2019, 12:05:52 am
Now I'm even more confused. No escape characters used in this example:

I'm wondering about:
ItemCount(AlbumKey() - [Disc #])


I'll test tomorrow and reply here.
Title: Re: NEW: ItemCount(...) expression
Post by: ferday on September 25, 2019, 03:24:13 am
this could be a highly interesting feature. 
Title: Re: NEW: ItemCount(...) expression
Post by: Matt on September 25, 2019, 07:52:42 am
You need to escape because otherwise it just evaluates the value of AlbumKey() or whatever and replaces the text with the value.  Instead you need to pass that actual string like AlbumKey() to the function so it can use it.

Does that make sense?
Title: Re: NEW: ItemCount(...) expression
Post by: RoderickGI on September 25, 2019, 08:40:19 am
Yes, it does make sense, but I think I need to try it out to get it to sink in.

But then the "ItemCount(AlbumKey() - [Disc #])" example doesn't make sense, because "AlbumKey() - [Disc #]" would be evaluated before being passed. Maybe you meant to put escape characters in that example?
Title: Re: NEW: ItemCount(...) expression
Post by: Matt on September 25, 2019, 08:47:29 am
But then the "ItemCount(AlbumKey() - [Disc #])" example doesn't make sense, because "AlbumKey() - [Disc #]" would be evaluated before being passed. Maybe you meant to put escape characters in that example?

Yes, they need to be escaped.  That was Matt typing at home on his phone!  Sorry!
Title: Re: NEW: ItemCount(...) expression
Post by: Moe on September 25, 2019, 02:35:17 pm
Thanks a lot for implementing this Matt.  I think this is going to be very useful.
Title: Re: NEW: ItemCount(...) expression
Post by: ferday on September 25, 2019, 06:01:40 pm
i had written a global function to count tracks and auto populate # tracks

this works great, and much simpler - the syntax is wild though, the escape characters are in odd spots to me

nice one Matt, highly useful
Title: Re: NEW: ItemCount(...) expression
Post by: Moe on September 25, 2019, 09:19:36 pm
Matt, I am trying to do what I think would be a simple task but I am not having any luck.  I'd like to find how many seasons of a show I have.  I was hoping that something like

Code: [Select]
ItemCount(/[series/]/[season/])
Would do it, but that just returns how many episodes I have for that show. I understand why it's doing that, but it's not the behavior I was hoping for.   To find the number of episodes I would have thought it would be something like

Code: [Select]
ItemCount(/[series/]/[episode/])
Which also does return the number of episodes.

So, I have a request.  Would it be possible to add a mode to this function?  Something like mode 0, count all files that match the given values.  Mode 1, count all unique values that match the given values.

So, if I have a show that has two seasons, each season has 10 episodes

Code: [Select]
ItemCount(/[series/]/[season/],0)Would return 20

Code: [Select]
ItemCount(/[series/]/[season/],1)Would return 2
Title: Re: NEW: ItemCount(...) expression
Post by: RoderickGI on September 25, 2019, 09:34:13 pm
You need to escape each control character Moe, not the function name. So try;

ItemCount(/[series/]/[season/])
Title: Re: NEW: ItemCount(...) expression
Post by: Moe on September 25, 2019, 09:41:06 pm
You need to escape each control character Moe, not the function name. So try;

ItemCount(/[series/]/[season/])

I have, that was just me making a mistake on the forum, not in MC.  I edited the post, thanks.
Title: Re: NEW: ItemCount(...) expression
Post by: RoderickGI on September 25, 2019, 10:13:12 pm
Nope. Still wrong in the post above.
Title: Re: NEW: ItemCount(...) expression
Post by: Moe on September 25, 2019, 10:17:19 pm
Sigh... long day.

It was correct in MC. I got it working for other things.  Fixing it now.
Title: Re: NEW: ItemCount(...) expression
Post by: RoderickGI on September 25, 2019, 10:58:47 pm
I've just tested this a bit using custom columns in the standard Shows View, and re-read Matt's first post, and the original thread. Now I understand your request Moe. What Matt has built doesn't really meet the original request.

I was also expecting ItemCount(/[series/]/[season/]) to return the number of unique combinations of Series and Season, which would give the number of Seasons, regardless of the number of Episodes. But Matt's original description specifically says the function counts files, not unique combinations.

So I support you request for a count of the unique combinations of the values passed to ItemCount().
Title: Re: NEW: ItemCount(...) expression
Post by: Hendrik on September 26, 2019, 01:38:53 am
ItemCount counts the number of files that have the exact same value of the given expression as the file the expression runs in the context of.
Which means it can do things like counting the number of files that belong to the same album as a file you are looking at, or to the same show, or to the same season.

But it can't count the number of seasons, or the number of discs belonging to an album, because it just doesn't know what value you might want. A simple mode doesn't help here. You would have to pass several values, a search expression, a comparison expression, etc. It gets rather unwieldy, and the performance issue might come back.

This is not a relational database, every such operation we do has to literally look at every file, evaluate the expression you specified for it, and then compare the values. This is not fast.